0

I am trying to control a E-Paper display using my Raspberry Pi 5. I want to use the gpiod library since it seems to be the best option (especially since RPi.GPIO is not supported on the Pi 5) together with spidev in python (suggestions for other libraries in python are welcome). I found out via

~ $ gpioinfo

that the GPIO-Pins are controlled by gpiochip4. When trying to access it with the following code:

import gpiod
from gpiod.line import Direction, Value
import time
import spidev
import logging

Configure the logger

logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(name)

Define the GPIO lines for the E-Paper display

VCC = 3.3 # 3.3V pin on the Raspberry Pi GND = 0 # Ground pin on the Raspberry Pi SDI = 10 # GPIO 10 (SPI MOSI) SCLK = 11 # GPIO 11 (SPI SCK) CS = 8 # GPIO 8 (SPI CE0) DC = 25 # GPIO 25 (Data/Command) RST = 17 # GPIO 17 (Reset) BUSY = 24 # GPIO 24 (Busy)

Configure the lines as output or input

config = { CS: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE), DC: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE), RST: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE), BUSY: gpiod.LineSettings(direction=Direction.INPUT) }

Request the lines

with gpiod.request_lines( "/dev/gpiochip4", consumer="e-paper", config=config ) as request:

...

it gives me the following error:

Traceback (most recent call last):
  File "/home/malte2/idefk/venv/main.py", line 31, in <module>
    with gpiod.request_lines(
         ^^^^^^^^^^^^^^^^^^^^
  File "/home/malte2/idefk/venv/lib/python3.11/site-packages/gpiod/__init__.py", line 54, in request_lines
    return chip.request_lines(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/malte2/idefk/venv/lib/python3.11/site-packages/gpiod/chip.py", line 315, in request_lines
    req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 16] Device or resource busy

I set the whole thing up in a virtual environment, using sudo does not change the error. How can I fix this/what do I need to do differently to be able to control the pins?

Kent Gibson
  • 244
  • 3
  • 11
dongxi
  • 9
  • 2

1 Answers1

0

Im not sure how your device would know it is busy without SDO (MISO) the thing that SPI devices use to write return data, but ... moving on:

you can investigate the "file"

sudo lsof /dev/gpiochip*

to see what process is using the device. "#..." might be where you gracefully close the device when the script closes or fails, we have no way to know that. if you find some other process using /dev/gpiochip, you could kill that process with sudo kill -9 PID or sudo pkill -9 processname and try again.

you could run sudo systemctl status pigpiod to see what the service is doing.