[Python] Using GPIO pin and neopixel Raspberry Pi 5, Failed to open PIO device (error -22)

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have switched from my Raspberry Pi 4 to Raspberry Pi 5 for computational power means for part of a project. I have encountered many errors trying to use NeoPixels on the pi5 (was working fine on the pi4), and none of the links on the internet have helped, so I will list the main things I have tried in search of an answer:


    1. Pi5Neo: https://pypi.org/project/Pi5Neo/ with example code. It was opening the SPI device but nothing was happening on the neopixels.


    2. The first AdaFruit solution: https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/using-neopixels-on-the-pi-5. After updating firmware and installing Pi5 blinka, ls -l /dev/pio0 still produced no such file or directory'


    3. The second AdaFruit solution: https://learn.adafruit.com/circuitpython-neopixels-using-spi. No issues were raised in the terminal but nothing happened on the pixels. When I run ls -l /dev/spi* I get:
    • crw-rw---- 1 root spi 153, 0 Mar 16 17:10 /dev/spidev0.0
    • crw-rw---- 1 root spi 153, 1 Mar 16 17:10 /dev/spidev0.1
    • crw-rw---- 1 root spi 153, 2 Mar 16 17:10 /dev/spidev10.0

    Code used:

    import time
    import board
    import neopixel_spi as neopixel

    NUM_PIXELS = 512
    PIXEL_ORDER = neopixel.GRB
    COLORS = (0xFF0000, 0x00FF00, 0x0000FF)
    DELAY = 0.05

    spi = board.SPI()

    pixels = neopixel.NeoPixel_SPI(
    spi, NUM_PIXELS, pixel_order=PIXEL_ORDER, auto_write=False
    )

    while True:
    for color in COLORS:
    for i in range(NUM_PIXELS):
    pixels = color
    pixels.show()
    time.sleep(DELAY)
    pixels.fill(0)
    '''
    '''
    import board
    import neopixel_write
    import digitalio

    pin = digitalio.DigitalInOut(board.D18)
    pin.direction = digitalio.Direction.OUTPUT
    pixel_off = bytearray([0, 0, 0])
    neopixel_write.neopixel_write(pin, pixel_off)


    1. Running using the neopixel blinka pi5 library: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/. With the below sample code:

      import neopixel
      import time
      import math

      #FREQS
      b_freq = 0.4
      r_freq = 1.0
      y_freq = 0.5
      g_freq = 0.8

      hell = 0.2

      pixels = neopixel.NeoPixel(board.D18, 512)
      #gpio-589
      #SETUP
      ORDER = neopixel.RGB

      #FIRST LIGHTS
      pixels[135] = (hell*255,hell*255,hell*255)
      pixels[375] = (hell*255,hell*255,hell*255)

    It came up with the error:

    File "/home/comarocket/old_scripts/neos_setup.py", line 97, in <module>
    neopixel_write.neopixel_write(pin, pixel_off)
    File "/home/comarocket/newenv/lib/python3.11/site-packages/neopixel_write.py", line 49, in neopixel_write
    return _neopixel.neopixel_write(gpio, buf)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    RuntimeError: Failed to open PIO device (error -22)


    I understand based on this link Not able to access GPIO pins on my Raspberry Pi 5 that I perhaps should not be using board.D18 to address the GPIO18 but rather something including the number gpio-589, but board.__dict__ didn't show anything of the sort.


    What to do?

    Continue reading...

Compartilhe esta Página