PCA9685 for LEDs
Moderators: adafruit_support_bill, adafruit

PCA9685 for LEDs

by togethernessnyc on Tue Mar 26, 2013 11:29 am

Hi!

I'm a newbie to the forums as well as Arduino and electronics in general. My knowledge is very rudimentary.

I've noticed a lot of the information on line regarding Adafruit's PCA9685 is just about servos. However, I'd like to use it to power an array of LEDs, fading at different rates.

I have an Arduino Leonardo as well as an Uno. I also have a Teensy 3.0.

Thanks!

Steve
togethernessnyc
 
Posts: 3
Joined: Fri Oct 05, 2012 7:27 am

Re: PCA9685 for LEDs

by adafruit_support_mike on Tue Mar 26, 2013 4:55 pm

The PCA9685 will work for LEDs too, and can take signals from any Arduino. The exact connections will depend on the length and width of the array you want to drive though.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCA9685 for LEDs

by togethernessnyc on Tue Mar 26, 2013 6:14 pm

Thanks! Can you recommend any code for creating a fading array? I was thinking of something like this:

http://arduino.cc/en/Tutorial/Array

But include the out-of-sync fading that I was describing earlier.

Also, how would this work with the PCA9685? Does it have to be connected to the Arduino at all times to work?
togethernessnyc
 
Posts: 3
Joined: Fri Oct 05, 2012 7:27 am

Re: PCA9685 for LEDs

by adafruit_support_mike on Thu Mar 28, 2013 12:48 am

togethernessnyc wrote:Thanks! Can you recommend any code for creating a fading array?

I don't know of an LED fading library that works with that specific chip, but the servo library for that board (https://github.com/adafruit/Adafruit-PW ... er-Library) gives you enough pieces to build a working fade system. You can set the overall PWM frequency, and tell each of the 16 channels what PWM duty cycle to use.

An untested, off-the-top-of-my-head version of the algorithm for a single channel would look like this:
Code: Select all | TOGGLE FULL SIZE
int channel = 1;
int fadeAge = 0;
int direction = 1;

void loop () {
    if (fadeAge > 2047) {
        direction = -1;
    }
    if (fadeAge < 1) {
        direction = 1;
    }
    fadeAge += direction;
   
    setPWM( channel, 2048 - fadeAge, 2048 + fadeAge );
    delay( 10 );
}

The general idea is that the pulse starts narrow, gets wide, then gets narrow again. Making that work at random times and for 16 channels would require additional bookkeeping, but the basic 'change the light intensity' code would be pretty much the same.

togethernessnyc wrote:Also, how would this work with the PCA9685? Does it have to be connected to the Arduino at all times to work?

To fade, yes. To keep the LEDs going at a specific level, no.

The PCA9685 is a 'free running' PWM controller. Tell it what to do, and it will keep doing that until you tell it to do something else. If you wanted to set the LEDs to a specific intensity and keep them there, you could disconnect the Arduino until you wanted the LEDs to do something else. To make a fade work, you have to keep changing the duty cycles at short time intervals so people see a smooth change from low-intensity light to high-intensity light. The Arduino has to remain connected to keep supplying the new values.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10122
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCA9685 for LEDs

by togethernessnyc on Thu Mar 28, 2013 3:59 pm

@mstone, Thanks! I just downloaded the servo library. I'm going to play around with your code a bit.

Re: constant fade/Arduino, understood! A little disappointing, but so it goes :)
togethernessnyc
 
Posts: 3
Joined: Fri Oct 05, 2012 7:27 am