PCA9685 for LEDs

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
togethernessnyc
 
Posts: 3
Joined: Fri Oct 05, 2012 7:27 am

PCA9685 for LEDs

Post by togethernessnyc »

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

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCA9685 for LEDs

Post by adafruit_support_mike »

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.

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

Re: PCA9685 for LEDs

Post by togethernessnyc »

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?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCA9685 for LEDs

Post by adafruit_support_mike »

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

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.

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

Re: PCA9685 for LEDs

Post by togethernessnyc »

@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 BANNED, but so it goes :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”