Giter Site home page Giter Site logo

systemd-gpio-monitor's Introduction

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.

systemd-gpio-monitor's People

Contributors

jemgoss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

vesek

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.