View: 1053|Reply: 0

picar pro code lesson 8 not working (led ws2811)

[Copy link]

1

Threads

1

Posts

15

Credits

Newbie

Rank: 1

Credits
15
Post time 2021-8-19 22:58:39 | Show all posts |Read mode
i am trying to run the code from lesson 8 (picar pro) but i keep getting errors.
see code and errors below.

code:

import time
from rpi_ws281x import*

class LED:
    def __init__(self):
        self.LED_COUNT = 3 # set to the total number of LED lights on the robot, which can be more than the total number of LED lights connected to the Raspberry Pi
        self.LED_PIN  = 12 # pin LED
        self.LED_FREQ_HZ = 800000
        self.LED_DMA = 10
        self.LED_BRIGHTNESS = 255
        self.LED_INVERT = False
        self.LED_CHANNEL = 0

        #use the conf items above to create a strip
        self.strip = Adafruit_NeoPixel(
        self.LED_COUNT,
        self.LED_PIN,
        self.LED_FREQ_HZ,
        self.LED_DMA,
        self.LED_INVERT,
        self.LED_BRIGHTNESS,
        self.LED_CHANNEL
            )
        self.strip.begin()

        def colorWipe(self, R, G, B): #this function is used to change the LED
            color = Color(R, G, B)
            for i in range(self.strip.numPixels()): # Only one LED light color can be set at a time, so a cycle is required
                self.strip.setPixelColor(i, color)
                self.strip.show()# After calling the show method, the color will really change

if __name__ == '__main__':
    led=LED()
    try:
        while 1:
            led.colorWipe(225, 0, 0) #LEDS turn red
            time.sleep(1)
            led.colorWipe(0, 225, 0) #LEDS turn green
            time.sleep(1)
            led.colorWipe(0, 0, 225) #LEDS turn blue
            time.sleep(1)
    except:
         LED.colorWipe(0, 0, 0)  #Turn off all lights  


errors:

Can't open /dev/mem: Permission denied
Traceback (most recent call last):
  File "/home/pi/python/picar_pro_codes_self/leds2.py", line 33, in <module>
    led=LED()
  File "/home/pi/python/picar_pro_codes_self/leds2.py", line 24, in __init__
    self.strip.begin()
  File "/usr/local/lib/python3.7/dist-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)

Reply

Use magic Report

You have to log in before you can reply Login | Sign Up

Points Rules