raise PicameraMMALError (status, prefix)
picamera.exc.picameraMMALError: camera component couldn't be enabled : out of resorrces( other than memory)
im only using the "if distance<2" to stop the preview since i didnt find any other way. when i do the ctrl+c, it only stop the program and camera preview is still there.if there is another way to stop it please let me know. please help me to fix the code.Thank you.
Code: Select all
import time
import RPi.GPIO as GPIO
import os
import picamera
GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 23
GPIO_ECHO = 24
print "Ultrasonic Measurement"
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
GPIO.output(GPIO_TRIGGER, False)
time.sleep(0.5)
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
elapsed = stop-start
distance = elapsed * 34000
distance = distance / 2
return distance
camera = picamera.PiCamera()
camera.start_preview()
while True:
time.sleep(0.3)
print distance
if (distance < 2):
camera.stop_preview()
if (distance < 5):
os.system (' omxplayer -o local stop.mp3')
if (distance < 10):
os.system (' omxplayer -o local safe.mp3')