Skip to content

How to use shutdown.py

Claude Pageau edited this page Apr 4, 2021 · 5 revisions

How to Use shutdown.py

Purpose

Safely shutdown (halt) Raspberry pi using a normally open momentary switch

Hardware Requirements

Requires one small normally open momentary push button switch and two short insulated wires.

Instructions

Mount switch and Connect each wire per below.

  • Connect control wire from one switch terminal to RPI GPIO control pin 5 (default)
  • Connect ground wire from second switch terminal to RPI GPIO ground pin 6 (default)
    or set gpio_pin variable by editing shutdown.py and setting gpio_pin = variable to desired control pin, then connect control wire as appropriate

Note: If desired set button_hold_sec variable by editing shutdown.py and changing button_hold_sec = variable to desired number of seconds required to hold down momentary switch before RPI halt action is taken.
default is 2 seconds. 0=No delay

Software Install

cd ~
mkdir shutdown
cd shutdown
wget https://raw.github.com/pageauc/pi-timolo/master/source/shutdown.py
chmod +x shutdown.py
sudo crontab -e

Add line below to sudo crontab -e (without #) Ctrl-x y to exit nano and save change

@reboot /home/pi/shutdown/shutdown.py

Operating Instructions

After initial power boot press momentary switch for specfied time to Initiate safe shutown (halt). You can then safely power off RPI
or After halt, wait approx 5 seconds then press switch again for specified time to intiate a restart or RPI

Clone this wiki locally