Vixen and arduino using a header/footer

jabelone

New elf
Joined
Dec 4, 2014
Messages
1
Location
North Brisbane, Queensland
Hi guys,

I finally have a working set-up. I'm using a pair of 'telemetry transceivers' which are essentially just a wireless serial bridge. I am using the vixen 3 generic serial output. This works well apart from a small problem, because of the wireless connection, occasionally (not very often) a packet gets dropped and the channel becomes out of sync.

To solve this issue I want to use the header/footer feature of vixen 3. I have tried many different combinations of code but I can't seem to get it. The closest I got was a channel randomly turning on after being passed the header. Below is the code I am running on the arduino uno. (not all mine, can't remember where I got it from) I have just completely rewritten all the code so it's much simpler, smaller and easier to read - plus it's all mine. ;)

Code:
#define channelCount 17 //The total number of channels the arduino is receiving from vixen, must match vixen controller settings exactly!

int incomingByte[channelCount];  //The variable that will hold our incoming serial data
const int channelPin[channelCount] = {
  2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1, A2, A3, A4}; //The rest are the channel outputs in order from 1 - 15
const int switchPin = A5; //Input for the override switch
char *header="VIXEN_START";

void setup()
{
  Serial.begin(9600);  //Start our serial connection at 9600 baud, must match vixen controller settings exactly!
  for (int i=0; i<channelCount; i++) pinMode(channelPin[i], OUTPUT);  //Set all of our pins defined earlier as outputs
  pinMode(switchPin, INPUT);  //Set our button pin as an input
  POST();
}

void loop()
{

  if (digitalRead(switchPin) == HIGH) { //If the switch is on "vixen mode" and do whatever vixen tells it to
    if (Serial.available() >= channelCount)  //If there is available serial bytes, and there are at least as many as the amount of channels we have
    {

      for (int i=0; i<=channelCount;i++)  //Read up to the number of channels we have and set the correct pins
      {
        incomingByte[i] = Serial.read();  //Read the serial byte and store it in the appropriate variable
      }
      for (int i=0; i<=channelCount;i++)  //Read up to the number of channels we have and set the correct pins
      {
        analogWrite(channelPin[i], incomingByte[i]);  //Set the output pin to the incoming data
      }
    }
  }

  else {  //If the switch is NOT on "vixen mode" then turn everything on
    for (int i=0; i<=channelCount;i++)  //Run for up to the number of channels we have and set the pins all high
    {
      digitalWrite(channelPin[i], HIGH);
    }
  }

}



void POST() //Power on self test
{

  /////////////////// Turn all inputs on then off ///////////////////
  for (int i=0; i<=channelCount+1;i++)  //Run for up to the number of channels we have
  {
    digitalWrite(channelPin[i], HIGH); //Set the pins all high with a small delay in between
    delay(200);  //Delay for 200ms
  }
  for (int i=0; i<=channelCount+1;i++)  //Run for up to the number of channels we have
  {
    digitalWrite(channelPin[i], LOW);  //Set the pins all low with a small delay in between
    delay(200);  //Delay for 200ms
  }

  /////////////////// Fade all Inputs in then out ///////////////////

  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue +=2) {  // sets the value (range from 0 to 255):
    for (int i=0; i<=channelCount; i++)  //Read up to the number of channels we have and set the correct pins
    {
      analogWrite(channelPin[i], fadeValue);  //Set the output pin to the fade value
    }
    delay(30);  //Delay for 30ms
  } 

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -=2) {  // sets the value (range from 0 to 255):
    for (int i=0; i<=channelCount; i++)  //Read up to the number of channels we have and set the correct pins
    {
      analogWrite(channelPin[i], fadeValue);  //Set the output pin to the fade value
    }
    delay(30);  //Delay for 30ms
  }

}
 
Top