>using a switch to poweron / poweroff the RPI-you need a switch (power or reset button from a old pc)
-connect the two sockets of switch to PIN 5 (GPIO3) and PIN 6 (GROUND):
-create a script called 'shutdown_button.py'
(
Thanks to Alex)
#! /usr/bin/env python
import os
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)
try:
while True:
# wait for the pin to be sorted with GND and, if so, halt the system
GPIO.wait_for_edge(3, GPIO.FALLING)
# shut down the rpi
os.system("/sbin/shutdown -h now")
except:
GPIO.cleanup()
-put it on your RPI ( i've created a own folder : /home/pi/RetroPie/myscripts )
-edit file : /etc/crontab
-set this line at the end, depending to your folder and path
@reboot root /usr/bin/python /home/pi/RetroPie/myscripts/shutdown_button.py
-reset your RPI
if RPI is on and you press the button, the RPI shutdow.
If the RPI is already off, RPI turns on again.