Need help with aux controller

11 posts / 0 new
Last post
Offline

Location

champlin,
United States
Joined: 25/03/2017
Posts: 4
Need help with aux controller

I have created a simple box with three buttons which is meant to  switch aux2 to one of three input1 , input3,  me/1 pgm out. I got the code to work with all the ATEM___ libraries but anytime i press one of the buttons it just switches to that source and then reverts right back if i hold it it goes in a loop of switching back from previous state to the new one back and forth and i cant make it switch and stay so here is the code i used what did i do wrong???? ATEM ME/2 4k production

 
void loop() {
 
 
     
  // Check for packets, respond to them etc. Keeping the connection alive DO NOT REMOVE!
  AtemSwitcher.runLoop();
  //////////////////////////////////////////////////////////////////////////////////////
 
 
  //reads buttons
  PCread = digitalRead(buttonPC);
  Cam2read = digitalRead(buttonCam2);
  PGMread = digitalRead(buttonPGM);
 
 
 
 
    //switches aux 2 to PC
    if(PCread == 0){
     
    AtemSwitcher.setAuxSourceInput(1,1);
    Serial.println("aux 2 has been switched to pc");
   
    }
  
    //switches aux 2 to Cam2 
    if(Cam2read == 0){
    AtemSwitcher.setAuxSourceInput(1,3);
    }
 
     //switches aux 2 to PGM
     if(PGMread == 0){
     AtemSwitcher.setAuxSourceInput(1,16);
    }
 
 
 
 
}
 
//end of program

Offline

Location

champlin,
United States
Joined: 25/03/2017
Posts: 4
Git Hub link

Here is the git hub link to the full ardiuno code https://github.com/Tesurus/Atem-aux-controller-using-skaarhoj-libraries-

Offline

Location

Leeds
United Kingdom
Joined: 12/07/2015
Posts: 81
Peculiar

How odd! Everything looks ok.
May be try something like:

if (PCread == 0 && AtemSwitcher.getAuxSourceInput(1) != 1)

if (Cam2read == 0 && AtemSwitcher.getAuxSourceInput(1) != 3)

if (PGMread == 0 && AtemSwitcher.getAuxSourceInput(1) != 16)

This way you're not sending the same command multiple times.

I've not switched an AUX via arduino yet but isn't the VIDEOSRC number for ME1 PGM "10010"?  I could be wrong!!

Other than that I'd try and diagnose for hardware issues via "Serial.print" to see if either a switch, wire or even a faulty internal pullup.  I've had a couple of faulty internal pullups on cheaper clone arduinos.

Good luck!

Colin

ATEM 2 M/E 4K, ATEM 1 M/E 4K, HyperDeck Studio Pro 4K, DeckLink Mini Recorder

Custom SKAARHOJ based controller

 

Offline

Location

Kristianstad
Sweden
Joined: 12/12/2016
Posts: 18
Hey!   Just had a play with

Hey!

 

Just had a play with your code and it seems like making a small change made it work for me.

Basically, the IF statements look for a "1" as opposed to a "0" like you had previously.

My best guess is that because you declare "PCread" integer to equal 0 in the Setup() stage, running an IF statement checking for "0" will always be true as you have declared that.

I suspect you are getting odd results because of this. 

However, I may be wrong on this one!

 

--CODE--
//switches aux 1 to PC
    if(PCread == 1){
     
    AtemSwitcher.setAuxSourceInput(0,1);
    Serial.println("aux 2 has been switched to pc");
   
    }
  
    //switches aux 1 to Cam2 
    if(Cam2read == 1){
    AtemSwitcher.setAuxSourceInput(0,3);
    }
 
     //switches aux 1 to PGM
     if(PGMread == 1){
     AtemSwitcher.setAuxSourceInput(0,16);
    }
 
 
 
--END--
 

John Barker
heretorecord.com

Check out my gear-focused YouTube Series right here!

Offline

Location

Leeds
United Kingdom
Joined: 12/07/2015
Posts: 81
Yes, John is correct!! Sad I

Yes, John is correct!! Sad I didn't see it myself.

You should've used bool instead of int.

i.e.

bool PCread = 0;

bool Cam2read = 0;

bool PGMread = 0;

ATEM 2 M/E 4K, ATEM 1 M/E 4K, HyperDeck Studio Pro 4K, DeckLink Mini Recorder

Custom SKAARHOJ based controller

 

Offline

Location

champlin,
United States
Joined: 25/03/2017
Posts: 4
I figured it

It was all in the timing because the code ran in a loop when ever the button is pressed it spammed the switcher with data and it rejected it so your portion with the 'not' statement helped solve part of the problem but it would still do weird things like misread buttons. so adding a "delay (10);" after every read also solved the misread button presses

Offline

Location

Kristianstad
Sweden
Joined: 12/12/2016
Posts: 18
Good to hear you are making

Good to hear you are making progress!

I have read a lot that it is unwise to use the "delay()" function within Arduino as it can impact the constant communication between your switcher and your DIY panel.

If you start to see connection issues, then removing the "delay()" function may be the cause.

I believe that people have found the elapsedMillis function instead.

Hopefully you won't find it as an issue, though!

Cheers!

John Barker
heretorecord.com

Check out my gear-focused YouTube Series right here!

Offline

Location

Leeds
United Kingdom
Joined: 12/07/2015
Posts: 81
no delay

As John says, delay() can cause communication issues so either use elapsedMillis or this is what I use:

(outside of the loop)

int pushButton = 0;

(in void loop)
if (!digitalRead(buttonPC)) {
   if (pushButton !=1) {
       pushButton=1;
       AtemSwitcher.setAuxSourceInput(0,1);
    }
} else if (pushButton==1) {
    pushButton = 0;
}

if (!digitalRead(buttonCam2)) {
   if (pushButton !=2) {
       pushButton=2;
       AtemSwitcher.setAuxSourceInput(0,3);
    }
} else if (pushButton==2) {
    pushButton = 0;
}

if (!digitalRead(buttonPGM)) {
   if (pushButton !=3) {
       pushButton=3;
       AtemSwitcher.setAuxSourceInput(0,16);
    }
} else if (pushButton==3) {
    pushButton = 0;
}

This way you won't get repeat button presses.

ATEM 2 M/E 4K, ATEM 1 M/E 4K, HyperDeck Studio Pro 4K, DeckLink Mini Recorder

Custom SKAARHOJ based controller

 

Offline

Location

Kristianstad
Sweden
Joined: 12/12/2016
Posts: 18
bradders - I do the same and

bradders - I do the same and it mostly works.

However, I find that my "Auto" button often gets double-pressed which causes the auto to stop midway (or react erratically).

Any thoughts on this?

Code (which is similar to yours)
  // auto
   if (digitalRead(27))  {
    if (pushButton !=27)  {
      pushButton=27;
      Serial.println("Auto");
      AtemSwitcher.performAutoME(0);
    }
  } else if (pushButton==27) {
    pushButton = 0; 
  }

John Barker
heretorecord.com

Check out my gear-focused YouTube Series right here!

Offline

Location

champlin,
United States
Joined: 25/03/2017
Posts: 4
Auto switch button

Your switch is bouncing aka turning on and off rapidly due to mechanical limitations of the switch. The way i debounced switches in this code was with "!=" but in your case i would suggest actual debouncing code here is a link that Arduino provided https://www.arduino.cc/en/tutorial/debounce. But since this is only one button you could create a electrical debouncer using a capacitor but again for me its easier because i have EE degree not CS one. But its your choice. I would just throw the their code into an object you can call upon so your main loop is cleaner and that way you can also debounce all of your buttons not just the auto switch because the cut switch will also have a negative effect.

 

 

And as for delay(); once i fully assembled everything cross talk stopped being a problem i was able to create a functional switcher board with selectable aux's and currently only able to select 3 sources due to lack of physical buttons. Also accidentally found a way how to power leds without resistors using the pwm function 

Offline

Location

Zwolle
Netherlands
Joined: 30/01/2017
Posts: 6
I am (also) using the

I am (also) using the elapsedMillis library for a delay function.
My hardware is based on the Skaarhoj BI8 boards so i dont have to worry about the pullups etc.
Bought some pcb's from Skaarhoj and soldered and assembled them myself. Also ordered at an online PCB supplier using the Gerber files from the Skaarhoj pcb's.
 
For example:
 
This is for 1 button (each button has it's own part (need to make that a little smaller & simpler but it works)
 
 if (inputSelect1.isButtonIn(1, bus1Selection))  { 
    AtemSwitcher.setPreviewInputVideoSource(0, Cam1);   //Change preview to ...
    digitalWrite(A1,HIGH);                              // Enable sendmodule
    Serial.write(Preset11, sizeof(Preset11));           // Send presetcommand
    PresetCam1 = 1;                                     // Save called presetnumber
    doAutoMix = true;                                   // Set doAutoMix to 1
    timeElapsed = 0;
  }
 
And if the set time is elapsed it goes thru the next part of the code.
 
  // If time is elapsed do autocut en disable sendmodule
  if (timeElapsed > interval) 
  {
  switch (doAutoMix) {
    case true:    
      AtemSwitcher.performAutoME(0);      // Sends AUTO command
      digitalWrite(A1,LOW);               // Disable sendmodule
      //Serial.print(doAutoMix);
      //Serial << F("Preset set and done Autocut\n");
        
        //Serial.print(interval);
        timeElapsed = 0;                  // reset the counter to 0 so the counting starts over...
        doAutoMix = false;
        //Serial.print(timeElapsed);
      break;
    case false:    
      //Serial.print(doAutoMix);
      break;
  }
  }
 
Hope this helps a little.
 

ElecDev : Have a vision to develop

ATEM TVS HD, ATEM TVS, Production studio 4k, 1M/E, Hyperdeck intensity & shuttle, Videoassist, and several mini/micro converters.