pi Shutdown Switch


Ref: https://www.instructables.com/id/Raspberry-Pi-Zero-Switch-Off-by-Button/

# pi zero short pin 21 to ground (last two pins on gpio)
import RPi.GPIO as GPIO
import time import os
buttonPin = 21
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
last_state = True
input_state = True
while True:
input_state = GPIO.input(buttonPin)
if (not input_state): print("Shutdown")
os.system('sudo shutdown -h now')

Create the python file in /usr/bin
sudo nano /usr/bin/pistop.py
--Paste in python text above

Add to startup so it runs on bootup to monitor the pins
sudo nano /etc/rc.local
# Add prior to exit 0 in rc.local
python /usr/bin/pistop.py

short pins and see if it works.