The code below runs on boot via this command in the /etc/rc.local file:
python3 /home/pi/Desktop/booth.py. When a button is pressed, the PiCamera preview begins, which covers my whole monitor screen so I cannot do anything. The Ctrl-C interrupt in the code is supposed to stop the program. The interrupt works when I run the booth.py file from the terminal, but not when it is run from the rc.local file. My goal is to have the program run automatically on boot from the rc.local file but maintain the ability to stop it with the keyboard interrupt.
Here is my code:
from time import sleep #lets us set delays in our code import os #allow us to do command line commands import RPi.GPIO as GPIO #RaspberryPi IO pins import picamera #camera library GPIO.setmode(GPIO.BCM) # set the mode for pin numbering camera = picamera.PiCamera() #create camera object button = 4 #take photo button pin GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)#sets button as input try: while True:#loop input_state = GPIO.input(button)#get state of take photo button if input_state == False:#if button is pressed c = GPIO.wait_for_edge(button, GPIO_RISING, timeout=3000) if channel is None: break else: camera.start_preview()#begin preview (if RPi just turned on) camera.capture("photo.jpg")#take photo camera.stop_preview()#stop camera preview GPIO.cleanup()#cleanup pins os.system("sudo shutdown -h now")#shutdown except KeyboardInterrupt:#interrupt Ctrl-C print('stopped')