I updated the Raspberry Pi On/Off circuit to include a signal to the Raspberry Pi so it detects when the Pi is turned off.
I'm also thinking now of not having a momentary switch for the power switch.
Here's the new circuit. Again, detailed component values have not been selected. The 10 ohm resistor symolises the Pi's load. I'll attach the iCircuit file to the Hackaday project.:
Here's the script (/home/pi/shutdownMonitor.py) that turns off the Pi when it detects that the power switch has been turned off:
# Import the modules to send commands to the system and access GPIO pins from subprocess import call import RPi.GPIO as gpio import time import os # Define a function to keep script running def loop(): time.sleep(60) # Define a function to run when an interrupt is called def shutdown(pin): print "shutting down..." os.system( "sudo shutdown -h now" ) # call('halt', shell=False) gpio.setmode(gpio.BCM) # Set pin numbering to board numbering gpio.setup(23, gpio.IN ) # , pull_up_down=gpio.PUD_TRI) # Set up pin 7 as an input # gpio.add_event_detect(23, gpio.RISING, callback=shutdown, bouncetime=200) # Set up an interrupt to look for button presses gpio.add_event_detect(23, gpio.FALLING, callback=shutdown, bouncetime=200) # Set up an interrupt to look for button presses loop() # Run the loop function to keep script runningIt is started from /etc/rc.local like this:
python /home/pi/shutdownMonitor.py &