cwgosling
Posts: 2
Joined: Mon Dec 03, 2018 6:11 pm

PiCamera preview randomly appears

Mon Dec 03, 2018 8:08 pm

I'm new to Raspberry Pi and am having an issue with the Raspberry Pi Camera hooked up to a Raspberry Pi 3 B+. It works fine in that it takes still pictures and video, but it randomly goes into preview mode even when a program isn't using the camera. This fills the screen and makes it impossible to work while the preview is up-, which is usually 5-15 seconds. Advice on how to get this to go away? I'm hoping it's a setting somewhere rather than a wonky component. I'm a teacher and it's getting tough to work when the device keeps flaking out during class.

(side note: I tried to search the forums to see if anyone else has had the same problem, but the search function has been out of order "because of high traffic" for the past few hours. So I apologize if this is a duplicate thread. If so, I'd appreciate it if someone could point me to the original and call it good.

cwgosling
Posts: 2
Joined: Mon Dec 03, 2018 6:11 pm

Re: PiCamera preview randomly appears

Wed Dec 05, 2018 7:36 pm

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?

Return to “Camera board”