This tutorial is aimed at getting some instant gratification from your WS2812 LEDs (also known as NeoPixels). We'll briefly cover a bare-bones setup for Raspberry Pi. This tutorial will work with ANY model Raspberry Pi, the Zero WH, 3B+ or 3A+ (as well as older models)!
If you've never used a Raspberry Pi before, we've got you covered with our free, online Raspberry Pi for Beginners Workshop. If you've covered at least Chapter 1 then you're ready to follow these instructions!
Parts Required for this Project
- A Raspberry Pi
- A Logic Level Converter
- Some WS2812 or NeoPixel LEDs
- A 5V Power Supply (Optional)
- A DC Barrel Jack to 2-Pin Terminal Block Adapter (Optional)
Connecting the LEDs
The Raspberry Pi uses 3.3V Logic, So we will need to use a Logic Level Converter to convert it to the 5V logic that WS2812/Neopixels require.
You will need to use an external power source, as NeoPixels take a LOT of power. Each pixel will draw about 20mA on average, and 60mA at white - max brightness. 30 Pixels will draw 600mA on average, and up to 1.8A. Ensure your power supply is large enough to drive your strip!
Here's the wiring used in the video (click for hi-res):
The Code
First, install the Python support for WS2812B LEDs:
curl -L http://coreelec.io/33 | bash
Navigate to the examples directory
cd rpi_ws281x/python/examples/
Execute the strandtest script (must use sudo)
sudo python strandtest.py
That should be all there is to it! Your LEDs should be running the same pattern you see in the video.
Troubleshooting: If your LEDs only flicker erratically instead of performing a nice demo we need to make some edits to /boot/config.txt, execute:
sudo nano /boot/config.txt
and either uncomment or add the following lines:
hdmi_force_hotplug=1
hdmi_force_edid_audio=1
save, reboot, and reattempt to run strandtest.py as above.
As always, if you have any troubles then reach out to us in the comments section below. We're full-time makers and we're here to help!
References
The one-line install command is just a simple script that automates the commands listed in Adafruit's NeoPixel tutorial. Follow the link if you want to see what's happening behind the scenes. To see the contents of the script before you run it, save it to a file with:
curl -L http://coreelec.io/33 >> ws2812-installer
Jeremy Garff's Github Repository - Issue #103
Looking to install the python library from the command line? You can use pip to easily install the appopriate libraries using the line below.
sudo pip install rpi_ws281x
You can also find the releases of this here: https://github.com/rpi-ws281x/rpi-ws281x-python/releases
Going Further
Are you looking to add WS2812/NeoPixel LEDs to your other project but you aren't using a Raspberry Pi? Check out our other guides to get you started on other hardware types:
- WS2812 / NeoPixel Addressable LEDs: Arduino Quickstart Guide
- WS2812 / NeoPixel Addressable LEDs: Pycom Quickstart Guide
- WS2812 / NeoPixel Addressable LEDs: Particle Quickstart Guide
Need to take one step back and figure out what these fandangled NeoPixels even are? Check out our What Are NeoPixel LEDs Guide!