1

I have a fairly substantial hardware control application that I'm currently running on a RPI 3b. I'm using nearly every pin on the GPIO, including using PWM output, I2C and multiple 1-wire buses. The application uses pigpio (python bindings) to control the GPIO/PWM/I2C and w1thermsensor to do the 1-wire temperature readings

I'd like to update to RPI 5, but as I understand it, the major hardware changes involved mean that pigpio will no longer work and there doesn't seem to be much sign of that getting fixed any time soon. I've checked out various other libraries briefly like WiringPi, gpiod and gpiozero but they all seem to have limitations/problems that make the choice non-obvious:

  • WiringPi -> although there's a new fork that supports rpi5, I can't find any new python bindings for it. I'm really not interested in having to write my own at this point; I'm not a C programmer. But maybe I've just missed where I can get the python bindings (or can I just use the old ones?)
  • gpiod -> doesn't seem to have any DMA support, maybe not important. Doesn't seem to be any documentation for python bindings. Not enormously excited about the idea of having to guess at the python API without any docs
  • gpiozero -> seems too opinionated. I already have all my IO code written based on direct access to the GPIO using pigpio, converting it all to use a "device-based" library is going to be a bit of PITA. Can't see any I2C support.

Although I'm using the hardware PWM outputs, both these and the I2C bus are operating at relatively slow speeds so I can probably get away without hardware support in a pinch, providing that I can still use the same pins on the GPIO header (I have a whole load of downstream breakout boards etc that I really don't want to have to rebuilt and test for a new pin config.

I'm hoping that w1thermsensor will just continue to work as before.

I'm guessing I'm going to have to accept that this upgrade isn't going to be painless. Can anyone suggest what the least painful way of converting my existing python code for pi 5 would be?

hollandlef
  • 121
  • 4

1 Answers1

1

I would suggest you forget any attempt to upgrade your code. There are so many differences this would be a nightmare. I suggest you write new code building up each functional block one by one.

If you want to use gpiod the version included in Raspberry Pi OS is 3 years old and has been replaced by V2.
This can be installed in a virtual environment using pip and is more usable. Having said that the documentation leaves a lot to be desired (it assumes a good understanding of the gpiochip interface), but it does have internal documentation which you can access via the normal python methods.

NOTE gpiod ONLY supports GPIO functionality it was never intended to support other functions. To use I²C you need to use the kernel functionality.

NONE of the existing libraries support hardware PWM, only software PWM.

Note gpiozero uses lgpio as its underlying library. lgpio is reasonably documented and behaves more like the older libraries and includes software timed PWM.

There is kernel support for PWM using the sysfs interface, but poorly documented. I have not been successful in getting it to work on Pi5, but Seamus has posted some code in another answer.

I have pretty well given up on PWM on Pi5 and use a Pico, which supports 8 hardware PWM blocks, each block has two signal outputs, for a total of up to 16 PWM outputs.

Seamus
  • 23,558
  • 5
  • 42
  • 83
Milliways
  • 62,573
  • 32
  • 113
  • 225