thamaeng
Posts: 24
Joined: Fri Oct 10, 2014 12:48 pm

Pi camera error

Tue Nov 25, 2014 8:27 pm

I am using camera preview in my program. i am using a condition to stop the preview. after stopping the preview, the red light in the camera remains on. it will not off unless i switch off the Raspberry pi. If i try to run the program again with the red light on in camera, its giving me a error somthing like this.
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')

Return to “Camera board”