It’s time to get back to some lighting as I spent a little time enhancing my setup that I left off configuring in Making the Lights Dance. In my Building the RaspberryPi Christmas Light Box post, I blamed a friend for starting me down this path. Once again, I’m blaming a different friend for causing me to wander down the LED lighting road. This friend saw some of my posts regarding the simplistic lighting box I created, and they suggested that I tinker with WS2811 lights. Let the tinkering begin!
Hardware List
It’s always good to talk through the hardware that we’ll be using for this. To start, I extended my previous Building the RaspberryPi Christmas Light Box system to be able to do some LED lighting. Here are the items that I purchased from Amazon:
- ALITOVE 5V 3A 15W AC 100V~240V to DC Power Supply Adapter
- WESIRI WS2811 Diffused Digital RGB LED Pixel Lights
- ELEGOO 3pcs MB-102 Breadboard 830 Point Solderless Prototype PCB Board Kit
By the way, your hardware may vary slightly but I bought the 5v lights just because. There are LED tape strips and these 12mm bullets. There’s indoor only and IP68 rated. There are 12v lights and many other options to choose from. I just happened to pick these because they were the cheapest at the time.
Tiny Electrical Lesson on the Hardware
I’m not an electrician by any stretch of the imagination but I know a guy that helped me get through it a little. He’s more AC than DC but we had a good chat about it all (ok enough babbling on that).
There are some very important concepts to keep in mind on the power requirements. These important items were things that I had to dig up and learn from my electrician. I figured I’d drop them here to help anyone else going down the LED lighting route as blindly as I did. You need to make sure the output voltage on the power supply matches the input requirements on the lights. Aside from voltage drops (I’ll cover that in a later article when I go bigger on the system), the voltage will remain constant. I am using 5V lights so an adapter capable of outputting 5V was required.
Wattage is cumulative! This is a very important point to remember in all of this. The example lights used have a spec of roughly 0.3W per LED bulb. Each strand has 50 bulbs. If you take 0.3W * 50 bulbs, you get 15W. This means that a single strand of lights requires 15W of power. If you wanted to use two strands, you’d do 0.3W * 100bulbs for 30W of power required. This means that when you purchase your power supply, it will need to support 5V and 15W * <The number of strands>. Given the power supply listed above in the hardware list, I can only run a single strand of lights :facepalm: here. For those wanting to do more than one strand, I would suggest possibly getting the SHNITPWR 4V – 12V Power Supply 10A 120W AC to DC Adapter. This was used when I went bigger with the LED lighting.
The only other thing to keep in mind would be the data channel on the lights. The lights have 3 wires (5 if you count the separate power leads at each end of the strand but who’s really counting?) that supply power and data. The power has your standard +/- and the third middle wire is data. The nice thing is that data does not suffer from voltage drop like the power. Data is repeated at each bulb so it doesn’t lose signal (as long as you get good power to the first bulb. A warning I didn’t fully head until I built the bigger system. Again, more details later).
Connecting Everything
The awesome folks over at Adafruit have put together some really nice articles to also help out. In order to get everything up and running, it was pretty simple to follow their NeoPixels on Raspberry Pi Wiring guide (FYI, this guide contained the warning that I ignored regarding the data power requirements. They refer to it as level shifting. In my testing of a single strand and later connecting 8 strands, I had zero issues without doing the level shifting. The moment I wired everything up outside for the bigger system, I did end up needing to level shift 🙂 ). Ok so I ignored all warnings and went straight for wiring the light strand directly to my Raspberry Pi 4 along with adding the power supply.
I started with my mess of goodies
- Green == Data Wire
- Red == +
- White == –
With the power connected to the power plug adapter and the pigtail connected to the lights, I needed to connect everything to the Raspberry Pi. This is where the breadboard comes in:
With all of the hardware in place, it is now time to fire everything up and get the software we need to run this light show! I’m assuming you can login to your Pi and create a directory called LEDs. We’ll use this directory to house our testing code. I’m also going to assume that you are ok with using NodeJS (sorry I’ve been on a Javascript kick lately. There’s also Python code available to do this as well). Let’s get into that directory and install the rpi-ws281x-native library we’ll need to get the lights running:
$ cd LEDs/
pi@raspberrypi:~/LEDs $ npm install rpi-ws281x-native
npm WARN npm npm does not support Node.js v10.21.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
> [email protected] install /home/pi/LEDs/node_modules/rpi-ws281x-native
> node-gyp rebuild
make: Entering directory '/home/pi/LEDs/node_modules/rpi-ws281x-native/build'
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/ws2811.o
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/pwm.o
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/dma.o
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/pcm.o
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/mailbox.o
CC(target) Release/obj.target/rpi_libws2811/src/rpi_ws281x/rpihw.o
AR(target) Release/obj.target/rpi_libws2811.a
COPY Release/rpi_libws2811.a
CXX(target) Release/obj.target/rpi_ws281x/src/rpi-ws281x.o
SOLINK_MODULE(target) Release/obj.target/rpi_ws281x.node
COPY Release/rpi_ws281x.node
COPY ../lib/binding/rpi_ws281x.node
TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/home/pi/LEDs/node_modules/rpi-ws281x-native/build'
npm WARN saveError ENOENT: no such file or directory, open '/home/pi/LEDs/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/LEDs/package.json'
npm WARN LEDs No description
npm WARN LEDs No repository field.
npm WARN LEDs No README data
npm WARN LEDs No license field.
+ [email protected]
updated 1 package in 13.568s
pi@raspberrypi:~/LEDs $
With that all set and ready to go, I suggest grabbing the example libraries hosted in the rpi-ws281x-native GitHub repo. Note that you will need to modify the require lines in those scripts from:
var ws281x = require('../lib/ws281x-native');
to something like this:
var ws281x = require('rpi-ws281x-native');
From there, you can try and test out the one of the scripts. Remember, you must specify the total pixels that are in the strand to be tested. By default, the code will only light up 10 bulbs. The example below shows how you would run the command for all 50 bulbs in our example strand:
$ sudo node rainbow.js 50
Press <ctrl>+C to exit.
pi@raspberrypi:~/LEDs $
Very important to run them using “sudo” because the code requires root access in order to be able to properly signal the strand.
Video: The Example Scripts in Action
Here is an example of me running those scripts and the lights in action