Shutdown Button
-
Hi Guys,
I installed this a shutdown script on my Pi 3b with latest retropie, and I then tried to amend the script that it uses, to make it require 3 seconds hold on the button to shut the computer down and immediate press, do nothing.
It seemed that if I changed the script more than 'shutdown -h' to shutdown -r' then the changes would not work.
I tried adding an IF statement earlier in the script that wouldn't really do anything, and then the whole script stopped working.
Does anyone know why this script seems to become inactive when edited? Or a way to edit it so that the button is required to be held for 3 seconds before the Pi shuts down.
Thansk for any help,
matalog
-
pie. 8bitjunkie. net/ retropie-shutdown-and- startup-switch-the-easy-way (remove spaces to see link)
This is the script - I want to link to the web page with the install instructions, but it won't let me post a link.
“#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocessGPIO.setmode(GPIO.BOARD)
we 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)
use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN)
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: # shutdown subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.5)”
-
Any ideas that may help with this?
Thanks again,
matalog
-
-
As I was saying I was trying to amend a script to require a 3 second hold of a button instead of shutting down upon immediate press, but every time I changed the script then it seemed to not run at all.
This works fine, and it even works if i add a comment or if I change
shutdown -h
toshutdown -r
This will shut down when I hold pin 5 to GND.#!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) # we 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) # use the same pin that is used for the reset button (one button to rule them all!) GPIO.setup(5, GPIO.IN) 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: # shutdown subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.5)
If I change any more than that, it will not work, for example, I made this to test if a changed method would work,
This does nothing when i hold pin 5 to GND.#!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) # we 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) # use the same pin that is used for the reset button (one button to rule them all!) GPIO.setup(5, GPIO.IN) oldButtonState1 = True if oldButtonState1 == 2: oldButtonState1 == 3 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: # shutdown subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.5)
That does not work.
Any ideas on why changing the installed script too much, would stop it from running?
matalog.
-
@matalog I'm not very firm in python.
But take a look to this link
https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetup.shand to this link
https://lowpowerlab.com/guide/atxraspi/assembly-install/shows how to use a timer to differ button event between shutdown and reboot in accordance of button press time. I think that is your demand....
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.