I have installed a jack button to turn on and off my raspberry pi 3 following the method described in the youtbue video The Borkin Button Easy Raspberry Pi Power Butto.
This allows to create a shutdown and boot up switch taking advantage of the 3.55mm av(audio video) jack.
Then the script below manage starting/shutting down the device.
#!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) # use the same pin that is used for the reset button (one button to rule them all!) GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP) oldButtonState1 = True while True: #grab the current button state buttonState1 = GPIO.input(5) # check to see if button has been pushed if buttonState1 != oldButtonState1 and buttonState1 == False: subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.1)
It does work fine when the raspi is connected to a screen. However when not connected to a screen the button doesn't work.
Anyone can shed some light on what the issue could be?