I've made a bit of progress. The code below takes still pictures effectively and then prints a bit of code so we know it worked without having to check the image.
Code: Select all
from picamera import PiCamera
from time import sleep
import random
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
x = random.randint(1,1867834)
print("this is just a test",x)
This code works most of the time. For example, I ran it ten or fifteen times in a row without incident. Then something goes awry. Here's the output:
Code: Select all
>>> %Run hiyas.py
mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x9c55f0 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
PROBLEM WITH THONNY'S BACK-END:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1164, in _execute_prepared_user_code
exec(statements, global_vars)
File "/home/pi/Desktop/hiyas.py", line 5, in <module>
camera = 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
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1141, in execute_source
return self._prepare_hooks_and_execute(bytecode, None, global_vars)
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1156, in _prepare_hooks_and_execute
return self._execute_prepared_user_code(statements, expression, global_vars)
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1173, in _execute_prepared_user_code
return {"user_exception": self._vm._prepare_user_exception()}
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1029, in _prepare_user_exception
"stack": self._export_stack(last_frame),
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 932, in _export_stack
locals=self.export_variables(system_frame.f_locals),
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 886, in export_variables
result[name] = self.export_value(variables[name], 100)
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 876, in export_value
rep = repr(value)
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1323, in __repr__
self.name, mmal.FOURCC_str(self.format),
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 823, in name
result = self._port[0].name.decode('ascii')
ValueError: NULL pointer access
>>> %Run hiyas.py
this is just a test 593661
If I run it again, everything is fine (as seen above). Can anyone help with this?