I have set up a on my bread board a button and trying to take images when I press it. I also have a led that turns on while pressing the button. All works fine, however, when I run the python script, it does not wait for me to press the button and automatically takes the image with an error
Here are images of my board and Pi.
Below is my code and the error
import picamera
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
sleepTime = 0.1
#GPIO pin components
lightPin = 4
buttonPin = 17
GPIO.setup(lightPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(lightPin, False)
try:
while True:
GPIO.output(lightPin, not GPIO.input(buttonPin))
camera = picamera.PiCamera()
camera.capture('image.jpg')
sleep(sleepTime)
finally:
GPIO.output(lightPin, False)
GPIO.cleanup()
The error
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "copyright", "credits" or "license()" for more information.
>>>
================= RESTART: /home/pi/Desktop/doorbelPhoto.py =================
Traceback (most recent call last):
File "/home/pi/Desktop/doorbelPhoto.py", line 25, in <module>
camera = picamera.PiCamera()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 433, in __init__
self._init_preview()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 513, in _init_preview
self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
File "/usr/lib/python3/dist-packages/picamera/renderers.py", line 558, in __init__
self.renderer.inputs[0].connect(source).enable()
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2212, in enable
prefix="Failed to enable connection")
File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
>>>