rm-hull / luma.core

A component library providing a Pillow-compatible drawing canvas, and other functionality to support drawing primitives and text-rendering capabilities for small displays on the Raspberry Pi and other single board computers.
https://luma-core.readthedocs.io
MIT License
149 stars 52 forks source link

Raspberry Pi 5 + SPI Display #268

Open brickbots opened 11 months ago

brickbots commented 11 months ago

Hello!

I'm working to port some working code to bookworm on a Raspberry Pi 5. This code works great on bookworm/RPI4, but with the RPI5 it's not able to initialize the SPI interface from the luma.core.interface.serial module.

Perhaps this is due to the new hardware controller on the 5?

Type of Raspberry Pi

Raspberry Pi 5

Linux Kernel version

Bookworm Linux pifinder 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux

Expected behaviour

I'm trying to initialize a waveshare 1.5" RGB OLED display based on the ssd1351 controller. Communication is via SPI

from luma.core.interface.serial import spi

# init display  (SPI hardware)
serial = spi(device=0, port=0)

Actual behaviour

Crashes with the error below

 serial = spi(device=0, port=0)
             ^^^^^^^^^^^^^^^^^^^^^
  File "...python/venv/lib/python3.11/site-packages/luma/core/interface/serial.py", line 302, in __init__
    bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
  File "...python/venv/lib/python3.11/site-packages/luma/core/interface/serial.py", line 190, in __init__
    self._DC = self._configure(kwargs.get("DC"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...python/venv/lib/python3.11/site-packages/luma/core/interface/serial.py", line 203, in _configure
    self._gpio.setup(pin, self._gpio.OUT)
RuntimeError: Cannot determine SOC peripheral base address
thijstriemstra commented 11 months ago

From https://forums.raspberrypi.com/viewtopic.php?t=361218:

RPi.GPIO, wiringPI, and pigpio do not work on the Pi5 which has new hardware for the GPIO.

Yikes.. Also see https://sourceforge.net/p/raspberry-gpio-python/tickets/214/

Have you tried a simple RPI.GPIO script on rpi5, e.g. a blinking led and does that work?

brickbots commented 11 months ago

Thank you! Yes I've tried and no it does not work... I've played a little bit with GPIOD and it's related python bindings, which seems to be the method that people are coalescing around. It theoretically works for RPI 3/4/5 and is fairly quick.... but I've not seen anything about SPI or I2C comms using that framework, just raw GPIO on/off.

I'll keep looking and if I can figure out the 'new' way to do SPI, maybe work on a PR. Just mainly wanted to see if anyone else had jumped into this yet or if there was some more clearcut solution.

thijstriemstra commented 11 months ago

I wasn't in a rush to get a new Pi5 so haven't run into the issue yet but surprised that no one posted a bug report before, also didn't see anything on twitter etc. Releasing a new Pi without RPI.GPIO etc software support is quite strange by rpi foundation.

brickbots commented 11 months ago

Agreed... even if the underlying hardware and memory mapping has changed, you'd think there could be some wedge or abstraction to allow most (all?) of the existing GPIO code to work....

Thank you for taking the time to think about this, and for the incredible Luma project. If it's okay with you, I'll keep this open as a reminder to keep checking back on the state of play for python/spi bindings.

outdoorbits commented 10 months ago

I just tested gpiozero as an alternative to RPi.GPIO for my project little-backup-box for the Raspberry Pi 4 and 5. This works for me on both the old and new hardware. However, I only tested it with inputs (buttons), not with outputs.