The place where random ideas get written down and lost in time.
2024-10-06 - PiFace on Raspberry Pi 4 with Linux Kernel 6.x
Category DEVPi5 uses the latest version of the “Raspberry Pi OS”, which is currently Deban bookworm with a Linux kernel 6.6.51. That breaks some stuff expected by the Piface “pifacedigitalio” library.
The first (unexpected) change is that we can’t use PIP to install packages in the system-wide Python provided by the Debian install. Instead a virtual env is enforced to ensure such packages do not break the entire system.
There is apparently a flag “pip --break-system-packages” that works around that check, and interestingly that option is not in the man page.
For a quick test, there’s some value in using a virtual env folder that I’m going to trash later.
The next realization is that none of the stuff works anymore:
Error “No such file or directory: '/sys/class/gpio/gpio25/value”
On an RPi 1, that means the user is not part of the group “gpio”.
Here it is apparently due to the fact that the GPIO driver has been changed and the “sysfs” paths are no longer valid. Fun. The core issue seems to be with GPIO interrupts here: https://github.com/piface/pifacecommon/blob/master/pifacecommon/interrupts.py
This describes the (now deprecated) sysfs interface: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
Translating these:
- The old way was to “echo 25 > /sys/class/gpio/export”
- That would make create/expose “/sys/class/gpio/gpio25/” at which points the pseudo files for direction etc could be used.
However:
- Instead now we have /sys/class/gpio/gpiochip512/base (512) + /sys/class/gpio/gpiochip512/ngpio (58) which means this controller handles gpio’s in the range 512..up to 570 excluded. Then there’s “gpiochip570” which has base=570 and ngpio=8.
- “$ gpioinfo | grep 25” ⇒ this lists all the pins and we can find that “GPIO25” is actually #25 (from 0-base) on that gpiochip0 which is actually the giochip512 above.
- 512 + 25 = 537… so that’s the new “sysfs” number for GPIO25.
- $ echo 537 | sudo tee /sys/class/gpio/export
- ⇒ And that makes “/sys/class/gpio/gpio537/” appear.
Thus in essence all we need is to “translate” the old GPIO number to the new sysfs numbers. Even though the sysfs interface is deprecated, it seems to still be present and should likely work as usual.
Considering that https://github.com/piface/pifacecommon/blob/master/pifacecommon/interrupts.py#L17 only seems to access one pin (GPIO25) this way and that we don’t need to be generic, it seems to me like a little fork of that project to rename the number to 537 would be just good enough for my needs. Let’s try that.
Here’s my fork with this change:
https://github.com/ralfoide/pifacecommon
and the documentation on how to use it:
# Create a new Python Virtual Environment
$ python3 -m venv my_piface
$ cd my_piface
# Install PiFaceCommon from a locally checked out source
$ git clone https://github.com/ralfoide/pifacecommon.git
$ bin/pip3 install pifacecommon/
# Install PiFaceDigitalio from the repository
$ bin/pip3 install pifacedigitalio
# Try one of the examples
$ git clone https://github.com/piface/pifacedigitalio.git
$ bin/python3 pifacedigitalio/examples/presslights.py