[Moderated] (split from 2012 thread and locked that one for being obsolete) because in 2019 we may need a new solution.piglet wrote: ↑Fri Sep 28, 2012 9:53 amI assume there must be some way to have:
1) a push-button linked to +5v pin and a gpio pin (and a maybe pull-down resistor on the gpio to ground *says he hoping that people don't laugh at how little he knows*)
2) a background task/interrupt to then initiate "sudo shutdown now" when that pin goes to +5v
How to do 1, and 2 and have 2 running all the time is beyond me. Is anyone willing to help?
Any idea why this solution is not working with latest Raspberry pi 4. Earlier my pi can be reboot from the same button if I press again after an orderly shutdown.
Here is my script:
Code: Select all
import subprocess import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # GPIO3 (pin 5) set up as input. It is pulled up to stop false signals GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) # wait for the pin to be sorted with GND and, if so, halt the system GPIO.wait_for_edge(3, GPIO.FALLING) subprocess.call(['shutdown -h now "System halted by power switch "'], shell=True) # clean up GPIO on normal exit GPIO.cleanup()