Dfplayer connected to esp32-cam

Hope someone can help me. I have an esp32-cam connected to home assistant. I want to connect a dfplayer mini to the esp32-cam module. My question is - which pins can I use for the uart tx connection? I can’t get my yaml file below to work, so can only think I have used the wrong pin to send commands to the dfplayer. I know it plays the mp3 file by manually triggering it. My yaml code is

api:
  reboot_timeout: 0s
ota:

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO15, 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.doorbell
# DFplayer configs
uart:
  tx_pin: GPIO15
  baud_rate: 9600
  
  on_press:
    then:
      - dfplayer.set_volume: 25
      - delay: 150ms
      - dfplayer.play: 1
      - switch.turn_on: led1

I have working dfplayer on esp8266
Without any doubt Rx should be connected too.

UART RX IO TX IO CTS RTS
UART0 GPIO3 GPIO1 N/A N/A
UART1 GPIO9 GPIO10 GPIO6 GPIO11
UART2 GPIO16 GPIO17 GPIO8 GPIO7

Hi. I think the problem is that my esp32-cam doesn’t have the other uart Tx/RX pins. It looks like an AI-THINKER board and I can’t see that other uart connections are available. I guess I can’t use the UART0 connections?

Got it working !!! It seems I need to use GPIO pins 0 and 16, even though I can’t find 16 being specified as a UART connection on any schematics.

Thanks alot for your help IgorZg.

I would try to use two free pins, because they said:
“Whenever possible, ESPHome will use the hardware UART unit on the processor for fast and accurate communication. When the hardware UARTs are all occupied, ESPHome will fall back to a software implementation that may not be accurate at higher baud rates.”

9600 baud is not very high so that can work.

Thanks for help so far. The final bit now. I have configured buttons on my ios device, they show fine. However, I don’t understand how to get them to trigger playing the dfplayer mp3 file. I have tried to follow ron schaeffer’s github post but I must be doing something wrong. Can someone explain what I need to add to the automations.yaml file to then trigger the dfplayer device through my esp32.

There are several ways to play something on dfplayer, here is what I did.
On dfplayer SD (which must be formated FAT32) I have folder named mp3.
In it, I have several mp3 files named like this:
001-this_is_first.mp3
002-this_is_second.mp3
003-this_is_third.mp3
and so far.
Then, in automations and scripts I call:

service: esphome.soundmachine_dfplayer_play
data:
  file: 1

I wired dplayer pin busy back to esp and configured this pin as binary sensor:

binary_sensor:
  # Expose MP3busy status
  - platform: gpio
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
      inverted: True
    name: "mp3busy"
  # Expose status
  - platform: status
    name: "Sound machine status"

so my automations can know when playing is finished. Here you can see status binary sensor too, so HA can check is esphome online.

Finally, here is my script which I use as ‘play queue’:

alias: sm_mp3_play
sequence:
  - wait_template: '{{ is_state(''binary_sensor.mp3busy'', ''off'') }}'
    timeout: '100'
    continue_on_timeout: true
  - service: esphome.soundmachine_dfplayer_play
    data:
      file: '{{ file }}'
  - wait_template: '{{ is_state(''binary_sensor.mp3busy'', ''on'') }}'
    timeout: '100'
    continue_on_timeout: true
mode: queued
max: 80

Thanks for your help. I have now got the dfplayer rersponding to a service call from the developer tools by specifying file: ‘2’ to play file 2.
However, I am still doing something wrong as pressing the button on the iphone does nothing. If I look in the iphone at the notification settings and the example trigger the action_data just specifies a comment - should that be defined? If so, how?
My automations.yaml is

- id: '1613553775102'
  alias: Doorbell Automation
  description: ''
  trigger:
  - type: turned_on
    platform: device
    device_id: 199fdbc24a59a8aadfb386b6a8b455f0
    entity_id: binary_sensor.doorbell_button
    domain: binary_sensor
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: LEAVE_PARCEL
      event_type: mobile_app_notification_action
      data:
        file: '2'
      service: esphome.esp32_1_dfplayer_play
  condition: []
  action:
  - service: notify.mobile_app_jims_phone
    data:
      title: Knock Knock
      message: Doorbell pressed at {{ as_timestamp(now()) | timestamp_custom('%-H:%M',
        true) }}
      data:
        attachment:
          content_type: jpeg
        push:
          category: camera
        entity_id: camera.doorbell
        sound: US-EN-Morgan-Freeman-Someone-Is-Arriving.wav
  mode: single

And my configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
ios:
    push:
        categories:
        -   name: cameras
            identifier: 'camera'
            actions:
            -   identifier: 'LEAVE_PARCEL'
                title: 'Please leave the parcel'
                activationMode: 'background'
                authenticationRequired: true

Maybe to call mp3 player service from action section like this:

- id: '1613553775102'
  alias: Doorbell Automation
  description: ''
  trigger:
  - type: turned_on
    platform: device
    device_id: 199fdbc24a59a8aadfb386b6a8b455f0
    entity_id: binary_sensor.doorbell_button
    domain: binary_sensor
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: LEAVE_PARCEL
      event_type: mobile_app_notification_action
  condition: []
  action:
  - service: notify.mobile_app_jims_phone
    data:
      title: Knock Knock
      message: Doorbell pressed at {{ as_timestamp(now()) | timestamp_custom('%-H:%M',
        true) }}
      data:
        attachment:
          content_type: jpeg
        push:
          category: camera
        entity_id: camera.doorbell
        sound: US-EN-Morgan-Freeman-Someone-Is-Arriving.wav
    - service: esphome.esp32_1_dfplayer_play
      data:
        file: '2'
  mode: single