WS2812 Addressable LEDs: Raspberry Pi Quickstart Guide

Hi Naughton,

Interesting problem. I’d imagine this is being caused by a faulty connection, but as a test, do you have another microcontroller available that you could use to try and develop the rig without the Pi and see whether the issues are able to be replicated. Please let us know if you’re able to resolve your issue, as this would be very helpful for other users in the future.

All the best with it!

Core Electronics | Support

Hey guys! Great tut, thank you :smiley: Running into an error with my install maybe? Please halp.

Some trouble here…seems like I’m running into same problem with line 9 of the rpi_ws281x module:

pi@raspberrypi:~/rpi_ws281x/python/examples $ sudo python 
Traceback (most recent call last):
  File "", line 9, in <module>
    from rpi_ws281x import *
ImportError: No module named rpi_ws281x

Here’s my install log:

pi@raspberrypi:~ $ curl -L | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100   741  100   741    0     0    251      0  0:00:02  0:00:02 --:--:--   251
Hit:1 buster InRelease
Hit:2 buster InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.6).
git is already the newest version (1:2.20.1-2+deb10u3).
python-dev is already the newest version (2.7.16-1).
scons is already the newest version (3.0.1-2).
swig is already the newest version (3.0.12-2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Cloning into 'rpi_ws281x'...
remote: Enumerating objects: 831, done.
remote: Total 831 (delta 0), reused 0 (delta 0), pack-reused 831
Receiving objects: 100% (831/831), 362.70 KiB | 1011.00 KiB/s, done.
Resolving deltas: 100% (509/509), done.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Version version.h
CC      main.o
CC      mailbox.o
CC      ws2811.o
CC      pwm.o
CC      pcm.o
CC      dma.o
CC      rpihw.o
AR      libws2811.a
RANLIB  libws2811.a
LINK    test
scons: done building targets.
running install
running bdist_egg
running egg_info
creating rpi_ws281x.egg-info
writing rpi_ws281x.egg-info/PKG-INFO
writing top-level names to rpi_ws281x.egg-info/top_level.txt
writing dependency_links to rpi_ws281x.egg-info/dependency_links.txt
writing manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
reading manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
writing manifest file 'rpi_ws281x.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib.linux-armv7l-2.7
copying -> build/lib.linux-armv7l-2.7
running build_ext
building '_rpi_ws281x' extension
swigging rpi_ws281x.i to rpi_ws281x_wrap.c
swig -python -o rpi_ws281x_wrap.c rpi_ws281x.i
creating build/temp.linux-armv7l-2.7
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c rpi_ws281x_wrap.c -o build/temp.linux-armv7l-2.7/rpi_ws281x_wrap.o
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-InigCj/python2.7-2.7.16=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/rpi_ws281x_wrap.o -L../. -lws2811 -lrt -o build/lib.linux-armv7l-2.7/
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
copying build/lib.linux-armv7l-2.7/ -> build/bdist.linux-armv7l/egg
copying build/lib.linux-armv7l-2.7/ -> build/bdist.linux-armv7l/egg
byte-compiling build/bdist.linux-armv7l/egg/ to neopixel.pyc
creating stub loader for
byte-compiling build/bdist.linux-armv7l/egg/ to _rpi_ws281x.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying rpi_ws281x.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying rpi_ws281x.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying rpi_ws281x.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying rpi_ws281x.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
writing build/bdist.linux-armv7l/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/rpi_ws281x-1.0.0-py2.7-linux-armv7l.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing rpi_ws281x-1.0.0-py2.7-linux-armv7l.egg
Removing /usr/local/lib/python2.7/dist-packages/rpi_ws281x-1.0.0-py2.7-linux-armv7l.egg
Copying rpi_ws281x-1.0.0-py2.7-linux-armv7l.egg to /usr/local/lib/python2.7/dist-packages
rpi-ws281x 1.0.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/rpi_ws281x-1.0.0-py2.7-linux-armv7l.egg
Processing dependencies for rpi-ws281x==1.0.0
Finished processing dependencies for rpi-ws281x==1.0.0 

Hi Andrew,

Could you please use sudo nano when in the appropriate directory. Just to confirm that this issue isn’t being caused by any of the syntax within the script, as that appears to have the appropriate dependencies installed. Thanks.

Core Electronics | Support

Yes, I’m able to open in nano…

What is the default version of python?
From the cli prompt, “python --version”

The output above shows the rpi-2382x being installed for python 2.7, so if you are running python 3.6 it will not find it.

Hi @Bryce

From the readme for the git repository currently used by the tutorial:

This Python code is being phased out and replaced with

If you’re just looking to install the Python library, you can: sudo pip install rpi_ws281x or sudo pip3 install rpi_ws281x depending on your Python version of choice or find releases here:

So please update the tutorial to install the module with pip/pip3 as above.


Edit: fix autocorrect f*up

1 Like

Hey @Robin57159

Thanks for letting me know :+1:. I’ll add it as an edit to be completed with the next site updates.

Core Electronics | Support

Hey I have a strip of these leds, I followed the instructions above however only around 20 leds light up (out of the 150) and they flash erratically, I dont have a logic level shifter attached… would this be the problem?

Hi Harry,

It could be a few things. Are you supplying enough power?

I’d suggest starting a new topic with some photos of your wiring and code.

Support | Core Electronics

Hi @Harry129816

Let’s do a little math with the wild assumption that the individual LEDs will draw in the region of 10 to 20 ma.

We will need to be able to provide 1.5 to 3.0 amps to drive 150 LEDs. As @Oliver suggested, check your power source is capable of providing this.

Hello everyone,

I have a LED Strip of 1 meter with 60 LEDs. I use a switching power supply that give 5V and 10 A as output.
I am using a Raspberry pi 3 to address the LEDs through a logic converter 3.3V 5V.
When I am running with all the 60 LEDs it worked, but no LED light up.
I have cut one LED from the strip. When I am running with only one LED it worked, and the LED light up.
I think the problem is caused by a lack of power. What is the recommended switching power supply to get all 60 LEDs light up

Here is the link to the switching power supply, that I am actually using.

Best regards,
Wilfried Wakeu

Hi Wilfried,

That should be enough power for just 60 WS2812s (assuming this is indeed what you’re using?).

It is possible you’re running into a speed limit on your logic level converter, again, depending on what you’re using.

Can you make a new topic and give us some photos of how you’ve got everything wired up, and let us know exactly which LEDs you’re using?

Support | Core Electronics

In your example, the Pi is being powered by a separate power adapter. I’d like to power both the Pi and LEDs using the same 5V DC power plug. Is it permissible to connect a wire from the 5V adapter to one of the 5V pins on the Pi? If not, how should it be wired?

Thank you!

Hi @Thomas137604

You haven’t specified what connection is on the power supply you intend using, but there are adapters available to add screw terminals to the supply. One of the most common is this one:

1 Like

Hi @Robin57159 - thank you for your reply! That is the jack I’m using. I just want to be sure it is ok to connect the 5V from the barrel jack directly to the 5V pin on the Pi.

Hi @Thomas137604

Yes you can connect a 5v supply to the RPi gpio pins to power it. Here’s an article from the MagPi magazine about powering the RPi.

Now go to bed :grinning:


When i tried to run the code to test the LED’s i received the error: Could not resolve host:

That domain definitely still exists. Which part of your code is throwing the error? Have you got an internet connection?

Hi guys. I have this all working on a Raspberry Pi 3 Model B V1.2.

I am trying to use it to drive 4 WS2815 strips. When I put one strip on GPIO18 (PIN 12) and one on GPIO 13 (PIN 33) I can drive both strips and everything works fine. I’m trying to find another 2 GPIO pins I can use in this way. The only other two pins I can seem to use without causing a seg fault are GPIO 19 and 12. However, when I connect all 4 strips, I get odd behavior. What I tell the strip on GPIO 18 to do, the strip on GPIO 12 also does and what I tell the strip on GPIO 13 to do the strip on GPIO 19 also does. Any ideas how I can control 4 strips independently?

EDIT Upon further reading, it appears only the PWM module can control two strips independently but can control up to 2700 LED’s. My strips contain 480 each so I believe I can connect the end of one to the start of another to enable control of all four. This will make coding difficult since I’ll have to create a second set of functions that start at LED 481 for the secondary strips… Any other ideas are welcome

Thank you!

Hey Paul,

It sounds like you’ve found the best option, in this case, I’ve checked in on other solutions, and generally, the best way to be able to get away with it is to use a separate microcontroller as a driver for your LED and then communicate with that from your Pi, but in your project, that likely defeats the purpose of using the Pi for control in the first place. Make sure to let us know how you go with your project!

Core Electronics | Support