Skip to content

espcamera ESPIDF Generic Failure and Memory Error on ESP32S2  #8942

Open
@jerryneedell

Description

@jerryneedell

CircuitPython version

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; Adafruit Feather ESP32S2 with ESP32S2

Code/REPL

import board
from digitalio import DigitalInOut
import time
import espcamera

cam = espcamera.Camera(
    data_pins=[board.D6,board.A5,board.D9,board.A4,board.D10,board.A3,board.D11,board.A2],
    external_clock_pin=board.D12,
    pixel_clock_pin=board.A1,
    vsync_pin=board.A0,
    href_pin=board.D13,
    pixel_format=espcamera.PixelFormat.RGB565,
    frame_size=espcamera.FrameSize.SVGA,
    i2c=board.I2C(),
    external_clock_frequency=20_000_000,
    grab_mode=espcamera.GrabMode.WHEN_EMPTY,
    powerdown_pin=board.D5,
    reset_pin=board.RX
)
print(cam.sensor_name)

Behavior

10.0.0.107 | REPL | 9.0.0-beta.0-52-g6c1e34e957reload.
Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; Adafruit Feather ESP32S2 with ESP32S2
>>> 
>>> 
>>> import code_test_rgb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "code_test_rgb.py", line 18, in <module>
espidf.IDFError: Generic Failure
10.0.0.107 | Done | 9.0.0-beta.0-52-g6c1e34e957soft reboot

Description

This is being run on a feather esp32s2 with an OV5460 breakout.

See the additional example below that fails with a Memory error when adafruit_requests is also used.
I suspect these failures are both due to memory issues on the esp32s2 so I am reporting both here.

Additional information

switching to PixelFormat = JPEG runs normally


import board
from digitalio import DigitalInOut
import time
import espcamera


cam = espcamera.Camera(
    data_pins=[board.D6,board.A5,board.D9,board.A4,board.D10,board.A3,board.D11,board.A2],
    external_clock_pin=board.D12,
    pixel_clock_pin=board.A1,
    vsync_pin=board.A0,
    href_pin=board.D13,
    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,
    powerdown_pin=board.D5,
    reset_pin=board.RX
)
print(cam.sensor_name)
10.0.0.107 | REPL | 9.0.0-beta.0-52-g6c1e34e957reload.
Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; Adafruit Feather ESP32S2 with ESP32S2
>>> import code_test_jpeg
OV5640

Both examples run as espected on an esp32s3 (memento or metro_esp32s3)

I suspect this is a memory issue and not really related to the Pixel Format.

If I extend the working code (JPEG format) to try to use the requests library to access AIO, then it fails with a Memory Error.

code:

# SPDX-FileCopyrightText: Copyright (c) 2022 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Upload a jpeg image to Adafruit IO at regular intervals

This example requires:
 * ESP32-S3-EYE development kit from Espressif

To use:
 * On io.adafruit.com, create a feed named "image" and turn OFF history
 * On io.adafruit.com, create a dashboard and add an "image" block
   using the feed "image" as its data
 * Set up CIRCUITPY/.env with WiFI and Adafruit IO credentials
 * Copy the project bundle to CIRCUITPY
"""

import binascii
import io
import busio
import os
import ssl
import time
import board
import espcamera
import socketpool
import wifi
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
from digitalio import DigitalInOut

aio_username = os.getenv('AIO_USERNAME')
aio_key = os.getenv('AIO_KEY')


cam = espcamera.Camera(
    data_pins=[board.D6,board.A5,board.D9,board.A4,board.D10,board.A3,board.D11,board.A2],
    external_clock_pin=board.D12,
    pixel_clock_pin=board.A1,
    vsync_pin=board.A0,
    href_pin=board.D13,
    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,
    powerdown_pin=board.D5,
    reset_pin=board.RX
)
print(cam.sensor_name)

cam.vflip = True
print("camera initialized")

pool = socketpool.SocketPool(wifi.radio)

requests = adafruit_requests.Session(pool, ssl.create_default_context())

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(os.getenv("AIO_USERNAME"), os.getenv("AIO_KEY"), requests)
# Adafruit IO feed configuration
try:
    # Get the 'camera' feed from Adafruit IO
    feed_camera = io.get_feed("featheresp32s2")
except AdafruitIO_RequestError:
    # If no 'camera' feed exists, create one
    feed_camera = io.create_new_feed("featheresp32s2")

while True:
    frame = cam.take(1)
    if isinstance(frame, memoryview):
        jpeg = frame
        print(f"Captured {len(jpeg)} bytes of jpeg data")

        # b2a_base64() appends a trailing newline, which IO does not like
        encoded_data = binascii.b2a_base64(jpeg).strip()
        print(f"Expanded to {len(encoded_data)} for IO upload")

        # Send encoded_data to Adafruit IO camera feed
        print("Sending image to Adafruit IO...")
        io.send_data(feed_camera["key"], encoded_data)
        print("Sent image to IO!")

        time.sleep(10)

fails:

Adafruit CircuitPython 9.0.0-beta.0-52-g6c1e34e957 on 2024-02-17; Adafruit Feather ESP32S2 with ESP32S2
>>> 
>>> import code_aio
OV5640
camera initialized
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "code_aio.py", line 65, in <module>
  File "adafruit_io/adafruit_io.py", line 748, in get_feed
  File "adafruit_io/adafruit_io.py", line 578, in _get
  File "adafruit_requests.py", line 752, in get
  File "adafruit_requests.py", line 691, in request
  File "adafruit_requests.py", line 510, in _get_socket
MemoryError: 
>>> 

line 65 is:

    feed_camera = io.get_feed("featheresp32s2")

These may be unrelated issues, let me know if you would prefer them to be separated.

It may be of little general interest since the ESP32S3 support works well and it is not trivial to attach a camera to any esp32s2 board other than the Kaluga (The same issues are present on the Kaluga)
I wanted to report the issue others are aware of potential limitations of using espcamera with esp32s2 boards.
If this is just a "fact of life" for the esp32s2, perhaps it should be noted in the espcamera docs.

I have not tried using the adafruit_OV5640 library instead of espcamera. I will try that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions