ESP32 Cam - working!

Big thanks for your suggestions, but…

Low current was already eliminated, I tried with 5V 4A power supply (which btw isn’t mobile phone charger at all), via 5V & GND PINs, no luck. Beside that, I’m not sure could this be a case, since same camera is working on Tasmota and on stock firmware via same micro USB port, but ok, I tried.

My biggest doubt is either PIN assignment isn’t ok, or maybe the problem could be in ESPHome, since this was already the case before. Ok, I tried PIN reverse order last night, cause Aliexpress seller was send me same files you recommending (I asked him does he know ESPHome config, of course he sent me stock files :rofl:)

Just one little correction: As per ESPHome wiki, 10 is best quality, 63 worst, so I tried with 20, and no luck :sleepy:

More and more I believe that problem is in ESPHome and HA, cause Tasmota template is using same PINs as AI Thinker example from ESPHome wiki and it is working in Tasmota + it is not showing video stream/camera entity in HA as integrated Tasmota device, or maybe I’m doing something wrong :rofl: :rofl: ? (this is some new moment I just discovered).

It very likely is something incompatible with ESPHome camera code, then. i know the ESPHome low-level interrupt code for ESP32-cam is incompatible with other devices, specifically because of how Espressif handles the interrupts. Good luck with your cameras. It looks like Tasmota is handling it very well!

Actually, something was screwed in latest versions of ESPHome, check this issue:

All these comments are by 2 weeks ago and last week.
I deleted ESPHome container and re-downloaded version 2022.11.5 - ESP32 cam is working now, with most usually used config example - AI-Thinker.

As for now, it stays mystery for me why in case of Tasmota, video stream is shown in Tasmota web UI, together with button switch and dimmer for flash LED, and there is no camera entity in HA when I integrate same that Tasmota device.

Perhaps because the tasmota integration makes no mention of supporting cameras Tasmota - Home Assistant

1 Like

True story :smiley:

Hi, may i ask how you did that?
I didn’t get an option to choose an other version.

First, I would ask you how do you using docker? If you are using it via Portainer and GUI, then I don’t know. Long time ago I tried Portainer and didn’t liked it.
I’m installing all my containers with docker-compose (command line). So, procedure in my case would be:

Stop container (replace esphome with the name of your ESPHome container):

docker stop esphome

Delete all stopped containers and unused networks:

docker system prune -a

Edit docker-compose.yaml file, so you appending the version of container you want to pull, instead of default, i.e. latest one, e.g. image: esphome/esphome:2022.11.5 Example of my docker-compose.yaml file, ESPHome section:

  esphome:
    container_name: esphome
    image: esphome/esphome:2022.11.5
    volumes:
      - "./esphome:/config"
      - "/etc/localtime:/etc/localtime:ro"
    restart: always
    privileged: true
    network_mode: host
    ports:
      - 6052:6052
      - 6123:6123

Finally, executing following command from directory where docker-compose.yaml file is located:

docker-compose up -d

In short, what ever way you are using to run docker containers, you basically need to:

  1. Stop container
  2. Delete container
  3. Append :2022.11.5 to your command line.

So no matter if you are using Portainer, docker-compose or docker run, just replace esphome with esphome:2022.11.5 (or esphome:latest with esphome:2022.11.5, depending on your current setup).

not sure if you are still having issues with this or not.

but i will mention i got the exact same camera you have and loaded the esp32 cam code in your post and it seems to be working.

not final config but setup enough to get video working.

substitutions:
  display_name: Camera
  device_description: ESP32
  friendly_name: Camera

esphome:
  name: "esp-cam"

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-0364Dc"
    password: "oQFv7YaFlvBK"

captive_portal:

web_server:
  port: 80    

time:
  - platform: homeassistant
    id: time_homeassistant
    on_time_sync:
      - component.update: sensor_uptime_timestamp

sensor:
  - platform: uptime
    id: sensor_uptime
  - platform: template
    id: sensor_uptime_timestamp
    name: "$friendly_name Uptime"
    device_class: "timestamp"
    accuracy_decimals: 0
    update_interval: never
    lambda: |-
      static float timestamp = (
        id(time_homeassistant).utcnow().timestamp - id(sensor_uptime).state
      );
      return timestamp;
  - platform: wifi_signal
    name: "$friendly_name Signal"
    update_interval: 60s

button:
  - platform: restart
    name: "$friendly_name Restart"

esp32_camera:
  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
  resolution: 640x480
  name: $friendly_name
  jpeg_quality: 10

Hey, thanks for the hint. In mean time, I gave up of ESPHome for this certain device. One reason: I had no success to make it work with latest version of ESPHome. Another one: I made it work with ESPHome 2022.11.5, but performances were really disappointing in my case.

I made it work with Arduino code from here. Afterwards, I integrated it to HA as MJPEG IP cam. Good thing with above Arduino code is that it has still image URL as well, so I can use it directly in DoubleTake, this was my intention.

On the other hand, I didn’t gave up from ESPHome completely, cause I like it and it gives you lot of control possibilities, so I will try your example as soon as I’m back to my home these days.

Do you know maybe what part of your code was deserved that video start working?

Thx

Sorry, but no joy, still getting same errors with your code.
I think that something is different on these boards I bought on Aliexpress. For example: I also had no success to get it work if I flash them from Arduino, using native ESP32 board libraries, which could be downloaded from Arduino IDE. Only with these libraries from here, found it here, I had success (manual unpack method to C:\Program Files (x86)\Arduino\hardware\espressif). You know how it’s going with Chinese no-name devices, maybe something was changed.
I will stick with MJPEG IP method for now, only one difference: will try this stuff which can be accessed from multiple clients same time: GitHub - arkhipenko/esp32-cam-mjpeg-multiclient: ESP32 MJPEG Multiclient Streaming Server

1 Like

had another look at your error above and it seems to be a pin-mismatch error, got a few of those until I stumbled on the right pinout config. if you got it working with the arduino code from [here]( arkhipenko/esp32-cam-mjpeg: ESP32 mjpeg streaming server (github.com)), it has to use one of the 5 pin outs defined in the camera_pins.h file, did you try them all in ESPHOME? My code uses the CAMERA_MODEL_AI_THINKER pins.

I will add that this is how I built the ESPHOME code for mine:

  • basic flash from ESPHOME web installer
  • adopt into ESPHOME add-on in HomeAssistant
  • turn on webserver and flash OTA
  • add to HomeAssisstant via the ESPHOME integration
  • add reboot button and flash OTA
  • add esp32_camera code and flash OTA

kept flashing different pin-outs until I found the one above that did not generate an error on esp32_camera:099

add remaining items like time, sensors and substitutions.

here is the device info from the esphome text sensor:
Device Info 2022.12.3|Flash: 4096kB Speed:40MHz Mode:DIO|Chip: ESP32 Features:WIFI_BGN,BLE,BT, Cores:2 Revision:1|ESP-IDF: v4.4.2|EFuse MAC: 40:22:D8:03:64:DC|Reset: Software Reset CPU|Wakeup: Unknown

Yeah it used to be that Ali vendors had some info from which you could get the pin outs, but that seems to have disappeared.

@briodan and @nickrout

@briodan : big thanks for your help, but it shouldn’t be wrong pin out (at least from my understanding :grinning:).

Yes, I tried all pin outs provided in mentioned Arduino code and was also tried all pin outs from ESPHome wiki. My camera is using AI-Thinker pin out, and sorry cause I forgot to mention, with Arduino code I’m using it as AI-Thinker model, not as ESP EYE, as provided per default on esp32-cam-mjpeg github (commented #define CAMERA_MODEL_ESP_EYE and uncommented #define CAMERA_MODEL_AI_THINKER).

image

To make things more clear, my 3 cameras bought here, for some reason simply:

  • Works with mentioned Arduino code, AI-Thinker model, if I’m using these board libraries
  • Works with ESPHome 2022.11.5 (and below probably), AI-Thinker model
  • Not working with latest ESPHome

Real thanks for your help, but I really think that I already tried everything. Maybe some next ESPHome update fix the problem.

Test with this configuration. I use custom_component on a board and after the last updates it stopped working. With version 2.0.0 it is working.


esp32:
  board: esp32dev
  framework:
    type: arduino
    version: 2.0.0

Sorry, but no luck :pensive:

With version 2.0.0 of Arduino framework, I can compile barely minimum conf (web server, etc.):

esphome:
  name: camera-living-room

esp32:
  board: esp32dev
  framework:
    type: arduino
    version: 2.0.0

logger:

api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "Camera-Living-Room"
    password: "<some password>"

captive_portal:

web_server:
  port: 80

But if I append ESP32 Camera component to above configuration:

esp32_camera:
  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
  resolution: 640x480
  name: Camera Living Room
  jpeg_quality: 10

I’m getting compile error:

INFO Reading configuration /config/camera-living-room.yaml...
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
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
INFO Generating C++ source...
INFO Compiling app...
Processing camera-living-room (board: esp32dev; framework: arduino; platform: platformio/espressif32 @ 5.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- AsyncTCP-esphome @ 1.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- ArduinoJson @ 6.18.5
Compiling .pioenvs/camera-living-room/src/esphome/components/api/api_connection.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/api_frame_helper.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/api_pb2.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/api_pb2_service.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/api_server.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/list_entities.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/proto.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/subscribe_state.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/api/user_services.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/esp32/core.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/esp32/gpio.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/esp32/preferences.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/esp32_camera/esp32_camera.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/json/json_util.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/logger/logger.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/md5/md5.cpp.o
Compiling .pioenvs/camera-living-room/src/esphome/components/mdns/mdns_component.cpp.o
In file included from src/esphome/components/esp32_camera/esp32_camera.cpp:4:
src/esphome/components/esp32_camera/esp32_camera.cpp: In member function 'virtual void esphome::esp32_camera::ESP32Camera::dump_config()':
src/esphome/components/esp32_camera/esp32_camera.cpp:60:56: error: 'struct camera_config_t' has no member named 'pin_sccb_sda'; did you mean 'pin_sscb_sda'?
   ESP_LOGCONFIG(TAG, "  I2C Pins: SDA:%d SCL:%d", conf.pin_sccb_sda, conf.pin_sccb_scl);
                                                        ^~~~~~~~~~~~
src/esphome/core/log.h:94:90: note: in definition of macro 'esph_log_config'
   esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                          ^~~~~~~~~~~
src/esphome/components/esp32_camera/esp32_camera.cpp:60:3: note: in expansion of macro 'ESP_LOGCONFIG'
   ESP_LOGCONFIG(TAG, "  I2C Pins: SDA:%d SCL:%d", conf.pin_sccb_sda, conf.pin_sccb_scl);
   ^~~~~~~~~~~~~
src/esphome/components/esp32_camera/esp32_camera.cpp:60:75: error: 'struct camera_config_t' has no member named 'pin_sccb_scl'; did you mean 'pin_sscb_scl'?
   ESP_LOGCONFIG(TAG, "  I2C Pins: SDA:%d SCL:%d", conf.pin_sccb_sda, conf.pin_sccb_scl);
                                                                           ^~~~~~~~~~~~
src/esphome/core/log.h:94:90: note: in definition of macro 'esph_log_config'
   esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                          ^~~~~~~~~~~
src/esphome/components/esp32_camera/esp32_camera.cpp:60:3: note: in expansion of macro 'ESP_LOGCONFIG'
   ESP_LOGCONFIG(TAG, "  I2C Pins: SDA:%d SCL:%d", conf.pin_sccb_sda, conf.pin_sccb_scl);
   ^~~~~~~~~~~~~
src/esphome/components/esp32_camera/esp32_camera.cpp: In member function 'void esphome::esp32_camera::ESP32Camera::set_i2c_pins(uint8_t, uint8_t)':
src/esphome/components/esp32_camera/esp32_camera.cpp:220:17: error: 'struct camera_config_t' has no member named 'pin_sccb_sda'; did you mean 'pin_sscb_sda'?
   this->config_.pin_sccb_sda = sda;
                 ^~~~~~~~~~~~
                 pin_sscb_sda
src/esphome/components/esp32_camera/esp32_camera.cpp:221:17: error: 'struct camera_config_t' has no member named 'pin_sccb_scl'; did you mean 'pin_sscb_scl'?
   this->config_.pin_sccb_scl = scl;
                 ^~~~~~~~~~~~
                 pin_sscb_scl
Compiling .pioenvs/camera-living-room/src/esphome/components/mdns/mdns_esp32_arduino.cpp.o
*** [.pioenvs/camera-living-room/src/esphome/components/esp32_camera/esp32_camera.cpp.o] Error 1
========================== [FAILED] Took 7.02 seconds ==========================

Did you done something else except of adding version: 2.0.0?

Thx

I just include the version, but the board I use custom_component on is not an espcam.
I have an ESPCAM in the drawer, but I can only test it tomorrow or Friday

I tested it here and for the camera it doesn’t work using version 2.0.0, it had the same error.

This is the yaml I used, if you want to test it, here it works normally with the latest version of esphome

esphome:
  name: espcam2

esp32:
  board: esp32cam
  framework:
    type: arduino
    #version: 2.0.2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "HeLCE2wZJFUmUF+fwt1cPAOLIr1O4UYoMP9xFcZ6r3E="

ota:
  password: "5efe4130e728775736f55f3a145b178f"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Espcam2 Fallback Hotspot"
    password: "9Iwhk6M01TE9"

captive_portal:


esp32_camera_web_server:
  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot
    
esp32_camera:
  id: teste
  internal: true         
  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

Thanks a lot for your effort, but this is the same configuration as I used before. Except of that you have:

  id: teste
  internal: true

I can try add it, but AFAIK, this will make that camera entity will not be exposed to Home Assistant, right? So this shouldn’t be useful?

I think main problem with my device is in Arduino libraries as said before. Next words are only my assumptions, so please don’t take me serious and be free to correct me if I’m wrong.

  1. When we installing ESP32 boards to Arduino IDE, most of us are adding https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json to File > Preferences > Additional Boards Manager URLs. From my understanding, this adding custom repository, GitHub - espressif/arduino-esp32: Arduino core for the ESP32 to Arduino IDE, where from libraries/boards can be downloaded later on, in Arduino Boards Manager. Of course, some other URL can be also added to Additional Boards Manager URLs, as long as you have repo on that URL.
  2. Let’s ignore shortly ESPHome and Home Assistant, and focus to Arduino only. I had no success to make my ESP32cam device works, by flashing Arduino code, if I’m using ESP32 boards from above mentioned github repo (even with default provided Arduino examples).
  3. Once when I deleted ESP32 boards from github repo, and manually installed boards from here (manual installation > download > extract archive with libraries into C:\Program Files (x86)\Arduino\hardware), my device started working, flashed with same Arduino code as before.
  4. I believe (but didn’t checked) that ESPHome is using “default” ESP32 Arduino repo in background, i.e. https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json and my device simply not working with this.

Have you tried the solutions in the github thread, ie either

Compiling with esphome 2022.11.5; or

Using arduino 1.18.9?

Which one? I am keep an eye on this.

This works for me. Cannot make video work if I compile it with ESPHome versions newer by 2022.11.5

I believe it is a typo and you was meant on 1.8.19 actually. Yes, I’m using my cameras, flashed with Arduino code, from Arduino IDE 1.8.19. (Actually, it was from 1.8.16 all the time, just upgraded to 1.8.19 and it is also working, but want to say didn’t flashed them from Arduino IDE 2.x.x at all)