title: Raspberry Pi Error with picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
body: <p>When running a program on the Raspberry Pi Zero W, which involved the RPi Camera, I encountered an issue. This was based on the Joy Detector Demo, from the AIY Kit. Normally, it would change LED colours and make noised based on camera facial input (emotions), but I also added a part which would stream the extent of joy to ThingSpeak.</p>
  <p>The expected output was for the program to run, using the camera , instead the following message appeared:</p>
  <pre><code>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))0xdd2800 (ENOSPC)
  mmal: mmal_connection_enable: output port couldn't be enabled
  ERROR:__main__:Exception while running joy demo.
  Traceback (most recent call last):
    File &quot;/home/pi/AIY-projects-python/src/examples/vision/joy/joy_detection_demo.py&quot;, line 383, in main
      args.enable_streaming, args.streaming_bitrate, args.mdns_name)
    File &quot;/home/pi/AIY-projects-python/src/examples/vision/joy/joy_detection_demo.py&quot;, line 307, in joy_detector
      camera = stack.enter_context(PiCamera(sensor_mode=4, resolution=(820, 616)))
    File &quot;/usr/lib/python3/dist-packages/picamera/camera.py&quot;, line 433, in __init__
      self._init_preview()
    File &quot;/usr/lib/python3/dist-packages/picamera/camera.py&quot;, line 513, in _init_preview
      self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
    File &quot;/usr/lib/python3/dist-packages/picamera/renderers.py&quot;, line 558, in __init__
      self.renderer.inputs[0].connect(source).enable()
    File &quot;/usr/lib/python3/dist-packages/picamera/mmalobj.py&quot;, line 2212, in enable
      prefix=&quot;Failed to enable connection&quot;)
    File &quot;/usr/lib/python3/dist-packages/picamera/exc.py&quot;, line 184, in mmal_check
      raise PiCameraMMALError(status, prefix)
  picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources 
  </code></pre>
  <p>Please let me know if I need to add the code from these python files, but my best bet is it is too intensive. Using python 3.7.</p>