The pigpio library for GPIO control supports hardware timing for PWM and servo outputs, which provides much more accurate and jitter-free control. It can be used from gpiozero by setting the pin factory.
However, pigpio is not included in the latest version (“trixie”) of Raspberry Pi OS. This post summarizes how to build it from source.
Build and install the binaries
mkdir pigpio
cd pigpio
sudo apt install -y python3-setuptools python3-full
wget https://github.com/joan2937/pigpio/archive/refs/tags/v79.tar.gz
tar zxf v79.tar.gz
cd pigpio-79
make
sudo make install
sudo ldconfig
Create the service
You need to also create the pigpiod service file in /lib/systemd/system/pigpiod.service. This will start the service automatically when the Pi boots.
[Unit]
Description=Daemon required to control GPIO pins via pigpio
[Service]
Type=forking
ExecStart=/usr/local/bin/pigpiod -t 0 -l
Restart=always
ExecStop=/bin/systemctl kill pigpiod
[Install]
WantedBy=multi-user.target
-t 0is required when using I2S audio to avoid a GPIO pin conflict-
-ldisables remote access to the daemon
Then start the daemon:
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now pigpiod
That’s it.
