WS2812 / NeoPixel Addressable LEDs: Raspberry Pi Quickstart Guide

Updated 17 October 2022

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

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):

ws2812B-neopixel-wiring-schematic-raspberry-pi

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 

Adafruit Neopixel Uberguide

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:

Need to take one step back and figure out what these fandangled NeoPixels even are? Check out our What Are NeoPixel LEDs Guide!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.