Guide by Tim; Control Multiple Fully-Addressable WS2812B RGB LED Strips with a Raspberry Pi Single Board Computer

I have just shared content in Guides > Raspberry Pi: “Control Multiple Fully-Addressable WS2812B RGB LED Strips with a Raspberry Pi Single Board Computer”





Read more

3 Likes

Hi from the US, while following your tutorial I only managed to get the first two led lights to light up. I was wondering what the problem was and what I can do to fix it. Thank you so much!

3 Likes

Heyya Natasha,

Weird that it would do that. Double-check that your LED Count hasn’t been changed accidentally. You can see the section to change in the image below. Make that number match the number of LEDs that you have.

If that doesn’t work make sure to double-check all your connections. Pop some images of your wiring set up through as well so I can give it a quick look :blush:

Hope this sorts you,
Tim

3 Likes

Hi
None of the pixels light
I keep getting the following error using your code on a Pi 4 B
HELP !

Python 3.9.2 (/bin/python3)

%cd /home/michael/Desktop
%Run OneStripNeopixel.py
Can’t open /dev/mem: Permission denied
Traceback (most recent call last):
File “/home/michael/Desktop/OneStripNeopixel.py”, line 16, in
pixels1.fill((0, 220, 0))
File “/usr/local/lib/python3.9/dist-packages/adafruit_pixelbuf.py”, line 217, in fill
self.show()
File “/usr/local/lib/python3.9/dist-packages/adafruit_pixelbuf.py”, line 205, in show
return self._transmit(self._post_brightness_buffer)
File “/usr/local/lib/python3.9/dist-packages/neopixel.py”, line 180, in _transmit
neopixel_write(self.pin, buffer)
File “/usr/local/lib/python3.9/dist-packages/neopixel_write.py”, line 38, in neopixel_write
return _neopixel.neopixel_write(gpio, buf)
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/bcm283x/neopixel.py”, line 78, in neopixel_write
raise RuntimeError(
RuntimeError: NeoPixel support requires running with sudo, please try again!

1 Like

Hey Michael, welcome to the forums :smiley:
Refer to the last runtime error from your console: you need to run with sudo

try running thonny as sudo

sudo thonny

and then execute your script

2 Likes

Thank you

1 Like

Hi Natasha, I had exactly the same issue when trying to use a RPII 3A. When I swapped the SD card into a RPII 4 it worked fine.
Peter

2 Likes

Hey mate,

That seems pretty weird to me. Does that only happen when you run the | strandtest.py | script or when you run the | OneStripNeopixels.py |? I’d like to try to replicate it here.

If that is happening for me over here as well I’ll update the scripts so that they will run seamlessly on any Raspberry Pi Single Board Computer.

Kind regards,
Tim

1 Like

Hi Tim,
Happens on both. Have to wait a bit on one of them until it hits the first two leds. I can’t remember which one.
Cheers,
Peter

I don’t seem to be able get this code to run on a Pi-Top with an RPI3b+
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)

Tried it on 2 machines. The first one says
NameError: name ‘Adafruit_NeoPixel’ is not defined

The second says
Can’t open /dev/mem: Permission denied
Traceback (most recent call last):
File “strandtest.py” line 92, in
File strip.begin()

Has anyone made this code work?

2 Likes

Hey mate,

I have an idea of what could be going on. Open up a new terminal window by pressing the black button on the top left of the screen. Type and enter into it the following | sudo thonny |. That will open up a Thonny IDE instance which has administrator privileges. From there open and run the Python script as you would normally using this Sudo Thonny IDE.

If that doesn’t fix you right up I’ll set it up over here and figure it out :slight_smile: we’ll get your system running!

Kind regards,
Tim

1 Like

1 Like

Thanks Tim. Was using the default Geany but tried sudo Thonny. I got the same result. Screen shot share. Is the version of Python3 critical? say 3.7 vs 3.9?

1 Like

Update:
I have now tried this on a number of different PI-Top configurations with several different RPi3B+'s, a RPi3b, and RPi2B and can never get past the error:
NameError: name ‘Adafruit_NeoPixel’ is not defined.

Which is a shame, because that means we will not be able to use the Addressable ws2812RB demo in our STEM Labs as all their machines are Pi-Tops.

The only configuration that seemed to get pass the error and run was a fresh RPi OS build (Sept 2022/Debain 11) but in that one configuration only the first 2 leds of the 60 came on.

Until I came across
“Sound must be disabled to use GPIO18. This can be done in /boot/config.txt by changing “dtparam=audio=on” to “dtparam=audio=off” and rebooting.”

So it does work with under these 2 conditions. 1) clean current Raspberry Pi OS build 2) sound is disabled.

1 Like

Hey Dan,

Thank you kindly for your perseverance. We have replicated the problem here when using the Raspberry Pi 3 Model B and I have now updated the guide with a troubleshooting section.

Now everyone can successfully nail blinky lights with the Raspberry Pi Single Board computers no matter what version they have :blush:.

Kindest regards,
Tim

Sorry Tim,

I’m not following. Where is this “troubleshooting section”?

Did you find a fix or just confirm that there is a problem with RPi3B’s

Thanks,

Dan

1 Like

Tim,

Great article. I am new to this project and I have two questions.

  1. Why are GPIO pins 18, 21, 12, 10 used for multiple strings? Is this because they are PWM pins and that is how the brightness is controlled?

  2. I would like to use more than 4 strings of lights. Would I use these four and then use others for SPI or another protocol?

Thanks!
John

1 Like

Hey Dan,

The troubleshooting section is just at the bottom of the Flashy Demonstration section. Make sure your computer hasn’t cached the old page. Click on the below link to refresh the page on your system

And that section has the fix for the problem when using Raspberry Pi 3 Model B single-board computers. You will still need to disable the sound.

Kind regards,
Tim

Hey John

Thanks for your kind words! PWM is the method that WS2812B needs for the Data Pin. Those pins you listed, and in the article, are all Hardware PWM-capable pins (18, 21, 12, and 10). These will gain the best result when it comes to controlling WS2812B.

There is another way to produce PWM referred to as Software PWM. Any GPIO Pin can do this on a Raspberry Pi. This is a less uniform data signal and may result in a flickering light source. However, that is definitely a method to consider if you want to independently control more than 4 strings of addressable LEDs on a single Raspberry Pi.

A deep dive on this topic can be found here - gpio - What's the difference between soft PWM and PWM - Raspberry Pi Stack Exchange

Kind regards,
Tim

1 Like

Tim,

Thanks for the info. Last question. Is it reasonable to put 2 50-LED strings in series together and run those on those 4 pins? For a total 400 LEDs, 100 LEDs per pin? I know an external power supply could be needed, however.

Again, thank you for your help.

John

2 Likes