Help needed getting Vixen to control 10 RGB LED's using PCA9685

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. :slight_smile:


#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]);

}}

Go on until you find a real problem. Don't forget to add a link to the data sheets, which are required for technical assistance.

While I appreciate your responding as I will take all the help I can get, I am not sure I understand what you mean by that when you said "until you find a real problem"? Haha. I tried the code that I had posted above (only change is that I put 30 channels instead of 44 as I had removed the other channels from Vixen so that I could try and at least just get these 30 RGB LED channels to work) and it did not work. I really didn't expect it to work because as I had mentioned, it is kind of piecemealed from what I could find online in various forums. The code uploaded to the Arduino Uno without issue but nothing happened when I ran the Vixen sequence. Not one of the lights responded or did anything.

Here is a link to the PCA9685 that I am using: Sunfounder PCA9685

And here is a link to it's data sheet: DataSheet

Attached is a picture of how I have the devices connected. the only difference is that I am using the dedicated SCA and SDL pins on the Uno instead of to Analog Pins 4 and 5.

Any suggesstions?

I suggest that you run the library examples first. Your code looks too weird to me, not worth hunting bugs.

Start from the library examples and extend them step by step. Verify that you don't confuse SCL and SDA. How do you connect the LEDs?

I ended up deciding against using the 16channel drivers. I was overwhelmed with trying to get that to work and realized that I can use Arduino Megas instead. Each Mega having 15 PWM ports, I can control 5 RGB LED's from each one and can just get additional MEGA's as needed for additional RGB's. Definitely not the most efficient way to go about this but sometimes you've got to take the path of least resistance and go with what you know and understand to get the job done. I also have the option of daisy chaining multiple arduinos to get more PWM pins.

Using the PCA9685 is easy, especially if you use the Brunnels LED driver library instead of the Adafruit servo library.
But I see you're using SSRs to switch your LED strings. Not sure if that (PWM/dimming) will work.
Leo..