Hi, I am using a midi shield https://www.sparkfun.com/products/9595 and an arduino ethernet to communicate with an ATEM switcher.
By themselves all components work fine, if I do not enable the MIDI library- just read from the buttons and pots it all works fine. When I run my board with the midi and the ethernet I have to reset the board and send a bunch of midi signals straight away or the board does not work (I see the tx light light up when I send midi signals but get no response from the ethernet. If I do the reset and send a bunch of midi data to the board (not too much just enough) the unit works fine.
There is very little in my code, just accepting some commands and then sending the UDP packet.
#include <Ethernet.h>
#include <MIDI.h>
#include <ATEM.h>
#define COMPILE_MIDI_IN
// MAC address and IP address for this *particular* Ethernet Shield!
// MAC address is printed on the shield
// IP address is an available address you choose on your subnet where the switcher is also present:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0xEB, 0x7E }; // <= SETUP
IPAddress ip(192, 168, 10, 50); // <= SETUP
// Include ATEM library and make an instance:
// Connect to an ATEM switcher on this address and using this local port:
// The port number is chosen randomly among high numbers.
ATEM AtemSwitcher(IPAddress(192, 168, 10, 240), 56417); // <= SETUP (the IP address of the ATEM switcher)
int tBarPos;
int bankSelected;
int bankSelectFine;
int programToInput;
int faderSide;
int inputKeeper;
int fadeToBlkCh; //Midi cc channel ftb
int rotSelect;
void resetSelector(){
bankSelected=0;
}
// Necaed to find what the mixer outputs when the transformer buttons are pushed
void HandleControlChange(byte channel, byte number, byte value){
if (number>0&& number<10){
AtemSwitcher.changePreviewInput(number);
}
if (number==10){
AtemSwitcher.changeTransitionType(value); // 0=MIX, 1=DIP, 2=WIPE, 3=DVE, 4=STING
}
if (number==0 && value==80){
rotSelect=1;
}
if (number==11) {
if (faderSide==1){
tBarPos=value;
}
if (faderSide==2){
tBarPos=127-value;
}
AtemSwitcher.changeTransitionPosition(int(map(tBarPos,0,127,0,1000)));
// Keep track of fader side
if (value==0){
AtemSwitcher.changeTransitionPositionDone();
faderSide=1;
}
if (value==127){
AtemSwitcher.changeTransitionPositionDone();
faderSide=2;
}
}
if (number==0 && value==0){
bankSelected=1;
}
if (number==0&&value==1){
bankSelected=2;
}
if (number==12&&faderSide==1){
AtemSwitcher.changeProgramInput(5);
}
if (number==12&&faderSide==2){
AtemSwitcher.changePreviewInput(5);
}
if (number==13&&faderSide==1){
AtemSwitcher.changePreviewInput(5);
}
if (number==13&&faderSide==2){
AtemSwitcher.changeProgramInput(5);
}
if (number==fadeToBlkCh){
inputKeeper = AtemSwitcher.getPreviewInput();
AtemSwitcher.changePreviewInput(0);
AtemSwitcher.changeTransitionPosition(int(map(value,0,64,0,1000)));
if (value==64){
AtemSwitcher.changeTransitionPositionDone();
AtemSwitcher.changePreviewInput(inputKeeper);
}
}
}
void HandleProgramChange(byte channel, byte number){
// V4 input buttons to ATEM input selector, the message for these is sent as three parts, this selects 1 to 4
//programToInput = number+1;
if (rotSelect==1){
AtemSwitcher.changeAuxState(3, number);
rotSelect=0;
}
if (bankSelected==1 && faderSide==1){
AtemSwitcher.changeProgramInput(number+1);
resetSelector();
}
if (bankSelected==1 && faderSide==2){
AtemSwitcher.changePreviewInput(number+1);
resetSelector();
}
if (bankSelected==2 && faderSide==2){
AtemSwitcher.changeProgramInput(number+1);
resetSelector();
}
if (bankSelected==2 && faderSide==1){
AtemSwitcher.changePreviewInput(number+1);
resetSelector();
}
}
// //Assuming the transition type and effect type row a and b send note on signals
//void HandleNoteOn(byte channel, byte pitch, byte velocity){
// AtemSwitcher.changeAuxState(3, pitch);
// AtemSwitcher.changeTransitionType(pitch+1); // 0=MIX, 1=DIP, 2=WIPE, 3=DVE, 4=STING
// AtemSwitcher.changeProgramInput(pitch);
//}
void setup() {
fadeToBlkCh=14;
faderSide=1;
// Initiate MIDI communications, listen to all channels
//MIDI.setHandleNoteOn(HandleNoteOn);
// Start the Ethernet, Serial (debugging) and UDP:
MIDI.begin(MIDI_CHANNEL_OMNI);
//Serial.begin(34800);
// Initialize a connection to the switcher:
MIDI.setHandleControlChange(HandleControlChange);
MIDI.setHandleProgramChange(HandleProgramChange);
delay(1000);
Ethernet.begin(mac,ip);
AtemSwitcher.serialOutput(true);
AtemSwitcher.connect();
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
MIDI.read();
AtemSwitcher.runLoop();
}
I am having trouble understanding what might be wrong - code or hardware, as I can make the unit function perfectly if I do send just the right number of midi signals to the unit just after start-up.
Could this have something to do with the baud rate? I know the ethernet uploads at 115200 and midi is 31250.
I have tried initialising the ethernet and midi in every permutation with delays between steps but still no joy.
Any ideas would be greatly appreciated.
Cheers
Fred