I wrote a small script to shutdown the pi once the button is pressed for 2 seconds. It should print a message and after one second shutdown the pi. I also have this script to run automatically on each boot (init.d). The problem is that the first time I run the script, when i press the button it works as it should. But after I turn on the pi again (and the script starts automatically on boot) the button is still turning off my pi but no message is printed.
here is my script:
#!/usr/bin/env python import RPi.GPIO as GPIO import time import subprocess def Shutdown(): print("message") time.sleep(1) subprocess.call(['shutdown', '-h', 'now'], shell=False) GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: GPIO.wait_for_edge(3, GPIO.FALLING) #sleep and check button state again (in case of accidental button press) time.sleep(2) if GPIO.input(3) == 0: break Shutdown()
I tried it both on a pi zero and a 3b.
Do you have any idea why this would happen? Thnks for you time.