TransWikia.com

Hardware PWM for Python 3.5 or higher?

Raspberry Pi Asked by Nic on December 14, 2020

I am developing a camera tracker to follow objects identified via OpenCV in a dedicated environment on mt Pi3. Currently the two SG90 servos are controlled by software PWM using RPi.GPIO – but the tracking is jittery and unstable.

I am considering implementing hardware PWM to improve stability. I am aware of pigpio, wiringpi and RPIO that offer hardware PWM, but as far as I can tell(?) they currently support only up to Python 3.3 and I am using Python 3.5.

Any suggestions for a library to work with Python 3.5 or 3.6? So far I have stumbled on pwmpy that requires a kernel overlay: https://github.com/scottellis/pwmpy


Results of software PWM vs hardware PWM on servo stability

After sorting out the Python version issues (thx @joan), I can now report back on the performance of the two tracking servo’s using software and hardware PWM.

Software PWM implemented via RPi.GPIO

Software PWM implemented via RPi.GPIO

Hardware PWM implemented via pigpio

Hardware PWM implemented via pigpio

Comparing the Standard Deviations clearly shows the improved stability of hardware PWM. Since the image processing is taking a lot of CPU resources, software PWM suffers and is visibly jittery with occasional big jumps. None of that with the hardware PWM and the bit of variation reflected in the numbers is probably due to slight variations in the image object identification and not the PWM server.

One Answer

For pigpio it may be as simple as building an appropriate version for your Python version, e.g. perhaps try python3.5 setup.py install (in the pigpio build directory).

Alternatively you could use the command line I/F to wiringPi (gpio) or pigpio (pigs).

Answered by joan on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP