ESP32-CAM Got invalid frame from camera!

After using Raspberry Pis and Home Assistant for some time, I started thinking that I should explore smaller cheaper microcontrollers for connecting sensors etc. Years back I programmed in machine code and assembler, but these days prefer not to fiddle at that level of detail “reinventing the wheel”. I have avoided Arduino so far, and then discovered ESPhome.

I purchased a ESP32-CAM thinking it would be a good learning exercise, but got side-tracked until fairly recently.

ESP32-CAM now connects to Wi-Fi, but I am not getting any result from it.
I copied and pasted the Ai-Thinker Camera Example configuration entry (and have since checked against other tutorials). I have since pasted additional code which does work to turn the ESP32-CAM’s LED on and off, so it is definitely communicating correctly.

#
# This is the ESP32-CAM board (DFRobot0602) with an AI Thinker ESP32-S module built-in.
#
substitutions:
  # Modify variables based on your settings
  hostname: "esp32-cam"
  devicename: esp32-cam

esphome:
  name: $devicename

esp32:
  board: esp32cam
  framework:
    type: arduino

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none

  # Optional manual IP (quicker to reconnect - don't wait for router to issue DHCP address)
  manual_ip:
    static_ip: 192.168.1.163
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
  fast_connect: true

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "$devicename Fallback Hotspot"
    password: "RiYYkI0mWCkc"

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

# Enable logging
logger:

captive_portal:


# Ai-Thinker Camera  - Example configuration entry
#
esp32_camera:
  name: $devicename
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  vertical_flip: false
  horizontal_mirror: false
#  resolution: 400x296
#  max_framerate: 12 fps

#
# Flashlight
output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4
light:
  - platform: binary
    output: gpio_4
    name: $devicename light
    id: camera_flash

I am powering the ESP32-CAM from a USB FTDI board connected to a PC USB3 port. A USB chargerDoctor reports 4.8V and about 0.17A. Also tried a phone charger which reports 5.02V 0.17A

I am able to update OTA from the Home Assistant ESPHome add-on:

INFO Reading configuration /config/esphome/esp32-cam.yaml...
WARNING GPIO0 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-cam (board: esp32cam; framework: arduino; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <WiFi> 1.0
|-- <FS> 1.0
|-- <Update> 1.0
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <AsyncTCP-esphome> 1.2.2
|-- <DNSServer> 1.1.0
|-- <ESPmDNS> 1.0
Compiling /data/esp32-cam/.pioenvs/esp32-cam/src/main.cpp.o
Linking /data/esp32-cam/.pioenvs/esp32-cam/firmware.elf
RAM:   [=         ]  14.2% (used 46592 bytes from 327680 bytes)
Flash: [======    ]  58.3% (used 1070242 bytes from 1835008 bytes)
Building /data/esp32-cam/.pioenvs/esp32-cam/firmware.bin
esp32_create_combined_bin(["/data/esp32-cam/.pioenvs/esp32-cam/firmware.bin"], ["/data/esp32-cam/.pioenvs/esp32-cam/firmware.elf"])
Wrote 0x115510 bytes to file /data/esp32-cam/.pioenvs/esp32-cam/firmware-factory.bin, ready to flash to offset 0x0
========================= [SUCCESS] Took 39.55 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.163
INFO Uploading /data/esp32-cam/.pioenvs/esp32-cam/firmware.bin (1070352 bytes)
Uploading: [============================================================] 100% Done...


INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.1.163 using esphome API
INFO Successfully connected to 192.168.1.163
[12:14:03][I][app:102]: ESPHome version 2022.5.1 compiled on Jun  5 2022, 12:13:01
[12:14:03][C][wifi:491]: WiFi:
[12:14:03][C][wifi:353]:   Local MAC: A4:E5:7C:D5:4A:14
[12:14:03][C][wifi:354]:   SSID: [redacted]
[12:14:03][C][wifi:355]:   IP Address: 192.168.1.163
[12:14:03][C][wifi:357]:   BSSID: [redacted]
[12:14:03][C][wifi:358]:   Hostname: 'esp32-cam'
[12:14:03][C][wifi:360]:   Signal strength: -34 dB ▂▄▆█
[12:14:03][C][wifi:364]:   Channel: 1
[12:14:03][C][wifi:365]:   Subnet: 255.255.255.0
[12:14:03][C][wifi:366]:   Gateway: 192.168.1.1
[12:14:03][C][wifi:367]:   DNS1: 192.168.1.1
[12:14:03][C][wifi:368]:   DNS2: 0.0.0.0
[12:14:04][C][logger:274]: Logger:
[12:14:04][C][logger:275]:   Level: DEBUG
[12:14:04][C][logger:276]:   Log Baud Rate: 115200
[12:14:04][C][logger:277]:   Hardware UART: UART0
[12:14:04][C][gpio.output:010]: GPIO Binary Output:
[12:14:04][C][gpio.output:011]:   Pin: GPIO4
[12:14:04][C][light:104]: Light 'esp32-cam light'
[12:14:04][C][esp32_camera:048]: ESP32 Camera:
[12:14:04][C][esp32_camera:049]:   Name: esp32-cam
[12:14:04][C][esp32_camera:050]:   Internal: NO
[12:14:04][C][esp32_camera:052]:   Data Pins: D0:5 D1:18 D2:19 D3:21 D4:36 D5:39 D6:34 D7:35
[12:14:04][C][esp32_camera:053]:   VSYNC Pin: 25
[12:14:04][C][esp32_camera:054]:   HREF Pin: 23
[12:14:04][C][esp32_camera:055]:   Pixel Clock Pin: 22
[12:14:04][C][esp32_camera:056]:   External Clock: Pin:0 Frequency:20000000
[12:14:04][C][esp32_camera:057]:   I2C Pins: SDA:26 SCL:27
[12:14:04][C][esp32_camera:058]:   Reset Pin: -1
[12:14:04][C][esp32_camera:076]:   Resolution: 640x480 (VGA)
[12:14:04][C][esp32_camera:101]:   JPEG Quality: 10
[12:14:04][C][esp32_camera:103]:   Contrast: 0
[12:14:04][C][esp32_camera:104]:   Brightness: 0
[12:14:04][C][esp32_camera:105]:   Saturation: 0
[12:14:04][C][esp32_camera:106]:   Vertical Flip: OFF
[12:14:04][C][esp32_camera:107]:   Horizontal Mirror: OFF
[12:14:04][C][esp32_camera:108]:   Special Effect: 0
[12:14:04][C][esp32_camera:109]:   White Balance Mode: 0
[12:14:04][C][esp32_camera:112]:   Auto Exposure Control: 1
[12:14:04][C][esp32_camera:113]:   Auto Exposure Control 2: 0
[12:14:04][C][esp32_camera:114]:   Auto Exposure Level: 0
[12:14:04][C][esp32_camera:115]:   Auto Exposure Value: 300
[12:14:04][C][esp32_camera:116]:   AGC: 1
[12:14:04][C][esp32_camera:117]:   AGC Gain: 0
[12:14:04][C][esp32_camera:118]:   Gain Ceiling: 0
[12:14:04][C][esp32_camera:124]:   Test Pattern: NO
[12:14:04][C][psram:020]: PSRAM:
[12:14:04][C][psram:021]:   Available: YES
[12:14:04][C][captive_portal:088]: Captive Portal:
[12:14:04][C][mdns:084]: mDNS:
[12:14:04][C][mdns:085]:   Hostname: esp32-cam
[12:14:04][C][ota:085]: Over-The-Air Updates:
[12:14:04][C][ota:086]:   Address: 192.168.1.163:3232
[12:14:04][C][api:138]: API Server:
[12:14:04][C][api:139]:   Address: 192.168.1.163:6053
[12:14:04][C][api:143]:   Using noise encryption: NO
[12:14:05][W][esp32_camera:162]: Got invalid frame from camera!
[12:14:09][W][esp32_camera:162]: Got invalid frame from camera!
[12:14:13][W][esp32_camera:162]: Got invalid frame from camera!
[12:14:17][W][esp32_camera:162]: Got invalid frame from camera!
[12:14:21][W][esp32_camera:162]: Got invalid frame from camera!

In HA Settings > Integrations, under ESPHome I have esp32-cam, which looks like

As mentioned, the light switch does turn the ESP32-CAM’s LED on and off; but only “idle” or “unavailable” from the camera.

Other references I have found on google suggest that the camera hardware may be faulty - but wondering if there is anything else i can try before attempting to return the camera I bought back in October.
I appreciate all suggestions.

esp32_camera is just for the configuration needed.

If you are expecting to see the images…

No you do not have to use the camera web server. The esp32_camera provides a camera entity to ha.

This is probably the problem, it gave me the same result too, bought another lens and everything worked

Great!

What is the solution then? I am curious.

Check that it is an ai-thinker?

Check the module’s datasheet.

The ESP32-CAM integration (screenshot at end of original post) does provide “esp32-cam” (the totally original name I gave it) under the Sensors heading. Clicking [Add to dashboard] does add a Picture Entity Card … but it shows as unavailable :frowning: Totally understandable if my camera hardware is faulty.

FYI, my interpretation of the web server component is that it makes camera video available for other external surveillance or PVR software.

1 Like

Yes that is correct.

Can you tell us exactly what hardware you bought?

I bought from Australian distributor/retailer Core electronics. It is ESP32-CAM Development Board, DFR0602 from DFRobot.

The ESP32-S chip on the back has AI-thinker logo. It came with a AF2569 camera already installed, and I haven’t even taken the lens protector off in case I damage sensitive components.

Thanks, the pin assignments look right ESP32-CAM Development Board with onboard camera Wiki - DFRobot

The other thing to check is that the power is adequate, and that the ribbon cable is seated properly. Carefully.

Also found [W][esp32_camera:151]: Got invalid frame from camera! · Issue #1225 · esphome/issues · GitHub

Thank Nick for taking the effort to continue with this.

I moved the cam to a phone charger’s 2.4A USB socket, which my cheap ChargerDoctor reports as 5.02V 0.17A.

My Home Assistant is kept totally up-to-date (core 2022.6.2, HA OS 8.1), and yes that was the post which most clearly suggests that my camera hardware may be faulty.

I am rather apprehensive of asking Core to replace the unit, given (a) the 8 months since purchase, (b) the fact that they probably don’t know what ESPHome is, let alone (c) that I have downloaded 3rd-party firmware. At least it’s a relatively small price.

Going forward I need to test new hardware soon after I receive it - but that will be complicated by my choice not to dive into the learning curves that are Arduino, ESP-IDE and every manufacturer’s cloud app.

You could (and should given you have nothing to lose) try cleaning and reseating the connector on the cable that connects the camera to the exp.

Could you solve that issue?

Nah, I should have purchased another ESP32-CAM and tested it straight away - I can still do that - but since the ESP32-CAM was my only ESPHome device I just shelved ESPHome, and got distracted with other things, like my IoT devices dropping of my wi-fi.

After breaking the camera connector on my RasPi 3, I am reluctant to apply force to clean and reseat the camera module as nickrout suggested.

As it happens I am currently trying to install CloudCutter to detach my Tuya devices from the cloud, and hopefully bring them into ESPHome (probably via libreTuya-esphome) … which hopefully will motivate me to get my head around ESPHome (and the camera).

Vincent are you also getting the “Got invalid frame from camera” error message ?

Here we meet again :sweat_smile:

We’re connecting the dots, I first found you when you started a discussion about Wifi routers and I told people in that discussion that I had bought 16 of those ESP32-Cams. I just received my package and while doing the first installation I had this same issue of “Got invalid frame from camera” error message. Since I had many ESP32-Cams I could isolate each component of the equation and found out the board seems to be the culprit. I could switch the OV2640 camera to another board and it worked. So I will probably request RMA for that board and it should be good to go. The next ESP32-Cam board was working flawlessly.

Thanks for your answer @donburch888 and don’t lose trust into ESPHome, it’s really amazing what you can do with that!

1 Like

Your description doesn’t rule out a flaky/dirty connection :slight_smile:

The ESP32-Cam is brand new, I see absolutely no debris inside the connector. I will double-check it and will update this post if it is the issue here.

These things generally are produced in poor QC environments. Added to that the general flakiness of those connectors. Not saying you are wrong, but a simple re-seating can sometimes be effective. Ymmv.

I agree with you, but re-seating was tested at least 4-5 times. But I haven’t tried to clean the connector since it didn’t appear to have any debris… I will test it and update you

1 Like

Posting in case this helps anyone else with the ESP32 cam “invalid frame”, remove the ref to power_down_pin: GPIO32 from the YAML and try again, it worked for me.