No description
Find a file
Paint Your Dragon 9671c327d2
Merge pull request #1 from jpcarrascal/master
Added a 2nd argument (button pressed time before shutdown) and changed executable destination and owner.
2021-10-13 08:25:25 -07:00
gpio-halt.c Added a 2nd argument: ms to wait before halting 2021-10-12 12:25:33 +02:00
LICENSE Initial commit 2014-08-02 09:52:22 -07:00
Makefile Executable moved to /usr/local/sbin, owner=root 2021-10-12 12:32:06 +02:00
README.md Update README.md 2021-10-12 13:04:12 +02:00

Adafruit-GPIO-Halt

Press-to-halt program for headless Raspberry Pi. Similar functionality to the rpi_power_switch kernel module from the fbtft project, but easier to compile (no kernel headers needed).

Modifications

  • Added a second argument, the time (in milliseconds) that the button should be kept pressed for halt to start. First argument, which was present in the original, is the GPIO pin (21 by default).
  • Make install will copy the executable to /usr/local/sbin (instead of /usr/local/bin) and set root as the owner. This makes more sense as power handling commands are usually owned by root and located in sbin directories.

Install as a service

(Based on this blog post: https://www.recantha.co.uk/blog/?p=13999)

Create and open service file:

sudo vi /etc/systemd/system/gpio-halt.service

Add this content to the file:

[Unit]
Description=GPIO shutdown (pin 21 to ground)
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/local/sbin/gpio-halt 21 3000

[Install]
WantedBy=multi-user.target

Start the script:

sudo systemctl daemon-reload
sudo systemctl start gpio-halt.service

Make the service run every time the system boots:

sudo systemctl enable gpio-halt.service

If you want to check the status of the service:

sudo systemctl status gpio-halt.service