pythonpython-3.xraspberry-pineopixeladafruit-circuitpython-neopixel

isuue running rpi_ws281x(neopixels) using python on Rasberry pi 4


I have installed the files for ws2812 neopixels on raspberry pi 4b using :

curl -L http://coreelec.io/33 | bash

and ran the python strandtest.py I am facing an import error

File "strandtest.py", line 9, in <module>
from rpi_ws281x import *
ImportError: No module named rpi_ws281x

enter image description here

Eventhough rpi_ws281x has been installed successfully. While running the same code in the code editor, the module is imported properly and facing an other issue

>>> %Run strandtest.py
Can't open /dev/mem: Permission denied
Traceback (most recent call last):
File "/home/pi/rpi_ws281x/python/examples/strandtest.py", line 91, in <module>
strip.begin()
File "/home/pi/.local/lib/python3.9/site-packages/rpi_ws281x/rpi_ws281x.py", line 131, in begin
raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -5 (mmap() failed)

RBI_editor


Solution

  • Initially, We have to install circuit python on your R_PI.

    sudo apt-get update
    
    sudo apt-get upgrade
    
    sudo apt-get install python3-pip
    
    sudo pip3 install --upgrade setuptools
    

    follow the instructions in the link by adafruit: https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi

    and then run the example.