2

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')

closed as unclear what you're asking by techraf, Milliways, joan, Jacobm001 Jan 2 '18 at 3:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Could you explain what you're wanting to happen, please? Are you expecting to hit ctrl+c in the desktop (or whatever) and have it magically end up at your program? Or something else? I wonder whether this is an XY problem – Mark Smith Dec 25 '17 at 15:22
  • Also, if you want to know whether the problem is related to the camera preview, you don't need to post here - you can just take free preview out and test it. Now the you know it's not, you can remove that part of your question. – Mark Smith Dec 25 '17 at 15:28
  • @MarkSmith I made changes to the question and removed the camera preview part since it does not stop the interrupt from working when using the terminal. – Nick Solonko Dec 26 '17 at 19:49

Browse other questions tagged or ask your own question.