I have a program that turns my pi on and off at a push of a button. The program works and i know that it runs on boot because it prints text and I can see it in the terminal. But what happens is when i press the button, nothing happens. I have tried 2 different ways of auto running the program.
import RPi.GPIO as GPIO import time import os GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP) def shutdown(channel): os.system("sudo shutdown -h now") GPIO.add_event_detect(3, GPIO.FALLING, callback = shutdown, bouncetime = 2000)
and i have tried to auto run it by putting "python powerbutton.py" at the bottom of the file /etc/rc.local and .bashrc