ESP32 connecting speaker with Max98357

Hi all,

After viewing some posts and videos, i want to connect a simple speaker to ESP32 dev board using the
Max98357 DAC amplifier

The configuration builds and setup the esp32 as expected with audio media player device created for the esp
but i cant hear anything i try to play (some sample MP3 files from the internet)

Here is my yaml config, i removed non- relevant stuff

esphome:
  name: esp32-speaker
  friendly_name: esp32-speaker

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "###"

ota:
  - platform: esphome
    password: "###"

wifi:
  ssid: # !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.0.29
    gateway: 192.168.0.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ESP"
    password: "###"

captive_portal:

web_server:
  port: 80

i2s_audio:
  i2s_lrclk_pin: GPIO21
  i2s_bclk_pin: GPIO18

media_player:
  - platform: i2s_audio
    name: "ESP32 Audio Player"
    dac_type: external
    i2s_dout_pin: GPIO19
    mode: mono
    id: media_out

when i try to play the media file via dev tools HA page (see pic)

it seems the device is getting the file but no sound

log from esp32 console:

|10:58:25|[D]|[media_player:061]|'ESP32 Audio Player' - Setting|
| --- | --- | --- | --- |
|10:58:25|[D]|[media_player:068]|Media URL: https://file-examples.com/storage/fe00d37cde6728af4966ebc/2017/11/file_example_MP3_700KB.mp3|
|10:58:25|[W]|[component:237]|Component i2s_audio.media_player took a long time for an operation (529 ms).|
|10:58:25|[W]|[component:238]|Components should block for at most 30 ms.|
|10:58:26|[W]|[component:237]|Component i2s_audio.media_player took a long time for an operation (486 ms).|
|10:58:26|[W]|[component:238]|Components should block for at most 30 ms.|

when i play same file on my google nest (via same HA dev tools page target is ) it plays ok as expected

I attach a photo of the setup

esp32 runs on 5V USB
5V/GND connect to DAC chip
3 connections from esp32 to DAC as in yaml
GPIO19 → DIN
GPIO18 → LRC
GPIO21 → BCLK

4 ohms speaker connected to speaker temrinal outputs of DAC

the remaining 2 connections (GAIN, SD) on the DAC are left unconnected

any idea what im doing wrong? or what to test maybe electrically on the DAC pins / speaker terminals to know if its working or not?

Did you resolve this?

Could most likely be easily resolved if people used the Esphome documentation and looked through historical forum posts that are identical to the OP but, nobody likes having to try and its much easier to have someone else fix it from the tech support on-demand HA forums…

whats your point?
i connected this according to what i saw in this forum and others and according to documentation of the esp32 and the amplifier module
yet it still does not work
im asking for any troublshooting tips to understand why its not working

try with GAIN on GND

Thank you for your reply
I tried it it didn’t help
I tested the speaker itself on different project and it worked so I suspect my DAC amplifier module got damaged somehow in my experiments
I ordered a new one and will try it out

It happen. Did you try other pin. I have the same board and i use:
LRCLK:GPIO15
BCLK:GPIO14
Dout:GPIO25

try something like this

substitutions:
  i2s_lrclk: GPIO06 #
  i2s_bclk: GPIO05  #
  spk: GPIO07 #


i2s_audio:
  - id: i2s_output
    i2s_lrclk_pin: 
      number: ${i2s_lrclk}
    i2s_bclk_pin:  
      number: ${i2s_bclk}

speaker:
  # Hardware speaker output
  - platform: i2s_audio
    id: i2s_audio_speaker
    i2s_audio_id: i2s_output
    dac_type: external
    i2s_dout_pin:   
      number: ${spk}
    sample_rate: 48000
    buffer_duration: 100ms

  # Virtual speakers to combine the announcement and media streams together into one output
  - platform: mixer
    id: mixing_speaker
    output_speaker: i2s_audio_speaker
    num_channels: 2
    source_speakers:
      - id: announcement_mixing_input
        timeout: never
      - id: media_mixing_input
        timeout: never

  # Vritual speakers to resample each pipelines' audio, if necessary, as the mixer speaker requires the same sample rate
  - platform: resampler
    id: media_resampling_speaker
    output_speaker: media_mixing_input
    sample_rate: 48000
    bits_per_sample: 16

media_player:
  - platform: speaker
    id: external_media_player
    name: None
    internal: False
    volume_min: 0.4
    volume_max: 0.85
    volume_increment: 0.15
    media_pipeline:
      speaker: media_resampling_speaker
      format: FLAC     # FLAC is the least processor intensive codec
      num_channels: 2
      sample_rate: 48000



1 Like

i was able to make it work thanks all!

i replace the Max98357 unit

i used ths config (arduino framework)

substitutions:
  i2s_lrclk: GPIO26 # LRC Pin of the Max98357 
  i2s_bclk: GPIO25  # BCLK Pin of the Max98357
  spk: GPIO27 # DIN Pin of the Max98357

i2s_audio:
  - id: i2s_in
    i2s_lrclk_pin: ${i2s_lrclk} # LRC Pin of the Max98357 
    i2s_bclk_pin: ${i2s_bclk} # BCLK Pin of the Max98357

media_player:
  - platform: i2s_audio
    name: "esp_speaker"
    id: media_player_speaker
    i2s_audio_id: i2s_in
    dac_type: external
    i2s_dout_pin: ${spk}   #  DIN Pin of the MAX98357A Audio Amplifier
    mode: mono
    on_play:
      - logger.log: "Media playing!"
      - media_player.volume_set:
          id: media_player_speaker 
          volume: 100% 

1 Like

Thank you, this also got audio working for me using a I2S Audio Amplifier MAX98357A Shield – Lonely Binary