#!/usr/bin/python # Connect a simple power button to pin 5 (GPIO 3) and pin 6 (GND). # By pressing this button, the Raspberry Pi will wake up from # halt state and boot. # This script is used to shut down the Raspberry Pi by using the same button. # https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi __author__ = "Gernot Walzl" __date__ = "2017-12-18" import subprocess from RPi import GPIO if __name__ == '__main__': GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN) GPIO.wait_for_edge(3, GPIO.FALLING) subprocess.call(['shutdown', '-h', 'now'])