#!/usr/bin/python # PiPower # Copyright 2017 (c) Mark van Renswoude # # Yet another power supply for the Raspberry Pi. # Designed to run on an ATTiny85 with a self-locking button. import RPi.GPIO as GPIO import time import os GPIO.setmode(GPIO.BCM) GPIO.setup(15, GPIO.OUT) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) hasShutdown = False def shutdownSignal(channel): print "PiPower: shutting down" os.system('shutdown -h now') hasShutdown = true GPIO.add_event_detect(18, GPIO.RISING, callback=shutdownSignal, bouncetime=300) GPIO.output(15, GPIO.HIGH) try: print "PiPower: waiting for signal" while not hasShutdown: time.sleep(1) print "PiPower: exiting" GPIO.cleanup() except KeyboardInterrupt: GPIO.cleanup()