If you want to use normal 20mA LED’s, this article will show you how to wire them for use with ShiftPWM. If you are not using 20mA LED’s, please take a look at my other pages for high power LED’s (350mA) or LED strips.
So which shift registers are compatible with ShiftPWM?
My library is compatible with almost any shift register. What is important is that you use a serial in – parallel out shift register with an internal storage register (so with a latch pin). The most commonly used shift register is the 74HC595. Please note however, that while the 74HC595 can handle 30 mA per output, it’s total current is officially rated at 70mA max. I have not encountered any problems with the 595 driving 8 LED’s, but I just want to be clear you are exceeding the maximum current rating of the device.
A great alternative to the 74HC595 is the TLC5916. It is a shift register with a constant current sink output. The are a bit more expensive, but still cost less than $1.50. You can choose the output current with an external resistor, so you do not need a resistors each LED. That will save you a lot resistors and a lot of soldering, which makes up for the price difference.
You can chain as many shift registers as you like, but if you are using many registers or long wires in between, the Arduino will have trouble driving the signal lines at high speeds. A small push-pull line driver between the Arduino and the signal wires will increase the output drive capability and solve the problem, see the schematics below.
The schematics below are for common anode RGB LED’s, but 74HC595′s will work with common cathode RGB’s as well. If you want to use the TLC5916 drivers, watch out when buying LED’s because they can only sink current. Common cathode RGB LED’s will not work with the TCL5916!
Which Arduino pins should I use?
There are two versions of ShiftPWM: a version that uses the hardware SPI port and a version that doesn’t.With the non-SPI version, you can choose all the pins freely. It is 2.5x slower than the SPI version, but you can use the SPI port for something else.
With the SPI version, you will have to use the MOSI (Master Out-Slave In, PB2) and SCK (SPI clock, PB1) pin.
It makes sense use the SS pin (Slave Select, PB0) as latch pin, but you can choose that pin freely. I use pin 8 by default, because SS is tied to the RX LED on the Arduino Leonardo so it is not available for ShiftPWM. Using pin 8 keeps it the library consistent between boards.
Do not use the MISO pin for anything, because this interferes with SPI operation!
The following table shows you where those pins are located on various Arduino boards:
|Regular Arduino / LilyPad (atmega328)||Arduino Leonardo||Arduino Mega||Teensy 2.0||Teensy++ 2.0|
|Data pin (MOSI)||11||ICSP 4||51||2 (B2)||22 (B2)|
|Clock pin(SCK)||13||ICSP 3||52||1 (B1)||21 (B1)|
|Default Latch pin||8||8||8||8||8|
|Slave select (SS)||10||- (RX LED)||53||0 (B0)||20 (B0)|
|MISO pin(do NOT use!)||12||ICSP 1||50||3 (B3)||23 (B3)|
Schematic for regular 74HC595 shift registers
The shift registers are used as a current sink here, so make sure that ShiftPWM_inverOutputs is set to true.
Schematic for TLC5916 constant current LED drivers
The constant current LED drivers are on when the output is written to 1, so make sure that ShiftPWM_inverOutputs is set to false.