|
| 1 | +SYSTEMD-GPIO(5) |
| 2 | +=============== |
| 3 | + |
| 4 | +NAME |
| 5 | +---- |
| 6 | +systemd-gpio - run commands when a button on a GPIO pin is pressed |
| 7 | + |
| 8 | +DESCRIPTION |
| 9 | +----------- |
| 10 | + |
| 11 | +Use systemd to configure commands to run when a button attached to a GPIO pin is pressed, released, or held. |
| 12 | + |
| 13 | +To configure a GPIO pin, create a file called /etc/gpio/*N*, where *N* is an integer pin number following the `gpiozero pin numbering`_ convention. Once you have populated the configuration file, activate the button by running the following command, replacing *N* with the pin number:: |
| 14 | + |
| 15 | + sudo systemctl enable --now [email protected] |
| 16 | + |
| 17 | +ENVIRONMENT |
| 18 | +----------- |
| 19 | + |
| 20 | +| GPIO_PULL_UP |
| 21 | +| GPIO_ACTIVE_STATE |
| 22 | +| GPIO_BOUNCE_TIME |
| 23 | +| GPIO_HOLD_TIME |
| 24 | +| GPIO_HOLD_REPEAT |
| 25 | +
|
| 26 | + Button behavior. See the documentation for the corresponding constructor arguments of `gpiozero.Button`_. |
| 27 | + |
| 28 | +| GPIO_WHEN_HELD |
| 29 | +| GPIO_WHEN_PRESSED |
| 30 | +| GPIO_WHEN_RELEASED |
| 31 | +
|
| 32 | + Commands to run when the button is held, pressed, or released, respectively. See the documentation for the corresponding properties of `gpiozero.Button`_. |
| 33 | + |
| 34 | +FILES |
| 35 | +----- |
| 36 | + |
| 37 | +/etc/gpio/*N* |
| 38 | + |
| 39 | + Configuration file for GPIO pin *N*, where *N* corresponds to the `gpiozero pin numbering`_. The file should be in the `systemd EnvironmentFile syntax`_ and may define any of the environment variables listed above. |
| 40 | + |
| 41 | +HISTORY |
| 42 | +------- |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +EXAMPLES |
| 47 | +-------- |
| 48 | + |
| 49 | +The following example configures GPIO 23 so that when it is pressed, it prints a message to all TTYs, and when held, shuts down the machine:: |
| 50 | + |
| 51 | + # /etc/gpio/23 |
| 52 | + GPIO_HOLD_TIME=5 |
| 53 | + GPIO_WHEN_PRESSED="wall 'Hold the power button for 5 seconds to power off.'" |
| 54 | + GPIO_WHEN_HELD=poweroff |
| 55 | + |
| 56 | +To activate the pin, run the following command:: |
| 57 | + |
| 58 | + sudo systemctl enable --now [email protected] |
| 59 | + |
| 60 | +.. _gpiozero: https://github.com/gpiozero/gpiozero |
| 61 | +.. _WiringPi: https://web.archive.org/web/20220405225008/http://wiringpi.com/wiringpi-deprecated/ |
| 62 | +.. _`gpiozero.Button`: https://gpiozero.readthedocs.io/en/latest/api_input.html#gpiozero.Button |
| 63 | +.. _`gpiozero pin numbering`: https://gpiozero.readthedocs.io/en/latest/recipes.html#pin-numbering |
| 64 | +.. _`systemd EnvironmentFile syntax`: https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#EnvironmentFile= |
| 65 | + |
| 66 | +SEE ALSO |
| 67 | +-------- |
| 68 | + |
| 69 | +systemctl(1), systemd.exec(5) |
0 commit comments