This technique can be used to connect a strip of any length and dynamically determine the number of LED pixels on the strip at start up. This allows for trading out light strips of different lengths without changing the code, as long as the maximum number of LED pixels set in the code is greater than the number of the longest light strip that might be used.
The disadvantage of this technique is that you need a physical connection to the end of the light strip. It would be really cool if they added a 5th connection to the strip that was pass through. Then the DO at the end of the strip could be connected to the pass through line and all the connections here could be at the beginning of the strip.
Click Here to get the Code
LPD8806 RGB Light Strips and SPI
The LDP8806 light strips are used as a slave device on a SPI bus to transfer data to each pixel in the strip.The hardware SPI (Serial Peripheral Interface) available on the Arduino Mega 2560 is on Pins 50, 51, and 52. The Arduino is the master device, and the light strip is the slave device.As shown in the image below, pin 52 is the CLK (Clock), pin 51 is the MOSI (Master Out Slave In), and pin 50 is the MISO (Master In Slave Out). The MOSI and CLK pins are used to send data to the light strip. The MISO pin will be used to receive data from the light strip.
Arduino Mega 2560 Hardware SPI Pins |
LPD8806 RGB Light Strip Pins |
At the beginning of the light strip, the DI and CI pins are the Data In and Clock In pins. The DI pin is connected to the Arduino MOSI (pin 51) and the CI pin is connected to the Arduino CLK (pin 52).
The DO pin at the end of the strip is connected to the MISO (pin 50) on the Arduino. If this pin is not connected, you will never receive data back from the strip!
Powering the Light Strips
The light strip requires an external 5 volt power supply. The Arduino cannot supply enough power to run these strips.
Step 1: Making the Hardware Connections
Parts Needed:
- Arduino Mega 2560 ($16)
- LPD8806 RGB LED Light Strip ($30)
- Power Supply to supply 5 Volts to light strip - I used an old PC power supply but this one will also work, Power Supply + 5 volts ($8)
- You may also need connectors to connect the power supply to your bread board depending on your setup
- A bread board
- Some connection wires
- A Soldering Iron (to make connections to the light strip)
- A voltage meter to measure supply voltages and ensure they are at or around 5 volts.
Here is the diagram of the circuit I used:
Circuit Diagram: LPD8806 RGB LED Light Strip and Arduino Mega |
Connections:
Connections at the START side of the Light Strip
- Identify the START side of the light strip, this is the side with the labels DI, and CI on the two center connection pads. Connect the GND on START side of the light strip to the power source GND on the bread board.
- Connect the +5V pad on the START side of light strip to the power source +5V on the bread board.
- Connect the DI pad on the START side of the light strip to the Arduino Mega's MOSI (pin 51).
- Connect the CI pad on the START side of the light strip to the Arduino Mega's CLK (pin 52).
Connections at the END side of the Light Strip
- Connect the DO pad on the END side of the light strip to the Arduino Mega's MISO (pin 50).
- Optionally, you can also connect the GND and +5V on the END side of the light strip to the power source GND and +5V.
Additional Arduino Connections
- Connect the Arduino Mega GND pin to the GND from the power source.
- Plug in the USB connection from the Arduino to your Computer.
Make sure the power to your power source is turned on.
Step 2: Loading and Running the code
- Click here to download the sketch for the Arduino.
- Open the Sketch in the Arduino IDE.
- Select the Arduino Mega 2560 under Tools->Boards in the Arduino IDE
- Make sure the Port for the Arduino is selected under Serial Ports
- Change the maxLEDs value in the code to your preferred maximum. This should be a number larger than the largest number of LED pixels any of your LED strips might have.
- Compile and Upload the sketch. The code will start running immediately and the LED's on the light strip should turn blue one by one.
- Open the the Serial Monitor from the Arduino IDE to see the output from the code. If everything is wired correctly, you should see the following line at the end of the output with the correct number of pixels for your light strip:
"Found 64 LED pixels in the strip. - If the MISO/DO connection is not connected, then the following line will be seen at the end of the output:
"No Data received after testing the maximum number of LEDs 100 Is the DO on the light strip connected to the MISO pin?"