Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I was wondering if it is possible to connect 8 individual RGB led's much like the adafruit strip. I saw the Pumpkin Pi project and would like to build one. I don't have any yellow or red LED's, but have a small stockpile of the RGB's.

I know for arduino I would use 270ohm resistors to RGB cathodes and control each brightness by a scale of 0 to 255.

Is there a way to do this on the Raspberry Pi?


Update


So I've been looking into this a little more. I took your guys idea of using the TLC5940 LED Driver.

So now I'm asking for some help again. I figured 1 long question that eventually solves this is better then a bunch scattered throughout stackexchange. Now comes the wiring part. I'm using an arduino wiring tutorial as a start since I'm in way over my head. I'm also referring to the data sheet. According to the diagram pin 27 or VPRG confuses me. The Arduino diagram has it grounded so I am grounding. . . How do I connect this correctly to the pi? I'm also guessing I need resistors too...

I'm sorry if this sounds really stupid, but I am a true beginner at this stuff. You have to learn to crawl before you can walk.

What do I need to do to correct this wiring diagram (fritzing)?

The wiring fzz file can be downloaded from google here. TLC5940

enter image description here


Update 2 - after comment


Taking into account some of the answers and comments this would be the wiring diagram then? 330ohm to anode. 2k ohm to pin 20. How does the inputs get from the pi to chip? enter image description here

share|improve this question
    
Ooohhh the pumpkin pi =:0 –  ppumkin Oct 24 '12 at 16:25
    
Would you clarify a few things? Do you want to drive all red, green and blue LEDs of 8 RGB LEDs (that will take 24 outputs, so 8 more than the 16 provided by a TLC5940). What RGB LEDs are you using? We need to know if they are common anode or common cathode (your wiring looks like common cathode, which won't work with a TLC5940, which can only sink current. Common cathode will need a different chip). Also blue might not switch on using 3.3V, so will need 5V. Must it be through hole electronics (e.g DIP), and not surface mount. Do you care if it uses 3 chips instead of one? –  gbulmer Nov 8 '12 at 0:37
    
@gbulmer Sorry about that. I don't have the package the LED's came in, but think you are correct on Common Cathode as to light them in arduino I wrote a HIGH. I will pick up some Common Anode from radioshack tonight. I Have 5 TLC5940 chips and don't care if I use them all. The reason why I'm going with DIP is to use a breadboard (baby steps). After I get it working I'll switch to surface mount. –  atrueresistance Nov 8 '12 at 14:32

4 Answers 4

up vote 2 down vote accepted

I see two things that should be addressed in this question:

  1. How to connect and communicate with the TLC5940

  2. How to connect LEDs up to the TLC5940.

For the first part, you will need to connect it to the i2c pins of the Raspberry Pi's P1 header (which are pins 3 (data) and 5 (clock)). You can then use pin 1 (3.3 V) for the VCC of the TLC5940. It recommends from 3 V to 5.5 V for input according to the datasheet. You will also want to connect a ground pin from P1 (e.g. pin 5) to the GND of the TLC5940. And you will need an additional GPIO (e.g. pin 7) to connect to the TLC5940's XLAT signal to latch in the value of the shift register.

Then you will need to setup the Pi for i2c communication: assuming raspbian, remove i2c-bcm2708 from /etc/modprobe.d/raspi-blacklist.conf, load it and i2c-dev and you should get /dev/i2c-0 and /dev/i2c-1 (i2c-1 is what you will need to use for Model B Rev. 2 Pis).

Finally, you will need to use an i2c transaction to set the value of the internal shift register, and then signal the XLAT (if using pin 7, it's GPIO 4).

I also overlooked the GSCLK pin. You will need to provide a clock input so that the internal counter actually increments, which can be done from another GPIO line if it's configured correctly. I also don't think the 3.3 V rail will provide sufficient current for this application (50 mA max). If you move to the 5 V rail, you can draw up to ~300 mA, but should use 5 V logic for i2c then (and the GSCLK), requiring more components.

For the second part, it sounded like you had that handled from some past Arduino project, unless I misread?

share|improve this answer

Yes. You would use the GPIO pins in PWM mode to control each brightness scale. An example of the wiring from wiring.org.co. The GPIO utility & guides from Gordons Project is another place to start

enter image description here

Edit

As Alex Chamberlain pointed out, only one GPIO pin supports PWM. You can use software to achieve PWM on other GPIO pins. Info & examples for C & Python.

This may be overkill, as Pumpkin Pi project only requires orange light. If you have a stockpile of RGB's, and time to experiment, you can illuminate a single LED color on the RGB & mix them with others to generate tertiary colors. A ratio of 2-parts red to 1-part green will appear as orange. Toggle half of the red LEDs will create the illusion of orange flickering to yellow. But that's a color theory; which, I haven't tried.

share|improve this answer
1  
Isn't there only one PWM output? –  Alex Chamberlain Oct 24 '12 at 16:58
    
Good question. eLinux claims that all GPIO pins can be reconfigured for PWM; however, General Wiring Functions states only GPIO-1 (pin 18) supports PWM. Section 6.2 Alternative Function Assignments of BCM2835 list all PWM pins; of which, only one is present on the pi's GPIO. –  emcconville Oct 24 '12 at 18:36
    
The eLinux article is just badly written; it's slightly better below. –  Alex Chamberlain Oct 24 '12 at 20:06
1  
The GPIO pins really can't source or sink enough current to drive LED's directly –  John La Rooy Oct 24 '12 at 21:20

Something like a TLC5940 is a good way to drive multiple PWM'd LEDS

Also check out the TCA6507 in the "Programming fun lights" appnote, although it's not available in DIP

Edit: It's fine to keep the VPRG pin on the TLC5940 connected to ground. This simply means that you can't use the "dot correction" to compensate for variations in your LEDs. If you have a bunch of LEDs and you want to go to the next level of complexity, you can use the dot correction to make them light up evenly.

The 2k resistor on pin 20 is required to set the output current.

IOUT = 3.96 * RIREF
Regular LEDs are usually 20mA, so that formula gives 2k for the resistor

share|improve this answer

This is a really helpful writeup someone did of how to use the TLC5940 with an AVR: https://sites.google.com/site/artcfox/demystifying-the-tlc5940

It's pretty helpful for learning about the process of learning how to write code that works with the TLC5940.

The first version of the example code is pretty general. I'm working on converting all the #define statements and low level functions into something that will work on the Raspberry Pi.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.