RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
Moderators: adafruit_support_bill, adafruit

RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by gdahilig on Sun Jul 08, 2012 9:58 am

From reading the product description (https://www.adafruit.com/product/815), I can use this to drive LEDs. Would it also work with RGB LEDs? If so, how would I wire it? I'm still fairly new to Arduinos (just 6 months in) and have not worked at all with servos. (I'm still at the LED stage :D )

I'm thinking that I would have to use one channel for each rgb color (since each channel has only one PWM), but that means I would only be able to drive only 4 RGB LEDs per board. Am I misunderstanding or if this is the case, would there be a better solution to drive 10 RGB LEDs?

Also, if I chain more than one board to extend the i2c bus to handle more RGB LEDs do I just connect the pins (gnd/oe/scl/sda/vcc/v+) from one board to the other?

Thanks!
gdahilig
 
Posts: 11
Joined: Tue Jan 03, 2012 2:07 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by gdahilig on Sun Jul 08, 2012 10:50 am

Also, if I chain more than one board to extend the i2c bus to handle more RGB LEDs do I just connect the pins (gnd/oe/scl/sda/vcc/v+) from one board to the other?


I should add:
if I chain more than one board to extend the i2c bus to handle more RGB LEDs, besides soldering in the address pins do I just connect the pins (gnd/oe/scl/sda/vcc/v+) from one board to the other?

thanks again,
gene
gdahilig
 
Posts: 11
Joined: Tue Jan 03, 2012 2:07 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by adafruit_support_bill on Sun Jul 08, 2012 11:14 am

RGB leds are just 3 leds that share a common anode or cathode. The ones we have in the store are the common anode type. To control a common anode led with the PWM driver, connect the common anode lead to 5v, and connect each of the R, G & B leads to one PWM channel through a current limiting resistor (220 ohms is a safe value). Since each led needs 3 channels, you can get 5 leds per driver. (with one left over)

if I chain more than one board to extend the i2c bus to handle more RGB LEDs, besides soldering in the address pins do I just connect the pins (gnd/oe/scl/sda/vcc/v+) from one board to the other?

That is correct :D
User avatar
adafruit_support_bill
 
Posts: 29144
Joined: Sat Feb 07, 2009 9:11 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by gdahilig on Sun Jul 08, 2012 12:46 pm

Thanks for help!

Gene
gdahilig
 
Posts: 11
Joined: Tue Jan 03, 2012 2:07 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by gdahilig on Sun Jul 08, 2012 2:09 pm

Ok. I've got it hooked up and I have a question about the library api. I've got the following setup on the board:
channel 0: Hooked up to RED led pin through a current limiting resistor
channel 1: Hooked up to GREEN led pin through a current limiting resistor
channel 2: Hooked up to BLUE led pin through a current limiting resistor
Common anode: 5v

I'm using the sample servo sketch as a start. Here's how I'm using it to set the color:
Code: Select all | TOGGLE FULL SIZE
#define SERVOMIN  0 // 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  255 // this is the 'maximum' pulse length count (out of 4096)

void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

void loop()
{
 Serial.println("Red");
 pwm.reset();
 pwm.setPWM(0, 255,0);
 delay(2000);   

 Serial.println("Green");
 pwm.reset();
 pwm.setPWM(1, 255,0);
 delay(2000);   

 Serial.println("Blue");
 pwm.reset();
 pwm.setPWM(2, 255,0);
 delay(2000);   

}


I've also tried other things like:
Code: Select all | TOGGLE FULL SIZE
 //red
 pwm.setPWM(0, 255,0);
 pwm.setPWM(1, 0,0);
 pwm.setPWM(2, 0,0);


Neither works. It appears that when I set channel 0 to 255, the other two are getting value, in other words, the color i'm getting is something other than red (i.e. bleed over with green and blue), not a pure red. So it's clear to me I don't understand how to map the servo api to use with RGB.

What would the proper/correct use of the Servo api when using it with RGB LEDs?

Thanks!
gene
gdahilig
 
Posts: 11
Joined: Tue Jan 03, 2012 2:07 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by mtbf0 on Sun Jul 08, 2012 3:38 pm

unfortunately the library is not too well documented, but having perused the data sheet for the device i think the arguments are probably led number, on time and off time, where led number is, predictably, a number between 0 and 15 indicating the led for which you wish to set the brightness and on time and off time are values between 0 and 4095 indicating the time during the pwm period at which you want to turn the leds respectively on and off.

so to get a 50% duty cycle on led 0 i think the call would look like,

Code: Select all | TOGGLE FULL SIZE
pwm.setPWM(0, 0, 2048);


but i could be wrong. probably works best if on time is always less than off time.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by adafruit_support_rick on Sun Jul 08, 2012 4:38 pm

You've got the common anode hooked to +5, and the PWM driving the cathodes. What that means is that your lights are going to be backwards from the way you think they're going to work. That is, when the PWM is OFF, the LED will be ON!
Why? Because the PWM pulls the cathode low during its OFF cycle, so current can flow thru the LED. During the PWM ON cycle, the cathode will be at +5V, and no current will flow.
I have the same setup in one of my projects, and it works great. You just have to invert your PWM logic. So, for red, you want:
Code: Select all | TOGGLE FULL SIZE
  //RED
pwm.setPWM(0, 0, 255);   //0% duty cycle on red led
pwm.setPWM(1, 255, 0);   //100% duty cycle on green led
pwm.setPWM(2, 255, 0);  // 100% duty cycle on blue led


This will give you cyan:
Code: Select all | TOGGLE FULL SIZE
  //RED
pwm.setPWM(0, 255, 0);   //100% duty cycle on red led
pwm.setPWM(1, 0, 255);   //0% duty cycle on green led
pwm.setPWM(2, 0, 255);  // 0% duty cycle on blue led
User avatar
adafruit_support_rick
 
Posts: 11637
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by gdahilig on Sun Jul 08, 2012 5:32 pm

Ahhhhhh, that makes sense! And it works GREAT!

Thanks everyone for their help!
gdahilig
 
Posts: 11
Joined: Tue Jan 03, 2012 2:07 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by atrueresistance on Wed Nov 14, 2012 3:45 pm

RGB leds are just 3 leds that share a common anode or cathode. The ones we have in the store are the common anode type. To control a common anode led with the PWM driver, connect the common anode lead to 5v, and connect each of the R, G & B leads to one PWM channel through a current limiting resistor (220 ohms is a safe value). Since each led needs 3 channels, you can get 5 leds per driver. (with one left over)


Looking at the product, are the resistors necessary for the anode RGB leds?

According to the product page:

220 ohm series resistors on all the output lines to protect them, and to make driving LEDs trivial
atrueresistance
 
Posts: 4
Joined: Tue Nov 13, 2012 11:58 pm

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by adafruit_support_bill on Wed Nov 14, 2012 5:19 pm

@atrueresistance - Which product page are you referring to? The quoted comment was with regard to the Diffused RGB (tri-color) LED - Common Anode: https://www.adafruit.com/products/159

The product description reads in part:
... These are Common-Anode type which means you connect one pin to 5V or so and then tie the other three legs to ground through a resistor. ...
User avatar
adafruit_support_bill
 
Posts: 29144
Joined: Sat Feb 07, 2009 9:11 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by atrueresistance on Wed Nov 14, 2012 8:54 pm

Sorry about that I was reading the Adafruit 16-Channel 12-bit PWM/Servo Driver (PCA9685) in the title and assumed that this was the driver used with led's much like the link mentioned. https://www.adafruit.com/products/815

The setup with this board and and the anode led's should provide a straight up connection as the resistors are inline correct?
atrueresistance
 
Posts: 4
Joined: Tue Nov 13, 2012 11:58 pm

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by adafruit_support_bill on Wed Nov 14, 2012 8:58 pm

That is correct. The original quote pertained to driving common anode LEDs direct from an Arduino. The 16-channel PWM/servo driver has the resistors on-board.
User avatar
adafruit_support_bill
 
Posts: 29144
Joined: Sat Feb 07, 2009 9:11 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by atrueresistance on Mon Nov 19, 2012 9:56 pm

So I just received this in the mail today and was messing with it trying to get an RGB common anode LED to light.

I hate to sound noobish (oh i clearly am), but i'm having a hard time getting it to register on my pi. I've installed i2ctools and python-smbus using debian wheezy. I'm having some trouble with the i2c address. I didn't solder any jumpers so it should be 40 according to the tutorial online.

Here is what I ran on the pi, I'm not getting an address for an existing i2c bus.
http://imgur.com/N9sZE
Image
I know you have expressed not to connect the 5v to power the board, but since the pi is able to power an led off it's pwm pins I thought it would be ok to power 1 led from the board via the pi's 5v. (I'll have a dedicated 5v 2ma once i scale.) Here is my wiring diagram.

http://imgur.com/4gRzk
Image
I know this won't help, but here is the hardwire version. I soldered my jumpers into 0,1,2 PWM | 0 V+ on adafruit board. I also soldered the breadboard piece to GND, OE, SCL, SDA, VCC, and V+.

http://imgur.com/24n9L
Image

Any help for a NOOB would be grateful.
atrueresistance
 
Posts: 4
Joined: Tue Nov 13, 2012 11:58 pm

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by adafruit_support_bill on Tue Nov 20, 2012 6:31 am

I'm not a Pi expert (yet), but I believe the Pi has 2 i2c busses and you need to scan the correct one. I think "i2cdetect 0" scans bus 0.
User avatar
adafruit_support_bill
 
Posts: 29144
Joined: Sat Feb 07, 2009 9:11 am

Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)

by atrueresistance on Tue Nov 20, 2012 8:45 am

Scanning both yields nothing... I am wiring it correctly right?

http://imgur.com/R31LF
Image
atrueresistance
 
Posts: 4
Joined: Tue Nov 13, 2012 11:58 pm