Building pigpio for Raspberry Pi OS “trixie”

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, for some reason, 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

sudo apt install -y python3-setuptools
wget https://github.com/joan2937/pigpio/archive/refs/tags/v79.tar.gz
tar zxf v79.tar.gz
cd pigpio-79
make
sudo make install

Testing the installation

The main part of pigpio runs as a background process (a “daemon”) that controls the GPIO pins. You can start this daemon manually with the command:

sudo pigpiod -t 0

Warning: if you have an I2S audio card attached, do not run pigpiod without the -t 0 option. Without that, a conflict in GPIO pin use will interfere with the I2S interface. The best case is that this will cause distorted sound and odd effects such as pitch change. The worst case is that it will apply 5V DC to your speaker and damage it. (I destroyed two speakers before finding the cause.)

You can then check that pigpio can be used by the gpiozero library with the following command:

python -c "import gpiozero; gpiozero.Device.pin_factory=gpiozero.pins.pigpio.PiGPIOFactory()"

This should not produce any output. If it is unable to communicate with the daemon, you will get output similar to the following:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import gpiozero; gpiozero.Device.pin_factory=gpiozero.pins.pigpio.PiGPIOFactory()
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pigpio.py", line 93, in __init__
    raise IOError(f'failed to connect to {host}:{port}')
OSError: failed to connect to localhost:8888

In this case, check that pigpiod is running then try again.

Create the pigpio service

You can create a “service” to start the pigpiod daemon automatically when the system boots. To do this, create the file /etc/systemd/system/pigpiod.service with the following content:

[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

Where:

  • -t 0 is required when using I2S audio to avoid a GPIO pin conflict
  •  -l disables remote access to the daemon

If you have previously started the pigpio daemon, you should stop it first. For example with:

sudo kill $(pgrep pigpiod)

Then reload the service files and start the daemon:

sudo systemctl daemon-reload
sudo systemctl enable --now pigpiod

Building the Python wheel

It is not normally necessary, but you might want to build the pigpio wheel yourself, for eaxmple if you are testing changes to the code.

First, create a virtual environment to get access to pip:

python -m venv ~/.venv
source ~/.venv/bin/activate

Note: some of the directories and files created by the “install” step above, are owned by the root user and group. Before building the pigpio wheel, you need to change the ownership of these. You can find the correct user and group name with the ls command, then use chown with the -R (recursive) option:

ls -lrt
...
-rwxrwxr-x 1 jamie jamie  73272 Feb 18 23:31 pigs
drwxr-xr-x 4 root  root    4096 Feb 18 23:31 build
drwxr-xr-x 2 root  root    4096 Feb 18 23:31 dist
drwxr-xr-x 2 root  root    4096 Feb 18 23:36 pigpio.egg-info

sudo chown -R jamie:jamie .

You can now build the pigpio wheel:

pip build .

And finally, install pigpio and any other packages you need:

pip install ./pigpio-1.78-py3-none-any.whl

Updated 2026-02-19 with information about building the wheel file.

Leave a Reply

Your email address will not be published. Required fields are marked *