NederlandsKlik deze knop voor de Nederlandstalige website

Autopilot for Blackmagic Design ATEM switcher

This project is a simple autopilot for Atem video switchers from Blackmagic Design. It is just like the previous project “Tally light ESP32 for Blackmagic ATEM switcher” based on the ESP32 microcontroller. Also for this autopilot, we again use the M5StickC development module (from VNGsystems) that we program with the Arduino IDE, but you can of course use any other ESP32 development board.

M5StickC ESP32 PICO Color LCD Mini IoT Development Board
Tested and recommended by OneGuyOneBlog.com:

M5StickC ESP32 PICO Color LCD Mini IoT Development Board
Banggood.com

Why automatic switching?

During the Corona (COVID-19) period, we started streaming all kinds of events live. Normally there is of course someone shifting neatly, as it should be. But imagine, you’re the only technician in the studio on a 4-hour DJ stream. The pizza delivery person is at the door, you have to go to the toilet, you want to get a beer or you just have to stretch your legs. Then you want to get out from behind the ATEM without the viewers noticing. At that moment you can switch on the autopilot. It will not switch as creatively as a trained video technician, but if you don’t stay away for too long, no one will notice.

Blackmagic Design ATEM Mini HDMI Live Switcher
Tested and recommended by OneGuyOneBlog.com:

Blackmagic Design ATEM Mini HDMI Live Switcher
Amazon.com

Requirements

Besides the M5StickC you also need some other things, namely the Arduino IDE, ESP32 core, M5StickC libraries, and the ATEM libraries. If you have not installed it before, follow the steps below. If you already have all this on your computer, you can already try the sketch at the bottom of this page.

Install the Arduino IDE, ESP32 core and M5StickC libraries

As usual, install the Arduino IDE with the ESP32 core. When using the M5StickC, you also install the M5StickC libraries. For more information, see the blog “Programming the M5StickC with the Arduino IDE”. If you use another ESP32 module, read the blog “ESP32 with Arduino IDE on Linux and Windows“.

Install the ATEM Arduino libraries

Download the SKAARHOJ open projects files from Github. Copy the files in the “ArduinoLibs” folder to the libraries folder of your Arduino IDE. You should have quite a few new folders in your libraries folder, such as Arduino/libraries/ATEM, Arduino/libraries/ATEMbase, etc.

The library is compatible with Arduino (with Ethernet shield) and the ESP8266 (WiFi), but not yet with the ESP32. This is easily remedied by making a total of 3 changes to the two files ATEMbase.cpp and ATEMbase.h.

In libraries/ATEMbase/ATEMbase.cpp, around line 50:

Search for

		// Set up Udp communication object:
	#ifdef ESP8266
	WiFiUDP Udp;
	#else
	EthernetUDP Udp;
	#endif

and replace by:

		// Set up Udp communication object:
	WiFiUDP Udp;

 

In the second file, libraries/ATEMbase/ATEMbase.h, around line 35:

#ifdef ESP8266
#include <WifiUDP.h>
#else
#include <EthernetUdp.h>
#endif

replace this with the following line (mind the uppercase and lowercase):

 #include <WiFiUdp.h>

 

The second change in this file, around line 60, look for this snippet:

  	#ifdef ESP8266
  	WiFiUDP _Udp;
  	#else
	EthernetUDP _Udp;					// UDP object for communication, see constructor.
	#endif

and replace it with:

  	WiFiUDP _Udp;

You can now use the ATEM library in your ESP32 projects.

Autopilot for Blackmagic Design Atem switcher: switching 2-1-3-2
Autopilot for Blackmagic Design Atem switcher: switching 2-1-3-2

Autopilot Arduino sketch

The operation of the sketch is simple. A random (new) input is always chosen as “preview”. The previous preview then becomes active as “program”. We wait between switching. The length of this period is also chosen at random, with a preset minimum and maximum duration.

In the sketch you can adjust the following things to your own situation:

  • clientIp: enter a (free) IP address for the ESP32 here
  • switcherIp: The IP address of the Atem switcher
  • ssid: the name of your WiFi network
  • password: the password of your WiFi network
  • cameras: the number of inputs you want to use (for Atem mini eg 4)
  • minTime: minimum waiting time in seconds
  • maxTime: maximum waiting time in seconds

The rest of the sketch speaks for itself, you can of course make it as complicated as you want.

/*****************
  Autopilot for Blackmagic Design Atem switcher

  Version 1.0

  Automatic switcher/controller for Blackmagic Design
  ATEM video switchers, based on the M5StickC ESP32 development
  board and the Arduino IDE.

  For more information, see:
  https://oneguyoneblog.com/2020/07/13/autopilot-for-blackmagic-design-atem-switcher/

  Based on the work of Kasper Skårhøj:
  https://github.com/kasperskaarhoj/SKAARHOJ-Open-Engineering


******************/

#include <M5StickC.h>
#include "WiFi.h"
#include <SkaarhojPgmspace.h>
#include <ATEMbase.h>
#include <ATEMstd.h>

IPAddress clientIp(192, 168, 178, 170);          // IP address of the ESP32
IPAddress switcherIp(192, 168, 178, 173);        // IP address of the ATEM switcher
ATEMstd AtemSwitcher;

// http://www.barth-dev.de/online/rgb565-color-picker/
#define GRAY  0x0020 //   8  8  8
#define GREEN 0x0200 //   0 64  0
#define RED   0xF800 // 255  0  0

const char* ssid = "yournetwork";
const char* password = "yourpassword";

int cameras = 4;  // Total number of camera inputs
int ledPin = 10;  // LED is on pin 10

int minTime = 3;     // Min. waiting time
int maxTime = 10;    // Max. waiting time

int programInput = 1; // Set a default program input
int previewInput = 2; // Set a default preview input
int timeout = 1000;   // Set a default waiting time

void setup() {

  Serial.begin(9600);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");

  M5.begin(); // Initialize the M5StickC

  pinMode(ledPin, OUTPUT);  // LED pin
  digitalWrite(ledPin, HIGH); // LED off

  AtemSwitcher.begin(switcherIp); // Initialize a connection to the switcher
  AtemSwitcher.serialOutput(true);
  AtemSwitcher.connect();
}

void loop() {

  AtemSwitcher.runLoop(); // Check for packets, respond to them, keeping the connection alive

  static unsigned long start_time = millis();

  if (millis() - start_time >= timeout) { // Time to switch?

    digitalWrite(ledPin, LOW);      // LED on white switching
    programInput = previewInput;    // For "program", choose the current preview input
    previewInput = randomNumber();  // For "preview", choose a new (random) input

    AtemSwitcher.changePreviewInput(previewInput); // Switch to new preview
    AtemSwitcher.changeProgramInput(programInput); // Switch to new program

    drawLabel(BLACK, GRAY, HIGH);   // Display program input number on LCD display

    Serial.print("Program: ");      // Print to the serial console
    Serial.println(programInput);

    start_time = millis();
    timeout = 1000 * random(minTime, maxTime + 1); // Pick a new random time to wait befor switching again
    digitalWrite(ledPin, HIGH);     // LED off

  }
}

void drawLabel(unsigned long int screenColor, unsigned long int labelColor, bool ledValue) {
  digitalWrite(ledPin, ledValue);
  M5.Lcd.fillScreen(screenColor);
  M5.Lcd.setTextColor(labelColor, screenColor);
  M5.Lcd.drawString(String(programInput), 15, 40, 8);
}

int randomNumber() { // Pseudo random non-consecutive number
  while (previewInput == programInput) {
    previewInput = random(1, cameras + 1);
  }
  return previewInput;
}

This sketch can also be found on GitHub.

Autopilot for Blackmagic Design Atem switcher: with ATEM Mini Pro
Autopilot for Blackmagic Design Atem switcher: with ATEM Mini Pro

Create your own autopilot

Like most projects on this website, this project is also just a starting point for your own creation. Adjust the sketch to your own taste or make it something completely different. If you have made something interesting, please let us know in the comment section below this article!

VNG Systems

M5StickC ESP32 PICO Color LCD Mini IoT Development Board
Tested and recommended by OneGuyOneBlog.com:

M5StickC ESP32 PICO Color LCD Mini IoT Development Board
Banggood.com

Blackmagic Design ATEM Mini HDMI Live Switcher
Tested and recommended by OneGuyOneBlog.com:

Blackmagic Design ATEM Mini HDMI Live Switcher
Amazon.com
3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *