-
-
Notifications
You must be signed in to change notification settings - Fork 19
GPIO Access
Homebridge RPi doesn't access the GPIO hardware directly. Instead, it talks to a system service (a daemon) on the Raspberry Pi, which in turn interacts with the GPIO pins. This also has the advantage that Homebridge RPi doesn't need any special privileges.
The system service can be configured for remote access, so Homebridge RPi can control GPIO devices connected to a remote Raspberry Pi. In addition to accessing the GPIO hardware, the service provides (remote) access to files and scripts. Homebridge RPi uses these features to monitor remotely the Raspberry Pi hardware and OS. This also has the advantage that Homebridge RPi can run on any Homebridge supported system.
Unfortunately, there are two versions of this system service. While offering similar functions, they provide a different interface and support different hardware and software. In summary:
- For Homebridge RPi v2, you want to Install and Configure
lg, unless your Raspberry Pi is running Raspberry Pi OS v11 (bullseye) or earlier. - For Homebridge RPi v1, you need to Install and Configure
pigpio, without support for the Raspberry Pi 5 (and later) nor for Rapberry Pi OS v13 (trixie) or later.
Historically, the system service was provided by the pigpio library, bundled with Raspberry Pi OS before v13 (trixie).
However, this library doesn't support the Raspberry Pi 5 hardware.
pigpio has been succeeded by lg, which does support the Raspberry Pi 5 in addition to earlier models.
However, lg is bundled with Raspberry Pi OS only as of v12 (bookworm).
Homebridge RPi v1 works exclusively with pigpio.
Homebridge RPi v2 works with both lg and pigpio.
It uses the port to determine to which service to connect; when no port has been specified, it defaults to lg.
Note that pigpio allows shared access to GPIOs; i.e. different processes can access a GPIO in use by Homebridge RPi.
However, lg claims GPIOs exclusively, i.e. another process cannot claim a GPIO in use by Homebridge RPi.
Trying so results in a "-97 GPIO busy" error.
As a consequence, lg doesn't support reading nor event notifications on GPIOs claimed for output.
While it's technically possible to update an GPIO claimed for output by lg through pigpio, there is no way to see the changed state in lg.
Note that lg uses software timing for PWM and servo pulses, where pigpio uses hardware timing.
A note in the lg documentation warns about the use of software timed servo pulses:
I would only use software timed servo pulses for testing purposes. The timing jitter will cause the servo to fidget. This may cause it to overheat and wear out prematurely.
The following table compares lg versus pigpio.
| . | lg |
pigpio |
|---|---|---|
| Daemon | rgpiod |
pigpiod |
| Port | 8889 |
8888 |
| Command-line tool | rgs |
pigs |
| Raspberry Pi 5 (and later) |
yes | no |
| Raspberry Pi 4B (and earlier) |
yes | yes |
| Raspberry Pi OS v13 (trixie) (and later) |
yes | no |
| Raspberry Pi OS v12 (bookworm) | yes | yes |
| Raspberry Pi OS v11 (bullseye) (and earlier) |
no | yes |
| Homebridge RPi v2 | yes | yes |
| Homebridge RPi v1 | no | yes |
| Setup Instructions | Install and Configure rgpiod |
Install and Configure pigpiod |
| GPIO access | exclusive | shared |
| PWM timing | software | hardware |