ESP32Cam + DfPlayer + LD2410 (UART)

Hi fellows. Since 2 weeks i’m using home assistant, and i already have a couple of sensors and cameras, included the PV and EVCC Charger. I am nearly addicted :stuck_out_tongue:

I’ve successful built a doorphone (DIY Doorphone with voice response topic)
It uses a DfPlayer via UART interface, and the ESP32 cam.
I’ve had the “brillant idea” to include in the project two buttons, and also a LD2410 sensor (necessairly via UART, due reliability).

I’m stuck with DfPlayer integration (all works well without LD2410). when i add it, does not work

Maybe i’m asking too much to the ESP32 Cam? looking at the log, there is no data flood from LD2410 sensor (when DfPlayer is disabled)…

here the config (a bit streamlined) :

#ESP32Cam + DfPlayer + LD2410


substitutions:
  statuslightpin: GPIO33
  flashlightpin: GPIO4
  buttonpin: GPIO12
  buttonpin2: GPIO15
  # dfplayer
  df_tx_pin: GPIO14
  df_rx_pin: GPIO13
  #ld2410
  ld_tx_pin: GPIO2
  ld_rx_pin: GPIO16


esphome:
  name: $devicename
  friendly_name: $devicename
  platform: ESP32
  board: esp32cam #esp32dev
  on_boot:
    priority: -10
    then:
      - light.turn_on: $statuslight

external_components:
  - source: github://esphome/esphome@dev
    components: [ ld2410 ]
 
# Enable logging
logger:
  level: DEBUG
 
# Enable Home Assistant API
api:
 
ota:

# Camera config
esp32_camera:
  name: $hostname 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: 1600x1200 #2560x1920 #1600x1200
  idle_framerate: 0.01 fps # 0.1 fps
  vertical_flip: true
  horizontal_mirror: false


uart:
  -  id: uart01
     rx_pin: $ld_rx_pin
     tx_pin: $ld_tx_pin
     baud_rate: 256000
     parity: NONE
     stop_bits: 1
  -  id: uart02
     tx_pin: $df_tx_pin
     rx_pin: $df_rx_pin
     baud_rate: 9600
     parity: NONE
     stop_bits: 1

#dfplayer:
#   uart_id: uart02
#   on_finished_playback:
#    then:
#     logger.log: 'Playback finished'

ld2410:
  uart_id: uart01
  timeout: 10s
  max_move_distance : 6m
  max_still_distance: 6m
  g0_move_threshold: 50
  g0_still_threshold: 20
  g1_move_threshold: 50
  g1_still_threshold: 20
  g2_move_threshold: 40
  g2_still_threshold: 20
  g3_move_threshold: 30
  g3_still_threshold: 20
  g4_move_threshold: 30
  g4_still_threshold: 20
  g5_move_threshold: 20
  g5_still_threshold: 20
  g6_move_threshold: 20
  g6_still_threshold: 20
  g7_move_threshold: 40
  g7_still_threshold: 30
  g8_move_threshold: 40
  g8_still_threshold: 30
 
binary_sensor:
  - platform: status
    name: $hostname status
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving target
    has_still_target:
      name: Still target
  - platform: gpio
    pin:
      number: $buttonpin
      mode: INPUT_PULLUP
      inverted: True
    name: $buttonname
    on_press:
      then:
        #- dfplayer.play:
        #    file: 5
        - light.turn_off: $flashlight
        - delay: 0.10s
        - light.turn_on: $flashlight
        - delay: 0.10s
        - light.turn_off: $flashlight
        - delay: 0.10s
        - light.turn_on: $flashlight

   - platform: gpio
    pin:
      number: $buttonpin2
      mode: INPUT_PULLUP
      inverted: True
    name: $buttonname2
    on_press:
      then:
        #- dfplayer.play:
        #    file: 6
        - light.turn_off: $flashlight
        - delay: 0.10s
        - light.turn_on: $flashlight
        - delay: 0.10s
        - light.turn_off: $flashlight
        - delay: 0.10s
        - light.turn_on: $flashlight
 
sensor:
  - platform: wifi_signal
    name: $hostname WiFi Signal
    update_interval: 600s
  - platform:  internal_temperature
    name: $hostname Internal Temperature
    update_interval: 600s

switch:      
  - platform: restart
    name: $hostname restart
    id: restart_switch

output:
 #flashlight
  - platform: gpio
    pin: 
      number: $flashlightpin
      #inverted: True
    id: gpio_4
 #statuslight
  - platform: gpio
    pin:
      number: $statuslightpin
      inverted: True
    id: gpio_33

light:
 #flashlight
  - platform: binary
    output: gpio_4
    name: $hostname flash
    id: $flashlight


#=========================== AUTORESTART 2 AM =================================
time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 0
        hours: 2
        days_of_week: MON-SUN
        then:
           - switch.toggle: restart_switch
 

and this is the log when DfPlayer is active:

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[I][logger:262]: Log initialized
[C][ota:469]: There have been 5 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[C][uart.arduino_esp32:077]: Setting up UART...
[C][uart.arduino_esp32:077]: Setting up UART...
[D][binary_sensor:034]: 'doorbell_button_gg': Sending initial state OFF
[D][binary_sensor:034]: 'doorbell_button_da': Sending initial state OFF
[C][light:035]: Setting up light 'doorbell flash'...
[D][light:036]: 'doorbell flash' Setting:
[D][light:041]:   Color mode: 
[C][light:035]: Setting up light 'doorbell status light'...
[D][light:036]: 'doorbell status light' Setting:
[D][light:041]:   Color mode: 
[D][esp-idf:000]: E (582) camera: Camera probe failed with error 0x105(ESP_ERR_NOT_FOUND)

[E][esp32_camera:024]: esp_camera_init failed: ESP_ERR_NOT_FOUND
[E][component:113]: Component esp32_camera was marked as failed.
[C][ld2410:033]: Setting up LD2410...
[C][ld2410:049]: Firmware Version : 0.0.0000
[C][ld2410:050]: LD2410 setup complete.
[D][binary_sensor:034]: 'doorbell status': Sending initial state OFF
[C][wifi:038]: Setting up WiFi...
[C][wifi:048]: Starting WiFi...
[C][wifi:049]:   Local MAC: E8:DB:84:12:7C:C8
[D][wifi:425]: Starting scan...
[D][sensor:094]: 'doorbell Internal Temperature': Sending state 23.33333 °C with 1 decimals of accuracy
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
[E][uart:015]: Reading from UART timed out at byte 4289593344!
E (13151) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (13151) task_wdt:  - loopTask (CPU 1)
E (13151) task_wdt: Tasks currently running:
E (13151) task_wdt: CPU 0: IDLE
E (13151) task_wdt: CPU 1: loopTask
E (13151) task_wdt: Aborting.

abort() was called at PC 0x400f5234 on core 0


Backtrace:0x40083a49:0x3ffbe9cc |<-CORRUPTED




ELF file SHA256: 0000000000000000

Rebooting...

What about the (free) heap memory?

You might also want to move your thread into the (correct) esphome category :wink:

1 Like

ESP32CAM uses non-standard interrupt mapping and handling, making it incompatible with other ESPhome modules.

ESPHome components? Not sure if this is accurate. While having the cam activated and with “higher” quality it puts quite a stress on the system already - but by lowering the quality just a bit I were able to attach I2C sensors in the past and having the camera working normally at the same time.

Got any links for in-depth reading about this by any chance?

I use the OV5640 who has a resolution of 2560x1920 (a 5v fan is rrquired, it became really hot!).
At 0.1 fps works well with also The DFPlayer UART attached.

I’ve tried at lower resolutions (640x480), disabling the serial logging and with fps at 0.01
No chances to have it working with cam, dfplayer and ld2410.

I’m a nerd, but remain a noob in some things. Maybe someone has more experience.

Thanks.

Apologies, but no, I don’t. :frowning: I was investigating this a few months ago, attempting to enable more flexibility, adding features to ESP32Cam devices. Looked into the ESP32Cam source code, found the special (i.e., “different”) handling and management of ESP32 interrupts. Would have been required to IFDEF every single reference in other modules to work. Just not worth the trouble.

Hmm ok thanks, so i’ll use it by its output pin.