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 )
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!
RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- gdahilig
- Posts: 11
- Joined: Tue Jan 03, 2012 3:07 am
- gdahilig
- Posts: 11
- Joined: Tue Jan 03, 2012 3:07 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
I should add: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 again,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?
gene
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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)
That is correctif 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?
- gdahilig
- Posts: 11
- Joined: Tue Jan 03, 2012 3:07 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
Thanks for help!
Gene
Gene
- gdahilig
- Posts: 11
- Joined: Tue Jan 03, 2012 3:07 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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:
I've also tried other things like:
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
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
#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);
}
Code: Select all
//red
pwm.setPWM(0, 255,0);
pwm.setPWM(1, 0,0);
pwm.setPWM(2, 0,0);
What would the proper/correct use of the Servo api when using it with RGB LEDs?
Thanks!
gene
-
- Posts: 1645
- Joined: Sat Nov 10, 2007 12:59 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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,
but i could be wrong. probably works best if on time is always less than off time.
so to get a 50% duty cycle on led 0 i think the call would look like,
Code: Select all
pwm.setPWM(0, 0, 2048);
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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:
This will give you cyan:
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
//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
Code: Select all
//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
- gdahilig
- Posts: 11
- Joined: Tue Jan 03, 2012 3:07 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
Ahhhhhh, that makes sense! And it works GREAT!
Thanks everyone for their help!
Thanks everyone for their help!
-
- Posts: 4
- Joined: Wed Nov 14, 2012 12:58 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
Looking at the product, are the resistors necessary for the anode RGB leds?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)
According to the product page:
220 ohm series resistors on all the output lines to protect them, and to make driving LEDs trivial
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
@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:
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. ...
-
- Posts: 4
- Joined: Wed Nov 14, 2012 12:58 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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?
The setup with this board and and the anode led's should provide a straight up connection as the resistors are inline correct?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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.
-
- Posts: 4
- Joined: Wed Nov 14, 2012 12:58 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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
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
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
Any help for a NOOB would be grateful.
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
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
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
Any help for a NOOB would be grateful.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: RGB LEDs and Adafruit 16-Channel 12-bit PWM/Servo Driver(PCA9685)
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.
-
- Posts: 4
- Joined: Wed Nov 14, 2012 12:58 am
Please be positive and constructive with your questions and comments.