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?

1
  • It is far from clear what you have ACTUALLY done. If you WANT to use gpiod install the system version using apt (although this is deprecated it does work). If you use a virtual environment (how did you setup?) you can NOT use sudo in your code.
    – Milliways
    Commented Jul 25 at 23:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.