I am running the following program when I boot up my Pi:
#This program will scan a bar code and if it matches a good bar code will flash a light
#green or red depending on the validity of the coupon.
import sys, select, os
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
greenLED = 16
redLED = 12
GPIO.setup(greenLED, GPIO.OUT)
GPIO.setup(redLED, GPIO.OUT)
GPIO.output(greenLED, GPIO.LOW)
GPIO.output(redLED, GPIO.LOW)
goodBarCode = "0827112134023"
try:
#Flash LED to test if script is running at RPi boot
GPIO.output(greenLED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(greenLED, GPIO.LOW)
time.sleep(0.5)
while(1):
print ("Program is running")
userBarCode = input("")
if userBarCode == goodBarCode:
GPIO.output(greenLED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(greenLED, GPIO.LOW)
time.sleep(0.5)
else:
GPIO.output(redLED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(redLED, GPIO.LOW)
time.sleep(0.5)
except:
GPIO.cleanup()
The objective I am trying to achieve is to turn on the Pi and have this script running and ready to scan barcodes without ever interacting with the Pi. I have successfully added the program to /etc/rc.local and the program begins on boot up. The issue I am having is that it seems to just immediately close the program after printing "Program is running" instead of waiting for an input, any advice would be great.
I think you just need a
instead of
input()
. See official docs, what you do is just likeeval(raw_input(""))
. Also, any other details to help you solve? Does it just quit silently?