I am able to create a shutdown (and reboot) button for a plain Raspi harnassing the fact, that shorting Pin 5 to GND will reboot the Pi if shutdown.
However, when adding the HifiBerry HAT things become more complicated, as Pin 5 is used for I2C and as stated by HiFiBerry, some other GPIO-Pins are used as well.
Now to my question: Will the following curcuit work with the Amp+ HAT?
In the shutdown script I would be monitoring Pin 13 for LOW state and send sudo shutdown -h now
.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""shutdown script for Raspberry Pi
watch LOW level on pin 13 to enter sleep mode
status led on pin 15: ON = ready, BLINK = confirm button
"""
import RPi.GPIO as GPIO
import os
import time
# use the pin number as on the raspi board
GPIO.setmode(GPIO.BOARD)
# set pin 15 as output and HIGH, pin 13 is input
GPIO.setup(15, GPIO.OUT)
GPIO.output(15, True)
GPIO.setup(13, GPIO.IN)
# start the loop for every .5 seconds, waiting for LOW on pin 13
# then 2 short flashes with led to confirm and shutdown to sleep mode
while True:
if not GPIO.input(13):
GPIO.output(15, False)
time.sleep(.1)
GPIO.output(15, True)
time.sleep(.1)
GPIO.output(15, False)
time.sleep(.1)
GPIO.output(15, True)
os.system("sudo shutdown -h now")
time.sleep(.5)
Will currents drawn from Pin 5 influence the function of the HAT in this setting?