adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.13k stars 1.22k forks source link

esp32-cam failing to init camera #9356

Open aguaviva opened 5 months ago

aguaviva commented 5 months ago

CircuitPython version

CircuitPython 9.1.0-beta.3 (https://circuitpython.org/board/ai-thinker-esp32-cam/)

Code/REPL

import espcamera
import board

cam = espcamera.Camera(
    data_pins=board.CAMERA_DATA,
    external_clock_pin=board.CAMERA_XCLK,
    pixel_clock_pin=board.CAMERA_PCLK,
    vsync_pin=board.CAMERA_VSYNC,
    href_pin=board.CAMERA_HREF,
    pixel_format=espcamera.PixelFormat.JPEG,
    frame_size=espcamera.FrameSize.SVGA,
    i2c=board.I2C(),
    external_clock_frequency=20_000_000,
    grab_mode=espcamera.GrabMode.WHEN_EMPTY)

f = cam.take()

print(len(f))

Behavior

Traceback (most recent call last):
  File "<stdin>", line 14, in <module>
espidf.IDFError: Requested resource not found

Description

I am trying to take a picture but fails

Additional information

aguaviva commented 5 months ago

it turns out it was documented in the PR (https://github.com/adafruit/circuitpython/pull/9231), I'd be nice if this could make it in the official documentation and have a unit test for this board.

aguaviva commented 5 months ago

This works like a charm:

import socketpool
import wifi
from adafruit_httpserver import Server, Request, Response

import board
import espcamera

cam = espcamera.Camera(
    data_pins=board.CAMERA_DATA,
    external_clock_pin=board.CAMERA_XCLK,
    pixel_clock_pin=board.CAMERA_PCLK,
    vsync_pin=board.CAMERA_VSYNC,
    href_pin=board.CAMERA_HREF,
    powerdown_pin=board.CAMERA_PWDN,
    reset_pin=None,
    i2c=board.I2C(),
    external_clock_frequency=20_000_000,
    pixel_format=espcamera.PixelFormat.JPEG,
    frame_size=espcamera.FrameSize.SVGA,
    # jpeg_quality=0,
    # framebuffer_count=0,
    # grab_mode=espcamera.GrabMode.WHEN_EMPTYi
    )

from adafruit_httpserver import Server, Request, ChunkedResponse

pool = socketpool.SocketPool(wifi.radio)
server = Server(pool, debug=True)

@server.route("/pic")
def chunked(request: Request):
    frame = cam.take(1)
    return Response(request, content_type="image/jpeg", body=frame)

server.serve_forever(str(wifi.radio.ipv4_address))

Now trying to get multipart working...

aguaviva commented 5 months ago

Update: the HTTPServer is getting updated to support streaming, see: https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer/issues/95