Hi all,
I have scoured the forums and other sites and can’t find a full solution to this issue. In an effort to make things as clear as possible, I may have over-explained some things; I apologize. Thanks in advance for any insight you guys can provide.
Goal: Use Vixen to control Christmas lights. Vixen is ran on my computer and sends info to the Mega 2560, the Mega controls a 16 channel relay board, the relay board switches strings of lights on and off.
Issue: The optocouplers on the relay board are interpreting “LOW” as “HIGH” and “HIGH” as “LOW”. This means when Vixen tells the arduino to switch a relay on, the relay turns off and vice versa. When the board is powered up with the code I have below, all of the relays turn on. When Vixen tells the Mega to turn on a relay, the relay turns off for the duration of the event in Vixen and then the relay turns back on when the event is over.
Attempts at a solution: As far as I can see, I just need the Mega to interpret a 255 from Vixen as a 0 and a 0 from Vixen as a 255. To do this, I just did ‘255-Serial.read()’ I have included this line, commented out in the code below. When I upload the sketch with the ‘255-’, all of the relays turn on. When I get Vixen talking to the Arduino, all of the relays turn off. This is great except when I play events in Vixen, the relay board does nothing.
If making a short video will help anyone understand what is going on I can certainly do so. Thanks!
int A = 2;
int B = 3;
int C = 4;
int D = 5;
int E = 6;
int F = 7;
int G = 8;
int H = 9;
int I = 10;
int J = 11;
int K = 12;
int L = 13;
int M = 14;
int N = 15;
int O = 16;
int i = 0;
int incomingByte[15];
void setup()
{
Serial.begin(9600);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(H, OUTPUT);
pinMode(I, OUTPUT);
pinMode(J, OUTPUT);
pinMode(K, OUTPUT);
pinMode(L, OUTPUT);
pinMode(M, OUTPUT);
pinMode(N, OUTPUT);
pinMode(O, OUTPUT);
}
void loop()
{
if (Serial.available() >= 15)
{
for (int i=0; i<15;i++)
{
incomingByte[i] = Serial.read();
// incomingByte[i] = 255 - Serial.read();
} // Arduino pins
digitalWrite(A, incomingByte[0]); // Pin 2
digitalWrite(B, incomingByte[1]); // Pin 3
digitalWrite(C, incomingByte[2]); // Pin 4
digitalWrite(D, incomingByte[3]); // Pin 5
digitalWrite(E, incomingByte[4]); // Pin 6
digitalWrite(F, incomingByte[5]); // Pin 7
digitalWrite(G, incomingByte[6]); // Pin 8
digitalWrite(H, incomingByte[7]); // Pin 9
digitalWrite(I, incomingByte[8]); // Pin 10
digitalWrite(J, incomingByte[9]); // Pin 11
digitalWrite(K, incomingByte[10]); // Pin 12
digitalWrite(L, incomingByte[11]); // Pin 13
digitalWrite(M, incomingByte[12]); // Pin A0
digitalWrite(N, incomingByte[13]); // Pin A1
digitalWrite(O, incomingByte[14]); // Pin A2
}
}