Hello All, hoping someone can lend a hand here. Ive created a light show sequence to music using Vixen software. As of now, I have 44 total channels of LED lights in the sequence. 14 of those channels will be single color LED's (1 Channel per LED). The other 30 channels will be for 10 RGB LED's (3 Channels per LED). Eventually the sequence will include close to 100 additional channels but those will be connected to SSR's and Im not worried about those for now as I am confident that once I get the RGB LED requiring PWM pin situation resolved, I wont have any issues with figuring out the digital pins controlling the SSR's.
The trouble I am having is trying to figure out how to get the serial commands coming from vixen to be read by the arduino and translated to the 16 Channel controllers (PCA9685). I have been scouring the internet and have read what seems like hundreds of forum posts and I think I am more confused now than I was before. The 2 PCA9685's that I ordered are coming in today and before I test them out, I wanted to see if there was anyone willing to review the code I have below to see if it even makes sense or will work. I basically cut and paste from different sketches I found online and tweaked according to what I understood from all the info I read. I hope that if what I put together is not correct, it is at least close. If anyone with more experience in this can take a look at the code below and let me know your thoughts/suggestions it would be greatly appreciated. I also included some questions in the sketch that hopefully someone can help answer.
The setup I have is 1 Arduino Uno connected to two PCA9685 16ch adafruit controllers. This will be assigned in Vixen as controller 1. Then I will have 2 other Arduino Megas assigned as controllers 2 & 3 in Vixen. Each Arduino will have its own USB Comm port. (The Mega's are not accounted for in this code as I am not too concerned with those for now and I think I can get those working.)
Please go easy on me. haha. I promise you I have tried my hardest to figure this out on my own.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);
int i = 0;
int incomingByte[30]; //I put 30 here because even though there are more than 30 channels coming out of Vixen,
//the Arduino controlling the RGB LED's is not controlling anything else so I was assuming since
//it is set up as its own controller in Vixen, that Vixen send only the 30 bytes pertaining to
//this controller to the comm port it is connect to. Am I correct in assuming that?
//Or should it be changed to the total number of channels in the sequence for ALL controllers?
void setup() {
Serial.begin(9600);
Wire.beginTransmission(0x40);
Wire.beginTransmission(0x41);
Wire.begin(); // Do I need to do this command twice? Once for each 16channel controller???
//And if yes, how would I write each of the Wire.begin() functions in this sketch?
pwm1.begin();
pwm1.setPWMFreq(60); //Is this supposed to be 60? I have seen some threads saying it should be 60 and
//others saying it should be 490 or even much higher numbers??
pwm2.begin();
pwm2.setPWMFreq(60);
}
void loop()
{
if (Serial.available() >= 30)
{
for (int i=0; i<30;i++)
{
incomingByte[i] = Serial.read();
}
pwm1.setPWM(0,0,incomingByte[0]); //Got some conflicting info on this as well. I am not sure if the incomingByte should be
// the third item in the parenthesis or the 2nd item in the parenthesis.
// In other words should it be (Pin, 0, incomingByte) or (Pin, incomingByte,0)
pwm1.setPWM(1,0,incomingByte[1]); //Should the first byte be 0 or 1?
pwm1.setPWM(2,0,incomingByte[2]);
pwm1.setPWM(3,0,incomingByte[3]);
pwm1.setPWM(4,0,incomingByte[4]);
pwm1.setPWM(5,0,incomingByte[5]);
pwm1.setPWM(6,0,incomingByte[6]);
pwm1.setPWM(7,0,incomingByte[7]);
pwm1.setPWM(8,0,incomingByte[8]);
pwm1.setPWM(9,0,incomingByte[9]);
pwm1.setPWM(10,0,incomingByte[10]);
pwm1.setPWM(11,0,incomingByte[11]);
pwm1.setPWM(12,0,incomingByte[12]);
pwm1.setPWM(13,0,incomingByte[13]);
pwm1.setPWM(14,0,incomingByte[14]);
pwm2.setPWM(0,0,incomingByte[15]);
pwm2.setPWM(1,0,incomingByte[16]);
pwm2.setPWM(2,0,incomingByte[17]);
pwm2.setPWM(3,0,incomingByte[18]);
pwm2.setPWM(4,0,incomingByte[19]);
pwm2.setPWM(5,0,incomingByte[20]);
pwm2.setPWM(6,0,incomingByte[22]);
pwm2.setPWM(7,0,incomingByte[23]);
pwm2.setPWM(8,0,incomingByte[24]);
pwm2.setPWM(9,0,incomingByte[25]);
pwm2.setPWM(10,0,incomingByte[26]);
pwm2.setPWM(11,0,incomingByte[27]);
pwm2.setPWM(12,0,incomingByte[28]);
pwm2.setPWM(13,0,incomingByte[29]);
pwm2.setPWM(14,0,incomingByte[30]);
}}