I am trying to run this program at boot up. Its file path is /home/pi/shutdown.py. The reason why I ask is because I have tried to use multiple different boot up sequences listed in the following website Execute script on start-up

Is there any way to get this script to run in the background at boot (I have to run other scripts as well)?

import RPi.GPIO as GPIO
import time
import os

#setting the giop pins up note how this is pin 23 on the pi
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)                                                                       
#the pin is pulled down and will wait for a raiceing edge

def printFunction(channel):
    print("power button was pushed will shut down now")
    os.system("sudo shutdown -h now")

GPIO.add_event_detect(23, GPIO.RISING, callback=printFunction, bouncetime=300)
| improve this question | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.