So here it goes. I've been trying for the last few days to figure out how to properly use exceptions, specifically the ValueError. I've researched it over and over again, but am still struggling to put into practice.
This is a quick Python code I wrote where I tried to use it.
#!/etc/python from PIL import Image from time import sleep from subprocess import call import time import os import PIL import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) pad0 = 23 GPIO.setup(pad0, GPIO.IN) pad0alreadyPressed = False while True: pad0pressed = not GPIO.input(pad0) if pad0pressed and not pad0alreadyPressed: print "Pad 0 pressed" try: call(["gphoto2", "--auto-detect"]) call(["gphoto2", "--capture-image-and-download","--filename","/home/pi/booth/test1.jpg"]) except ValueError: print("focus error. Trying again") time.sleep(5) call(["gphoto2", "--auto-detect"]) call(["gphoto2", "--capture-image-and-download","--filename","/home/pi/booth/test1.jpg"]) pad0alreadyPressed = pad0pressed
The idea was to put the adafruit code for their 5 pad cap sensor together with gphoto2 to be able to take a photo with touch sensor. Unfortunately the camera has difficult time focusing and taking a photo when things are too close. It gives an error saying that it can't focus.
Pad 0 pressed Model Port ---------------------------------------------------------- Nikon DSC D300s (PTP mode) usb:001,006 /home/pi/booth/images/capture/Capture-160726160447.jpg *** Error *** Out of Focus ERROR: Could not capture image. ERROR: Could not capture.
I was attempting to put an except catching the error, and retrying to take a photo after 5 seconds allowing for focus to try again, but I still get the same outcome. Can somebody help me understand what I'm doing wrong, and what is the correct way to do this. Or am I using the ValueError incorrectly? Again, all I want is to be able to trigger my shutter with a cap sensor and to avoid getting stuck on the focus error by attempting to retake it.
All help would be greatly appreciated.
Thanks in advance.