R-PI sleep
From emboxit
Copy shutdowncheck.py script to /home/pi/bin/button/
#!/usr/bin/python import RPi.GPIO as GPIO import os, time GPIO.setmode(GPIO.BCM) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.OUT) GPIO.output(25, GPIO.HIGH) print ("[Info] Telling Sleepy Pi we are running pin 25") while True: if (GPIO.input(24)): print ("Sleepy Pi requesting shutdown on pin 24") os.system("sudo shutdown -h now") break time.sleep(0.5)
Run the script at startup
To run this script at startup, we must edit the
/etc/rc.local
In LXTerminal:
$ sudo leafpad /etc/rc.local
and insert the following line just before the final exit 0 and save changes:
python /home/pi/bin/button/shutdowncheck.py &
DONT forget the “&” which allows the script to run in the background!
Set permissions
On a fresh PI install you will need to set the permissions on
/etc/rc/local
so that it can execute at startup.
To do this execute the following command from a terminal window:
sudo chmod u+x /etc/rc.local