fr0zt
March 23, 2021, 7:12pm
1
Hello,
I have an AI Thinker ESP32 Cam that I’m trying to set up with ESPHome. When I include code that enables the onboard flash LED the camera stops working with these errors looping:
[W][esp32_camera:153]: Got invalid frame from camera!
[E][camera.c:495] i2s_run(): Timeout waiting for VSYNC
This yml the camera works and produces a valid picture stream:
esphome:
name: coop_esp32_door
platform: ESP32
board: esp32cam
wifi:
ssid: "ABC"
password: "123"
output:
- platform: ledc
pin: GPIO4
id: flash32
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
vertical_flip: false
name: "Coop Cam v2"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
Likewise, just including the LED flash code works:
esphome:
name: coop_esp32_door
platform: ESP32
board: esp32cam
on_boot:
then:
- output.set_level:
id: flash32
level: 2%
- delay: 500ms
- output.turn_off: flash32
wifi:
ssid: "ABC"
password: "123"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
But when I include the LED flash code with the camera code, I get the errors:
esphome:
name: coop_esp32_door
platform: ESP32
board: esp32cam
on_boot:
then:
- output.set_level:
id: flash32
level: 2%
- delay: 500ms
- output.turn_off: flash32
wifi:
ssid: "ABC"
password: "123"
output:
- platform: ledc
pin: GPIO4
id: flash32
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
vertical_flip: false
name: "Coop Cam v2"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
Does anyone know if there’s an issue using the onboard LED and camera at the same time?
zoogara
(Daryl)
March 23, 2021, 7:44pm
2
Possibly a power issue? True a higher current supply - if you are powering via the USB port on the HA machine or your PC that can cause similar issues.
fr0zt
March 23, 2021, 11:33pm
3
I’m using a 2.4A power supply, which I think should be more than enough? I added a 1A power supply in parallel and get the same errors.
I also can’t get other PWM components working while the camera component is present. See below for another yml, this time where I have a pwm switch component. As soon as the device boots it starts giving the same error:
Got invalid frame from camera!
yml:
esphome:
name: coop_esp32_door
platform: ESP32
board: esp32cam
wifi:
ssid: "ABC"
password: "123"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Coop Esp32 Door Fallback Hotspot"
output:
- platform: ledc
pin: GPIO13
id: IN1
frequency: "25000Hz"
- platform: ledc
pin: GPIO2
id: IN2
frequency: "25000Hz"
light:
- platform: monochromatic
output: IN1
id: andrew_mono_down
restore_mode: ALWAYS_OFF
name: "Andrew Mono Down"
- platform: monochromatic
output: IN2
id: andrew_mono_up
restore_mode: ALWAYS_OFF
name: "Andrew Mono Up"
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
vertical_flip: false
name: "Coop Cam v2"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
taikapanu
(Juha Panu)
March 24, 2021, 3:47am
4
Are you powering it from the 5v pins? Powering from 3.3 will be a problem.
You could also add small capacitor in the esp pins.
And in general, when the wifi is in used then ADC2 mapped pins shouldn’t be used. Might cause some stability errors.
fr0zt
March 24, 2021, 4:31am
5
Yes, powering from 5v.
I googled ADC2 pins and it looks like that refers to analogue to digital pins? This page seems to indicate that they’re GPIO 32-39? https://esphome.io/components/sensor/adc.html
Those are just used by the camera. There aren’t any issues using the camera while WiFi is enabled (as long as the PWM switches aren’t enabled)
Thanks
taikapanu
(Juha Panu)
March 24, 2021, 4:36am
6
GPIO 13 and 2 are part of the ADC2. Note is that might cause instability. Guess it depends on multiple items.
ADC2_CH0 (GPIO 4)
ADC2_CH1 (GPIO 0)
ADC2_CH2 (GPIO 2)
ADC2_CH3 (GPIO 15)
ADC2_CH4 (GPIO 13)
ADC2_CH5 (GPIO 12)
ADC2_CH6 (GPIO 14)
ADC2_CH7 (GPIO 27)
ADC2_CH8 (GPIO 25)
ADC2_CH9 (GPIO 26)
fr0zt
March 24, 2021, 4:55am
7
Ok, I’ll try other GPIO pins.
It looks like the only pins on the ESP 32 Cam available that aren’t in that list are GPIO 1, 3, and 16. I’ll need 4 total (2 for motor, 2 for endstops), but will try with just the motor first.
fr0zt
March 24, 2021, 11:16pm
8
No luck. I switched to using GPIO 1 and GPIO 3 (instead of 2 and 13), but still same error. Even without a motor plugged in, the below yml results in [16:12:23][W][esp32_camera:153]: Got invalid frame from camera!
errors every second.
I guess PWM GPIO output just doesn’t work with the camera enabled? Has anyone got this working?
esphome:
name: coop_esp32_door
platform: ESP32
board: esp32cam
wifi:
ssid: "ABC"
password: "123"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Coop Esp32 Door Fallback Hotspot"
output:
- platform: ledc
pin: GPIO3
id: IN1
frequency: "25000Hz"
- platform: ledc
pin: GPIO1
id: IN2
frequency: "25000Hz"
light:
- platform: monochromatic
output: IN1
default_transition_length: 5s
id: andrew_mono_down
restore_mode: ALWAYS_OFF
name: "Andrew Mono Down"
- platform: monochromatic
output: IN2
default_transition_length: 5s
id: andrew_mono_up
restore_mode: ALWAYS_OFF
name: "Andrew Mono Up"
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
vertical_flip: false
name: "Coop Cam v2"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
fr0zt
March 29, 2021, 6:24pm
9
Is there anywhere I could submit this as an issue?
This is a big problem if PWM cannot be used with the ESP32 Cam in ESPHome while the camera is enabled.
@fr0zt this note explains it:
Note
Camera uses PWM timer #1 . If you need PWM (via the ledc
platform) you need to manually specify a channel there (with the channel: 2
parameter) on this page . I had the same issue, set the ledc channel to ‘2’ and it works.
4 Likes
alco
(Alco)
March 4, 2022, 7:36pm
11
Sample code with working PWM on the ESP32-cam Led pin, for anyone that googled this:
# Flashlight, use channel 2 for PWM, channel 1 is used by camera.
output:
- platform: ledc
pin: GPIO4
id: gpio_4
channel: 2
## GPIO_4 is the flash light pin
light:
- platform: monochromatic
output: gpio_4
name: PWM light
also I made my ESP32 cam configuration public at my github:
10 Likes