Use systemd to configure commands to run when a GPIO button is pressed on a Raspberry Pi
Project description
systemd-gpio
Use systemd to configure commands to run when a GPIO button is pressed on a Raspberry Pi.
This project is inspired by https://github.com/ali1234/systemd-gpio. The main difference is that we are using gpiozero rather than WiringPi, because WiringPi is no longer maintained.
Usage
To configure a GPIO pin, create a file called /etc/gpio/N
, where N
is an integer pin number following gpiozero's convention. For example, to configure actions for pin GPIO23, create the file /etc/gpio/23
.
The file should use the systemd EnvironmentFile syntax. All variables are optional.
The values for GPIO_PULL_UP
, GPIO_ACTIVE_STATE
, GPIO_BOUNCE_TIME
, GPIO_HOLD_TIME
, and GPIO_HOLD_REPEAT
are passed to the Python gpiozero.Button
class.
The values of GPIO_WHEN_HELD
, GPIO_WHEN_PRESSED
, and GPIO_WHEN_RELEASED
control the commands to be executed when the button is held, pressed, or released, respectively. See the corresponding methods gpiozero.Button.when_held
, gpiozero.Button.when_pressed
, and gpiozero.Button.when_released
, respectively.
Once you have populated the configuration file, activate the button by running the following command, replacing N
with the pin number:
sudo systemctl enable --now gpio@N.service
Examples
# /etc/gpio/23
GPIO_HOLD_TIME=5
GPIO_WHEN_PRESSED="wall 'Hold the power button for 5 seconds to power off.'"
GPIO_WHEN_HELD=poweroff
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for systemd_gpio-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0da80813d044961c620f4ce87235491f39b2368791218881df55b2e57d1fb9 |
|
MD5 | 71cd2a1b1d4208ad13f5c4736c19952f |
|
BLAKE2b-256 | 6038e378e39d926a18f749bf5492f4a4ae25d0777376c20dd701e8944d268083 |