User Tools

Site Tools


tutorials:products:digitalrgbledstrip:index.html

This is an old revision of the document!


Introduction

We love some good LED blinking as much as the next person but after years of LED-soldering we need something cooler to get us excited. Sure there are RGB LEDs and those are fun too but what comes after that? Well, we have the answer: Digital LED Strips! These are flexible circuit boards with full color LEDs soldered on. They take a lot of LED-wiring-drudgery out of decorating a room, car, bicycle, costume, etc. The ones we carry come with a removable waterproof casing.

There are two basic kinds of LED strips, the "analog" kind and "digital" kind. Analog-type strips have all the LEDs connected in parallel and so it acts like one huge tri-color LED; you can set the entire strip to any color you want, but you can't control the individual LED's colors. They are very very easy to use and fairly inexpensive.

The Digital-type strips work in a different way. They have a chip for each LED, to use the strip you have to send digitally coded data to the chips. However, this means you can control each LED individually! Because of the extra complexity of the chip, they are more expensive.

You can buy waterproof digital RGB LED strips by the meter at the Adafruit shop!

"Digital" LED strips

This tutorial is for the Digital RGB LED strips only! See the 'analog' RGB strip product page for tutorials on that kind

Technical specs:

We used to carry the HL1606-chip-based LED strips and now carry the superior LPD8806-type. They look very very similar but have a few differences, in the following specifications the width is different:

  • 19mm (0.75") wide (HL1606) or 16.5mm (0.65") wide (LPD8806), 4.5mm (0.18") thick with casing on, 62.5mm (2.45") long per segment
  • 32 LEDs per meter (16 segments)
  • Removable IP65 waterproof casing
  • Maximum 5V @ 120mA draw per 2.5" strip segment (all LEDs on full brightness) - about 2A per meter
  • 2 common-anode RGB LEDs per segment, individually controllable
  • LED wavelengths: 630nm/530nm/475nm
  • Microcontroller required to control strip

Project Ideas

The Adobe Flash Plugin is needed to display this content.





The Adobe Flash Plugin is needed to display this content.


1-dimentional cellular automata!

The Adobe Flash Plugin is needed to display this content.


Light-edge clock

Schematic

The strip is made up of 2.5" segments. Each segment is independent and so you can cut the strip down on the segment boundaries, or extend them, or split them up, etc.

This is what the HL1606-based strip segments look like:

the LPD8806-based strip looks like this (its thinner, and has fewer 'pads' on the side)

Each segment basically acts like this

There is one chip (either HL1606 or LPD8806) latch chip, it controls 6 LEDs (2 x RGB) with 2 or 4 input data lines and 2 or 4 output data lines. The HL1606 uses 4 pins, the LPD8806 uses only 2. For both, data is sent on the DI(data in) pin and CI (clock in) pin. The HL1606 also uses the LI (latch in) pin to 'push' the data down the line to the next chip through the DO (data out), CO and LO pins. The LPD8806 has a slightly smarter method by which you send special data to let it know its time to latch. By alternating data sends and latching, you can write to near infinite number of LEDs in the strand - limited pretty much by the power supply!

The SI pin is used by the HL1606 to 'strobe' the built in fading function. We've had difficulty getting it to work reliably in a way that doesn't suck so we wont be using it in the tutorial.

The whole thing is run off of 5V, and data signal should be 5V (although we suppose you can try 3.3V data signals, it might work)

Current draw

Each segment has 6 LEDs total (two red, two green and two blue). Each LED draws about 20mA when lit at full brightness. So if you have the segment set to full white, that will be 120mA from a 5V supply.

Each meter has 16 segments, 32 LEDs so we multiply 16 * 120mA to get the maximum current. Per meter, this comes out to 1.92 Amps. Since the chips also draw a little power, we will round this up to 2A per meter!

For this reason we suggest getting a large power supply. You can use an ATX power supply (available at every computer or electronics store, really!) and connect the PWR_ON green wire on the large ATX plug (leftmost in the image above) to ground (black) to activate it. Then grab 5V and ground from one of the 4-pin hard drive connectors.

In reality, this is an upper limit. If your project doesn't light up all the LEDs, and uses colors instead of just bright white, the power usage will be a quarter or half. Either way, you'll want to keep this in mind, the power usage adds up and overdrawing from a small power adapter can damage it permanently

Which type of strip do I have?

As we mentioned, there are two strips you may have. If you ordered before August 2011 its going to be the HL1606 type, otherwise you probably have the LPD8806 type. Its not too hard to tell the difference. Look at the segments of the strip and find the 'pads' on the side of each 2.5" segment. The HL1606 strips have 6 pads on each side. the LPD8806 have 4 pads on each side:

This is what the HL1606-based strip segments look like:

the LPD8806-based strip looks like this (its thinner, and has fewer 'pads' on the side)

Wiring the LPD8806 based strips

This wiring tutorial is for the LPD8806 only - its a little bit different than the HL1606 so if the photos don't match up, check which kind you have!

The toughest part of the project is probably just soldering to the strip, its very easy to use! First, cut the piece to the length you want, on the cuttable boundaries. Next, tin the 4 INPUT pins (make sure you're connecting to 5V/CI/DI/GND which is input, not the corresponding 5V/CO/DO/GND pins!). To make the images clearer, we removed the plastic covering for this tutorial. However, you can just cut a little bit away on yours to allow you to access the pads. Once you take off the plastic cover its a bit difficult to get it back on

JUST BECAUSE YOU HAVE A STRIP WITH WIRES SOLDERED ON DOES NOT MEAN THEY ARE ON THE RIGHT SIDE, THEY COULD BE ON THE OUTPUT PINS. CHECK THREE TIMES TO MAKE SURE YOU ARE CONNECTING TO THE INPUT SIDE!

Tin the pads by carefully melting a little solder onto the pads

Start by soldering a red wire to the +5V power line

Next connect two wires to the data and clock pads. We'll use yellow for the Clock pin (CI) and green for the data pin (DI)

Finally, solder a black wire to ground

That's it! Now you're ready to use the strip. You may want to use heatshrink to provide a secure cover for the wires, or stuff hotglue in the end, which will do the same.

Wiring the HL1606 based strips

This wiring tutorial is for the HL1606 only - its a little bit different than the LP8806 so if the photos don't match up, check which kind you have!

The toughest part of the project is probably just soldering to the strip, its very easy to use! First, cut the piece to the length you want, on the cuttable boundaries. Next, tin the 6 INPUT pins (make sure you're connecting to SI/CI/DI/LI which is input, not the corresponding SO/etc pins!)

JUST BECAUSE YOU HAVE A STRIP WITH WIRES SOLDERED ON DOES NOT MEAN THEY ARE ON THE RIGHT SIDE, THEY COULD BE ON THE OUTPUT PINS. CHECK THREE TIMES TO MAKE SURE YOU ARE CONNECTING TO THE INPUT SIDE

Tin the pads by carefully melting a little solder onto the pads

Solder the +5V power wire to the +5V pin, we'll use red

Connect the ground signal/power pin to GND - we'll use black

Follow up by connecting the data lines. We wont be using the SI pin (the strobe function of the chip is not supported by our example code), so connect Yellow to LI (latch), Green to CI (clock), and Blue to DI (data)

Great! You're now ready to use the strip. You may want to use heatshrink to provide a secure cover for the wires, or stuff hotglue in the end, which will do the same.

Basic Usage

The HL1606 is not a common chip for most people, so the best way to explain it is to say its basically a 74HC595. Like a '595 there is an SPI input and then there is a shift-output so you can chain them. The HL1606 has 6 outputs and they're specifically for driving LEDs. The most basic way to use them is to set each LED on or off. This means you can have up to 8 primary 'colors' on an LED: red, yellow, green, teal, blue, violet, white and black.

There are some pros and cons to driving the strips this way,
Pro: Very simple, easy and fast. Use any 3 pins, No interrupts or constant updating required
Con: Only a handful of colors

Let's get the strip up and running using this method to start

The most important thing to remember is that you need a lot of current (power) to drive these strips (see above) so you will need to arrange a 5V power supply.This test will require about 1 Ampere per meter!

Note in the image above that the 5V can come from a separate power supply that can provide the power you need. Be sure to tie the grounds together and check the polarity, sticking -5V by accident into the strip could be a sad and expensive mistake. We'll be using an Arduino to demonstrate the strip but the code can easily be ported to your favorite microcontroller.

Note that we have Latch connected to digital I/O pin #2, Clock connected to #3 and Data to #4

Now visit our github repository and click on the Downloads button in the top right corner to download a zip of the library and examples. Uncompress the folder and rename it HL1606strip make sure that inside that folder is the cpp and .h files. Then copy it to your arduinosketchfolder/libraries folder. See our tutorial for more details.

Restart the Arduino software. You should see a new example folder called HL1606strip and inside, an example called basicPatterns. Upload that sketch to your Arduino. You should see the following!

The Adobe Flash Plugin is needed to display this content.

You can change how long the strip is by adjusting the object creation (instantiation) line

HL1606strip strip = HL1606strip(STRIP_D, STRIP_L, STRIP_C, 32);

The last argument "32" is the number of LEDs to address. Count how many are in your strip! The display may be wonky otherwise

The basicPatterns sketch has many examples of how to set the color of each pixel by calling

 strip.setLEDcolor(**n**, **COLOR**);

where n indicates which LED you want to change and COLOR is RED, YELLOW, GREEN, TEAL, BLUE, VIOLET, WHITE, or BLACK. After you've set the pixel color, you need to save the changes to the strip by calling

 strip.writeStrip();

writeStrip() isnt very fast, it will take a few milliseconds to write the changes and it takes longer the more LEDs there are. So change all the LED's you want at once and then write them!

Advanced Usage

Now that you have the basics down, we can get a little more complicated. The really fun part about color LEDs is not just having 8 primary colors but having hundreds or thousands of colors! Again, as we said before, the HL1606 is a rather stupid chip, it is just a shift register. It doesn't really have a PWM system built in which is why it is so low power and low cost. However, we can coax it into display many colors by writing data to the strip really fast. This will PWM the entire strip and will create a blended color effect.

The trade off with the added color-space is that we need to use an interrupt (we use timer #2) to refresh the strip constantly and that the arduino has to do a bunch of crunching in the background.

Pro: Hundreds/thousands of colors!
Con: Uses timer #2, must use hardware SPI on pins 11, and 13, uses background CPU

To wire this up, we'll have to make a small change. The clock and data lines must now connect to the hardware SPI pins to be fast enough. On atmega168/328 Arduinos, this means 11 and 13 are used for Data and Clock output (for the Mega, pins 51 and 52). The latch pin (L) can be any pin but pin 10 (Arduino) or 53 (Mega) but it MUST BE AN OUTPUT!

Now visit our github repository and click on the Downloads button in the top right corner to download a zip of the library and examples. Uncompress the folder and rename it HL1606stripPWM make sure that inside that folder is the cpp and .h files. Then copy it to your arduinosketchfolder/libraries folder. See our tutorial for more details.

Restart the Arduino software. You should see a new example folder called HL1606stripPWM and inside, an example called colorswirl. Upload that sketch to your Arduino. You should see the following!

The Adobe Flash Plugin is needed to display this content.

(Our camera's sensor didn't film the PWMing very well, its not that flickery in person)

This sketch and library is a little more complex than the one before but should be pretty easy to adapt. Change the object instantiation so the first argument is the number of LEDs in the strip

 HL1606stripPWM strip = HL1606stripPWM(32, latchPin); 

You can then set the color LED resolution, hardware SPI interface speed and how long you're willing to spend on PWMing the strip:

  // You can customize/control the pulse width modulation and color 
  // resolution by setting how many bits of PWM you want per LED
  // For example, 3 bits is 8 different PWM values per LED and 9 bits, 512
  // values for full color. 4 bits is 16 PWM per LED, 12 bit color with
  // 4096 different colors available.
  // Increasing the PWMbits by 1 means you need *TWICE* as much CPU !!!
  // We suggest starting with 3 and tweaking the other variables to get
  // the fastest SPI and maximum CPU. Then try upping this to 4. For short
  // strips (like 1 meter) that are ok with SPIdiv of 16, you can try 5
  strip.setPWMbits(3);
 
  // We use the built-in hardware SPI module. We can change the speed
  // of the module to push data out faster. In theory, HL1606's should work with
  // the SPI divider set to 16 but we found that this makes some strips
  // spaz out. Start with 32 and once it works try reducing it to 16
  // If you're lucky, you can even try 8 
  // Valid divider values are: 2, 4, 8, 16, 32, 64, and 128, dont try others!
  strip.setSPIdivider(32);
 
  // all the hard work of running the strip is done in an interrupt
  // we can configure the interrupt so that we spend more or less
  // time running the strip, letting you do other stuff like sensors
  // or an LED or whatever. Set it between 0 and 100, where 100 means
  // higher quality colorstrip display but no time for anything else.
  strip.setCPUmax(70);    // 70% is what we start at

The initial settings are a good place to start. You can then tweak the values as necessary. Although it may seem like 70% CPU is a lot, the vast majority of Arduino projects we have seen use only maybe 10% of the CPU usage, a lot of time is spent waiting for input.

Updating the SPI divider to be lower (faster) is 'free' so do that first. Then you can change the PWMbits as you'd like, and finally the CPU max to get good refresh performance

/home/ladyada/public_html/wiki/data/attic/tutorials/products/digitalrgbledstrip/index.html.1313008245.txt.gz · Last modified: 2016/01/28 18:05 (external edit)