I want to, but somehow rarely follow the tried and true. It seems I have “stepped into it” again.
First, it was the gpg3_power.py
throwing
# pi@GoPi5Go:~/GoPi5Go/systests/gpg_power_service $ python3 gopigo3_power.py
# Traceback (most recent call last):
# File "/home/pi/GoPi5Go/systests/gpg_power_service/gopigo3_power.py", line 23, in <module>
# GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# RuntimeError: Cannot determine SOC peripheral base address
due to the RPi Foundation shipping PiOS Bookworm with a non-working RPi.GPIO package.
I rewrote the gopigo3_power.py as gopi5go_power.py using lgpio but today I found out I could have simply uninstalled the non-working version and installed a working version:
echo -e "Removing non-working RPi.GPIO supplied with Bookworm"
sudo apt remove python3-rpi.gpio
echo-e "Installing working RPi.GPIO "
sudo pip3 install rpi-lgpio --break-system-packages
Next, it was the issue of the GoPiGo3 class needing pigpiod
, (which is not available for Pi5), to setup the SPI pins on the Raspberry Pi GPIO connector for ALT0 mode. I commented out those six lines, and found that the PiOS Bookworm, (only PiOS version that runs on the Raspberry Pi 5), already sets the SPI pins to ALT0 mode. After building wiringPi from source on 64-bit PiOS Bookworm gpio readall
shows the pins are indeed set to ALT0 mode without my doing:
pi@GoPi5Go:~/GoPi5Go/systests/wiringpi $ gpio readall
+-----+-----+---------+------+---+---Pi 5---+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
...
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | - | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 |
...
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 5---+---+------+---------+-----+-----+
So not an issue (I still think).
BUT, hold on a second… during an overnight test gopigo3.spi_read_16()
which is used by gopigo3.get_voltage_battery()
threw: OSError: No SPI Response
and quit that test program.
SPI is supposed to be thread safe, so what gives. Apparently Dexter Industries thought there could be problems and wrote a check, but in 7 years of multi-threaded SPI calls on Carl with a Pi 3B and Pi3B+ he never complained.
I found only one person reporting SPI on the Pi5 having an issue - "Pi 5 SPI transaction latency under PREEMPT_RT and heavy loads". Long transfers is different than returning without the result ready, but does point to SPI acting differently on Pi5 due to the new RP1 chip handling the GPIO interfaces.
I ran a GoPiGo3 SPI get_voltage_battery test of over 80 million battery checks by four simultaneous running threads using a special “SPI fault tolerant” gopigo3.py , there were no SPI errors reported (but my safetyShutdown.py program that monitors battery health quietly shutdown without a way for me to know why…).
Life on the edge is never dull.