Safe Shutdown Script
-
I am having an issue with the shutdown script of a newly installed on/off button on my pi 4 on pins 5 and 6. The startup works fine, but the shutdown isn't working. Here are the contents of
/home/pi/scripts/shutdown.py
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocesswe will use the pin numbering to match the pins on the Pi, instead of the
GPIO pin outs (makes it easier to keep track of things)
GPIO.setmode(GPIO.BOARD)
use the same pin that is used for the reset button (one button to rule them a$
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
oldButtonState1 = True
while True:
#grab the current button state
buttonState1 = GPIO.input(5)check to see if button has been pushed
if buttonState1 != oldButtonState1 and buttonState1 == False: subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.1)
Anything look weird?
-
I ended up using @cyperghost 's script from [https://retropie.org.uk/forum/topic/17415/multi-switch-shutdown-script?_=1609290226722](link url)
and now have things working.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.