Thank you for all your help, my problem is not fixed yet.
When I open a terminal, and input the command line "sudo python cron.py", it video window show up when button is pressed.
While if I set a reboot and want it start automatically, after press the button, LED is on, which means the script is running. but there is no video show up. If I press button again, the Raspberry Pi is shut down.
Here is my cron.py script. Please help me figure out what the problem is. Thanks
Code: Select all
#!/usr/bin/python
import os
import subprocess
# Import required libraries
import RPi.GPIO as GPIO
import time
# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)
# List of LED GPIO numbers
LedSeq = [4,17,22,10,9,11]
print "Setup GPIO pins as inputs and outputs"
# Set Switch GPIO as input
#GPIO.setup(7 , GPIO.IN)
GPIO.setup(7 , GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# Set up the GPIO pins as outputs and set False
print "Setup LED pins as outputs"
for x in range(6):
GPIO.setup(LedSeq[x], GPIO.OUT)
GPIO.output(LedSeq[x], False)
# set up variables
ButtonCounter = 0
print "Press the button"
# Wrap main content in a try block so we can
# catch the user pressing CTRL-C and run the
# GPIO cleanup function. This will also prevent
# the user seeing lots of unnecessary error
# messages.
try:
# Loop until users quits with CTRL-C
while True :
if GPIO.input(7)==1:
ButtonCounter += 1
print " Button pressed!"
time.sleep(0.5)
print "Press the button (CTRL-C to exit)"
# light green LED
GPIO.output(LedSeq[4], True)
GPIO.output(LedSeq[5], True)
print "before FaceReco"
# face recognition program start to run
subprocess.Popen("/home/pi/rpispy_vcu/camcv2 /home/pi/rpispy_vcu/faces.csv 1 5000", shell=True)
print "after FaceReco"
# press button twice, turn off program
if ButtonCounter>2:
print "turn off green LED and stop face recognition"
GPIO.output(LedSeq[4], False)
GPIO.output(LedSeq[5], False)
time.sleep(1.0)
os.system("sudo shutdown -h now")
#raise KeyboardInterrupt
except KeyboardInterrupt:
# Reset GPIO settings
GPIO.cleanup()