TLC5940 powered LED painting

Ok, so here's what I'm working on: it's a light-up cityscape painting. It's an antique and used to have those blinking christmas lights in it, but I decided to run it through an Arduino so that I could control individual channels, etc. There are:

19 amber superbright LEDs (these are on all the time and follow along a street on the painting) 13 green superbright LEDs (these are on all the time and form a straight line (along a field) 10 blue superbright LEDs (these need to fade randomly on and off and are scattered around the painting)

I've got my Arduino hooked up to a TLC5940, and I was playing around with this thread to try and figure out the random fades: http://arduino.cc/forum/index.php/topic,70947.0.html. Now, the question is "how the heck do I wire all this stuff up?", so here are my questions:

2) Thought on enclosure? I was thinking just wiring the TLC5940 and all the output wires, resistors, etc to a breadboard and then having that attached to the Arduino inside a project box, and then adding grommets to the outside for all the wires (since they'll need to be run all over the back of the painting). Any better ideas on how to make it a bit more organized or cleaner? I may just run all the wires, hot glue them down, and then cover the entire back with black felt or something. Maybe have the project box connect to the back with some kind of ribbon connector (so that you can unplug the project box if need be)? I don't know.

fungusmonkey: 1) For the amber and green LEDs: Can I run these in parallel off of one of the TLC5940 channels (so I don't need resistors)? Or should I just wire a resistor to each LED and run them in parallel directly from on of the Arduino outputs (set to HIGH)? Would there be brightness issues or anything if I did it this way? Is there a clean way to solder a "T" connection with wires?

The TLC5490 uses the IREF to set the output in mA per channel. Do you have the datasheets for the led's? What this means is that you do not need resistors for every single led, just the one IREF to set the current output for the chip. (20mA = 2k resistor) Here is the TLC datasheet. http://www.ti.com/lit/ds/slvs515c/slvs515c.pdf

If you go to page 10, you will find a graph on the top left that shows the correlation between the reference resistor and output current.

To wire it up, i would suggest following the hardware setup found here http://code.google.com/p/tlc5940arduino/

Haha, no - I didn't have any problems wiring up the TLC5940, that was all pretty self-explanatory through the example sketches.

I mean, will I run into any problems by running 32 LEDs (13 green, 19 amber) in parallel off a single channel? Dropped voltage? Risk of damaging the chip? Anything like that?

If not, then codewise, how would I go about setting it up so that certain channels stayed on all the time, while other channels cycled randomly? I was thinking maybe channels 0-9 could control the blue LEDs, and then 10-15 could be on all the time.

Would need details on the LEDS, how many amps are they using?

The static ones don't need to be connected to the arduino, the could be powered off your power supply. The flickering ones could be put on the PWN lines for the fades.

Sure thing:

10 Superflux Piranha LED 5mm Dome Blue: 3.0-3.2v, 20mA 13 Superflux Piranha LED 5mm Dome Green: 3.0-3.2v, 20mA 19 Superflux Piranha LED 5mm Dome Amber: 1.8-2.1v, 20mA

The whole thing is being powered by the regulated 9v power supply for the Arduino. I couldn't do all 10 blue LEDs with PWM because the Arduino only has 6 PWN channels, which is why I wired up the TLC5490. If it wouldn't cause any adverse damages to the chip, I'd like to run all the green LEDs off one channel from the 5490, all the amber LEDs from another channel, and then use the next 10 channels to fade the LEDs randomly.

fungusmonkey:
Sure thing:

10 Superflux Piranha LED 5mm Dome Blue: 3.0-3.2v, 20mA
13 Superflux Piranha LED 5mm Dome Green: 3.0-3.2v, 20mA
19 Superflux Piranha LED 5mm Dome Amber: 1.8-2.1v, 20mA

The whole thing is being powered by the regulated 9v power supply for the Arduino. I couldn’t do all 10 blue LEDs with PWM because the Arduino only has 6 PWN channels, which is why I wired up the TLC5490. If it wouldn’t cause any adverse damages to the chip, I’d like to run all the green LEDs off one channel from the 5490, all the amber LEDs from another channel, and then use the next 10 channels to fade the LEDs randomly.

Let me get this straight, you want to have 10 green LEDs on one Outx ? The tlc5490 has 16 out channels, you would just need 3 of them daisy-chained to run each LED independently. For a single Out channel the current limit is 120mA (Technically 130mA?), so you cannot run it this way. 20mA x 10 LEDs would be 200mA supply for a single out. If you need more TLC5940’s, ti.com gives out free samples (5 at a time) and you can even get free overnight shipping!

You could also consider maybe doing Out0-Out4 (5 channels) with two Green LEDs each, which is no problem because it would only need 40mA (Set by a 1k IREF resistor). Then of course you could continue in that fashion for the other LEDs.
It’s just kind of awkward with the odd numbers.

Also, you can multiplex the additional LEDs on the channels if you wanted to.

will I run into any problems by running 32 LEDs (13 green, 19 amber) in parallel off a single channel?

Yes you can't run LEDs in parallel with this chip. However, you can run them in series and take the last anode up to 17V without damaging the chip. That is five LEDs at a time. If you want to run a higher voltage to control more than five then see the application note:- SLVA280 Using TLC5940 With Higher LED Supply Voltages and Series LEDs

Updated with original idea schematic.

So - lemme see if I got this straight: instead of running the LEDs parallel, I'd need to break them up into groups and run them in series? What size groups?

First off that push button is wrong, it should go to ground and you should enable the internal pull up resistors. It can't work the way you have it. That schematic is fine for the LEDs that are on all the time. If you want to put LEDs in series, find the forward voltage drop of each and have as many in series so that the sum of all the forward voltage drops minus 0.5V is less than the voltage you are trying to power them from.

It's actually wired up just like the example at: http://arduino.cc/en/Tutorial/Button with it going to ground through a resistor, I just drew it too fast and missed that part sorry.

It's not a physical switch, just a digital one I was going to use in a "if (buttonState == HIGH)" if/else loop. When it's high, it runs the random loop (which I'm still working the kinks out of), when it's low, it just leaves all the blue channels on.

Finally got another break in my crazy work schedule to wrap this up. Here is an update on the schematic. Hopefully everything should be on here correctly, including the button placement and resistors:

And here is what I worked out for the code, using this sketch -http://arduino.cc/forum/index.php/topic,70947.0.html- as the basis, and then adapting it to turn on and off with the switch and to use single color LEDS:

#include <Tlc5940.h>
#include <tlc_animations.h>
#include <tlc_config.h>
#include <tlc_fades.h>
#include <tlc_progmem_utils.h>
#include <tlc_servos.h>
#include <tlc_shifts.h>

#define NUM_LEDS 10
#define BLINK_RES 110
#define MIN_DELAY_MS 5
#define MAX_DELAY_MS 12

int blinks[NUM_LEDS];
int delays[NUM_LEDS];
int values[NUM_LEDS];

const int buttonPin = 2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

void init_led(int led) {
  blinks[led] = delays[led] = values[led] = 0;
}

void setup() {
  randomSeed(analogRead(0));
  Tlc.init();
  pinMode(buttonPin, INPUT);   // initialize the pushbutton pin as an input:
  
  for(int led = 0; led < NUM_LEDS; led++) {
    init_led(led);
  }
}

int fade() {
  int min_delay = -1;
  
  // find min delay
  for(int led = 0; led < NUM_LEDS; led++) {
    if(blinks[led]) { // if this led isn't currently blinking then we ignore it
      if(delays[led] < min_delay || min_delay == -1) {
        min_delay = delays[led];
      }
    }
  }
  
  // decrement all current delays by min delay found
  for(int led = 0; led < NUM_LEDS; led++) {
    if(blinks[led]) { // if this led isn't currently blinking then we ignore it
      delays[led] -= min_delay;
      if(delays[led] == 0) {
        values[led]++;
        delays[led] = blinks[led];
      }
    }
  }
  
  for(int led = 0; led < NUM_LEDS; led++) {
    int val = (BLINK_RES / 2) - abs((BLINK_RES / 2) - values[led]);
    val = val * (4096 / BLINK_RES);
    Tlc.set(led, val);
  }
  
  min_delay = max(0, min_delay);
  delay(min_delay);
  
  return min_delay;
}


void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// if the button is pressed down, run random LED fades  
  Tlc.clear();
  // 5000 and 65 arbitrarily chosen
  if(random(5000) < 65) {
    int led_start = random(NUM_LEDS);
    
    // find a random free LED, if one exists
    for(int led = led_start; (led + 1) % NUM_LEDS != led_start; led = led + 1 % NUM_LEDS) {
      if(blinks[led] == 0) {
        blinks[led] = random(MIN_DELAY_MS, MAX_DELAY_MS);
        delays[led] = blinks[led];
        values[led] = 0;
        break;
      }
    }
  }
  
  for(int led = 0; led < NUM_LEDS; led++) {
    if(values[led] == BLINK_RES) {
      init_led(led);
    }
  }
  
  delay(MAX_DELAY_MS - fade());
  
  Tlc.update();
}
else {
    // otherwise, turn all LEDs off
   Tlc.clear();
   Tlc.update();
  }
}

Is there any reason why the groups of LEDs can’t be wired using one resistor for the lot?

Is there any reason why the groups of LEDs can't be wired using one resistor for the lot?

Yes because the forward volt drop on different LEDs is different so they will not share current.

http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

Thanks Mike. I'm slowly learning.

So, does that all look right? I've got it assembled on the breadboard this way and it seems to work the way I want, but I don't have all the LEDs wired up yet and I'm still new to this stuff. There's no red flags or anything?

You will need some decoupling on those chips before too long. http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html