-
-
Save chris-gong/fbebf494725cc762d731d567700fdafa to your computer and use it in GitHub Desktop.
from rpi_ws281x import * | |
# LED strip configuration: | |
LED_COUNT = 300 # Number of LED pixels. | |
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). | |
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0). | |
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) | |
LED_DMA = 10 # DMA channel to use for generating signal (try 10) | |
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest | |
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) | |
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 | |
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,LED_DMA,LED_INVERT,LED_BRIGHTNESS,LED_CHANNEL) | |
strip.begin() | |
for x in range(0,LED_COUNT): | |
strip.setPixelColor(x,Color(255,0,0)) | |
strip.show() |
@daggiemaggie I would suggest signing into your root account, or using sudo
before running any commands. For example, sudo python glow.py
.
Hi,
I am new to raspberry pi and coding with python. I was trying your code on my raspberry pi 4 (model B) but it gives errors like this:
Can’t open /dev/mem: Permission denied
Traceback (most recent call last):
File “/home/pi/Documents/glow.py”, line 12, in
Strip.begin()
File “/usr/local/lib/python3.7/dist-packages/rpi_ws281x/rpi_ws281x.py”, line 130, in begin
raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -5 (mmap() failed)The assistant in python also says that 'Adafruit_NeoPixel' and 'Color' are not defined.
Is there something I am doing wrong?
Thanks in advance :)
use LED_PIN = 10 instead of LED_PIN = 18
and go to interfaces under raspberry pi configuration and enable all the GPIO related interfaces (eg: SPI)
then without root also your program will work
Hi,
I am new to raspberry pi and coding with python. I was trying your code on my raspberry pi 4 (model B) but it gives errors like this:
Can’t open /dev/mem: Permission denied
Traceback (most recent call last):
File “/home/pi/Documents/glow.py”, line 12, in
Strip.begin()
File “/usr/local/lib/python3.7/dist-packages/rpi_ws281x/rpi_ws281x.py”, line 130, in begin
raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -5 (mmap() failed)
The assistant in python also says that 'Adafruit_NeoPixel' and 'Color' are not defined.
Is there something I am doing wrong?
Thanks in advance :)