WS2812B RGB LED Strips Raspberry Pi Python Issues

Hi,
I’m trying to simply turn on my LED strip as per this tutorial

This is my basic code for it:

import time
import board
import neopixel

pixels1 = neopixel.NeoPixel(board.D18, 55, brightness=1)

pixels1.fill((0, 220, 0))

but I get an error saying:

  File "/home/pi/ledtest.py", line 8, in <module>
    pixels1 = neopixel.NeoPixel(board.D18, 55, brightness=1)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/env/lib/python3.11/site-packages/neopixel.py", line 141, in __init__
    self.pin = digitalio.DigitalInOut(pin)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/env/lib/python3.11/site-packages/digitalio.py", line 193, in __init__
    self.direction = Direction.INPUT
    ^^^^^^^^^^^^^^
  File "/home/pi/env/lib/python3.11/site-packages/digitalio.py", line 223, in direction
    self._pin.init(mode=Pin.IN)
  File "/home/pi/env/lib/python3.11/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 40, in init
    GPIO.setup(self.id, GPIO.IN)
RuntimeError: Cannot determine SOC peripheral base address

I’m using Raspberry Pi 5, Bookworm OS Desktop. I wired everything as per the tutorial.

Please help

1 Like

Probably the code will work with a Bullseye OS, Bookworm needs a virtual environment setup.
I started to test this and it complained about rpi_ws281x being an externally managed environment.
I will set that up and post here results, but a quick fix might be loading Bullseye OS.

Cheers
Jim

PS or someone else might have a solution for you.

EDIT: As posted by someone else the --break-system-packages flag might allow it to work.
ie. sudo pip3 install rpi_ws281x --break-system-packages
But didnt install the packages correctly when I tested it.

Suggest reading the page below. Note the two warning messages.
The date on this web page is 15 Jul 2024.

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. Failing to do so can result in a segmentation fault.

If you have the Pi 5, Neopixels are not currently working due to a change in the GPIO controls.

The original Core electronics guide is a little old now me thinks.
Regards
Jim

It certainly is! we’ll capture this improvement for the team to update. Thanks @James46717

1 Like

Alright, hopefully there is a fix for this because I am using the Raspberry Pi 5 running Bookworm, but I guess it won’t work for now. Thanks everyone!

The issue has been discussed here: https://forums.raspberrypi.com/viewtopic.php?t=361218 You can take a look.

Yeah I know it’s because of the GPIO for RPi 5, but it’s the neopixel module which has to be updated. They are just talking about accessing GPIO on the high-level, but I need it to interface with the WS28112B

Adafruit has suggested using SPI (Page 8 of this guide) to use Neopixels on the Pi 5. They have also put together another guide to walk you through it. Hopefully this can get your project back on the road.

3 Likes

Yeah, I used SPI and it works! Thanks everyone

1 Like