Skip to content

Systemd-based monitoring of a GPIO pin (for Raspberry Pi)

License

Notifications You must be signed in to change notification settings

jemgoss/systemd-gpio-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

systemd-gpio-monitor

Systemd-based monitoring of a GPIO pin (for Raspberry Pi).

The basic idea here is to monitor an input pin at the end of the Pi's main GPIO header for a short to the GND pin next to it and initiate an orderly shutdown. This is useful to shut down a headless Raspberry Pi without having to log in through the serial interface or ssh: just touch a paper clip to the pins at the end of the GPIO header. NOT THE 3V3 / 5V END!!

I had originally done this with a small python script but wanted to achieve it with minimal resources. Hence using only systemd and no other shell or script-based polling of the pin's value.

It works by setting up an input pin with internal pullup, assigning a falling edge detection interrupt and monitoring the pin's value through sysfs using a systemd.path unit.

This can easily be adpated to perform other tasks when a GPIO pin change is detected.

Dependencies:

Since I couldn't find a way to set an internal pullup directly through sysfs, I've reverted to using gpio-admin, a program from quick2wire.

Usage:

  1. Copy all systemd unit files to /etc/systemd/system.

  2. Enable and start monitoring:

  • 40 pin header:
  # systemctl enable --now [email protected]
  • 26 pin header:
  # systemctl enable --now [email protected]

You may want to first test the action without actually shutting down:

  1. Edit [email protected] to echo the poweroff command.
  2. Monitor the activation service:
  • 40 pin header:
  # journalctl -f -u [email protected]
  • 26 pin header:
  # journalctl -f -u [email protected]

Improvements are certainly welcome.

About

Systemd-based monitoring of a GPIO pin (for Raspberry Pi)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published