espressif / esp32-camera

Apache License 2.0
1.94k stars 645 forks source link

camera_example does not work with AI Thinker ESP32-CAM #700

Open dgploss opened 3 weeks ago

dgploss commented 3 weeks ago

Checklist

How often does this bug occurs?

always

Expected behavior

I'd expect the example to compile and run without any issue.

Actual behavior (suspected bug)

The example application does not find the camera.

Error logs or terminal output

The example compiles using `idf.py build` with a few (harmless?) warnings:

warning: unknown kconfig symbol 'ESP32S2_DEFAULT_CPU_FREQ_240' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'ESP32S3_DEFAULT_CPU_FREQ_240' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'SPIRAM' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'SPIRAM' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'ESP32S2_SPIRAM_SUPPORT' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'ESP32S3_SPIRAM_SUPPORT' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults
warning: unknown kconfig symbol 'SPIRAM_SPEED_80M' assigned to 'y' in /home/esp/esp-idf/components/esp32-camera/examples/camera_example/sdkconfig.defaults

Upload with idf.py flash monitor is successful but the camera does not work:

I (280) cam_hal: cam init ok
E (282) ledc: ledc_channel_config(840): sleep_mode argument is invalid
E (288) camera_xclk: ledc_channel_config failed, rc=102
I (293) sccb-ng: pin_sda 26 pin_scl 27
I (297) sccb-ng: sccb_i2c_port=1
I (300) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
E (339) camera: Camera probe failed with error 0x105(ESP_ERR_NOT_FOUND)
E (339) example:take_picture: Camera Init Failed
I (339) main_task: Returned from app_main()

Steps to reproduce the behavior

Clone esp-idf repository. Clone esp32-camera into esp-idf/components/esp32-camera.

In esp-idf directory run install.sh esp32 and . export.sh.

Choose AI THinker board:

--- a/examples/camera_example/main/take_picture.c
+++ b/examples/camera_example/main/take_picture.c
@@ -6,7 +6,7 @@

 // 1. Board setup (Uncomment):
 // #define BOARD_WROVER_KIT
-// #define BOARD_ESP32CAM_AITHINKER
+#define BOARD_ESP32CAM_AITHINKER

 /**
  * 2. Kconfig setup
@@ -45,8 +45,6 @@

 #include "esp_camera.h"

-#define BOARD_WROVER_KIT 1
-
 // WROVER-KIT PIN Map
 #ifdef BOARD_WROVER_KIT

Run idf.py menuconfig to disabe unavailable camere types (keep only Support OV2640 2MP).

Build and run:

idf.py build
idf.py flash monitor

Project release version

master

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Linux

Operating system version

Debian trixie

Shell

Bash

Additional context

The camera and the board HW appears functional, the Arduino CameraWebServer example builds and runs succesfully.

The esp-idf development environment is correctly set up as other examples work flawlessly (generic_gpio, hello_world, himem, sdmmc, simple_sniffer, etc.)

Is there an earlier version of esp-idf and esp32-camera that are known to work together on the Ai Thinker ESP32-CAM board?

matusz commented 3 weeks ago

Exactly the same issue was reproduced on fedora 38 (Linux fedora 6.5.6-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Oct 6 19:02:35 UTC 2023 x86_64 GNU/Linux)

mpasteur commented 1 week ago

Hi,

i was just struggling with this one! Camera probe failed with error 0x105 often means an hardware outage. Check you wires.

After that you would encounter an error (your log entries are not harmless at all ^^) E (509) cam_hal: cam_config(385): cam_dma_config failed E (515) camera: Camera config failed with error 0xffffffff

That's because in esp-idf > v5.X you have to add esp_psram by yourself in CMakeLists.txt. (cf https://docs.espressif.com/projects/esp-idf/en/v5.0.7/esp32/migration-guides/release-5.x/system.html#psram) Then menuconfig should show you psram entries.

regards

dgploss commented 1 week ago

Hi Marc,

Thanks for your comments.

"Check you wires." is a recurrent suggestion with error 0x105. Unfortunately it is not the case here. I have no "wires", no breadboard, I use a compact esp32-cam-mb board. Moreover other camera examples always work fine: Arduino CameraWebServer (as mentioned earlier), and since then I've also successfully tested a Rust example.

My guess is that the bug is related to E (848) camera_xclk: ledc_channel_config failed, rc=102 and I was hoping that the Espressif devs would have a quick fix for this.

Using esp_psram was a good idea! Now I can see PSRAM properly initialised. Also the relevant warnings disappeared. But the main error remains.

I (29) boot: ESP-IDF v5.4-dev-3952-gbdc4c1ef19-dirty 2nd stage bootloader
I (29) boot: compile time Nov 15 2024 16:10:19
I (29) boot: Multicore bootloader
I (33) boot: chip revision: v3.1
I (36) qio_mode: Enabling default flash chip QIO
I (40) boot.esp32: SPI Speed      : 80MHz
I (44) boot.esp32: SPI Mode       : QIO
I (47) boot.esp32: SPI Flash Size : 4MB
I (51) boot: Enabling RNG early entropy source...
I (55) boot: Partition Table:
I (58) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 nvs              WiFi data        01 02 00011000 00006000
I (71) boot:  1 phy_init         RF data          01 01 00017000 00001000
I (77) boot:  2 factory          factory app      00 00 00020000 00100000
I (84) boot: End of partition table
I (87) esp_image: segment 0: paddr=00020020 vaddr=3f400020 size=0f35ch ( 62300) map
I (111) esp_image: segment 1: paddr=0002f384 vaddr=3ff80000 size=0001ch (    28) load
I (111) esp_image: segment 2: paddr=0002f3a8 vaddr=3ffb0000 size=00c70h (  3184) load
I (115) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=1c108h (114952) map
I (151) esp_image: segment 4: paddr=0004c130 vaddr=3ffb0c70 size=019a8h (  6568) load
I (153) esp_image: segment 5: paddr=0004dae0 vaddr=40080000 size=10ea0h ( 69280) load
I (184) boot: Loaded app from partition at offset 0x20000
I (184) boot: Disabling RNG early entropy source...
I (194) quad_psram: This chip is ESP32-D0WD
I (195) esp_psram: Found 8MB PSRAM device
I (195) esp_psram: Speed: 80MHz
I (195) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode.
W (202) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped
I (210) cpu_start: Multicore app
I (727) esp_psram: SPI SRAM memory test OK
I (735) cpu_start: Pro cpu start user code
I (735) cpu_start: cpu freq: 240000000 Hz
I (735) app_init: Application information:
I (735) app_init: Project name:     camera_example
I (739) app_init: App version:      v2.0.13-1-g6f51764-dirty
I (745) app_init: Compile time:     Nov 15 2024 16:10:46
I (750) app_init: ELF file SHA256:  be72e67f6...
I (754) app_init: ESP-IDF:          v5.4-dev-3952-gbdc4c1ef19-dirty
I (760) efuse_init: Min chip rev:     v0.0
I (764) efuse_init: Max chip rev:     v3.99 
I (768) efuse_init: Chip rev:         v3.1
I (772) heap_init: Initializing. RAM available for dynamic allocation:
I (778) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (783) heap_init: At 3FFB3778 len 0002C888 (178 KiB): DRAM
I (788) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (794) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (799) heap_init: At 40090EA0 len 0000F160 (60 KiB): IRAM
I (805) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator
I (811) spi_flash: detected chip: generic
I (815) spi_flash: flash io: qio
I (818) main_task: Started on CPU0
I (821) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (828) main_task: Calling app_main()
I (831) gpio: GPIO[25]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:2 
I (840) cam_hal: cam init ok
E (842) ledc: ledc_channel_config(840): sleep_mode argument is invalid
E (848) camera_xclk: ledc_channel_config failed, rc=102
I (853) sccb-ng: pin_sda 26 pin_scl 27
I (856) sccb-ng: sccb_i2c_port=1
I (860) gpio: GPIO[32]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
E (898) camera: Camera probe failed with error 0x105(ESP_ERR_NOT_FOUND)
E (898) example:take_picture: Camera Init Failed
I (898) main_task: Returned from app_main()
mpasteur commented 1 week ago

Hi, i use the same esp32-cam ESP32-D0WD() but without esp32-cam-mb. I've see an improvment using a stable external power source in replacement to the usb one used during flash (through my ftdi uart)

you've an esp-idf version more recent than mine (i'm on the stable version 5.3.1 and you're on v5.4-dev). Did you try with 5.3.1 ?

Comparing our logs you have a first error: E (842) ledc: ledc_channel_config(840): sleep_mode argument is invalid E (848) camera_xclk: ledc_channel_config failed, rc=102

EDIT: Oops sorry i've just see that you mentionned the "E (848) camera_xclk: ledc_channel_config failed, rc=102" error ^^

mpasteur commented 1 week ago

I've just check with the master branch of esp-idf and i reproduce your bug ! So there is a change in current branch which is incompatible with current version of esp32-camera component The ledc_channel_config now need a sleep_mode argument.

I don't get exactly what to put on this one but adding ch_conf.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD; (the default value) on xclk.c l57 make the trick.

@me-no-dev can you take a look on this ?

dgploss commented 6 days ago

Hi,

I've also verified with esp-idf v5.3.1 and camera_example v2.0.13 , it works fine there: I (1199) example:take_picture: Picture taken! Its size was: 153600 bytes. Thanks for the suggestions.