I2S ESP32 Stereo output two MAX98357A

Hi there, I’m trying to get two MAX98357A boards to work in stereo mode using latest ESPHome on ESP32 (devkit1). However regardless of using stereo mode argument in the code, sound from both speakers work in mono regime.

status_led:
  pin:
    number: GPIO2
    inverted: true

i2s_audio:
  - id: i2s_out
    i2s_lrclk_pin: GPIO14
    i2s_bclk_pin: GPIO27
  - id: i2s_in
    i2s_lrclk_pin: GPIO13
    i2s_bclk_pin: GPIO12

media_player:
  - platform: i2s_audio
    name: ESPHome I2S Media Player
    dac_type: external
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO25
    mode: stereo

    
# Example configuration entry
microphone:
  - platform: i2s_audio
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO26
    adc_type: external
    id: mic_i2s
    pdm: false

voice_assistant:
  microphone: mic_i2s

I have used the following diagram to hook DAC modules (mine hooked to different pins):

Can someone holp to sort this out?

I don’t know much if anything about these boards so I could be very wrong. :slight_smile:

But the wiring diagram shows both amp boards wired to exactly the same signal. Do you not have to toggle a pin on the board for left or right channel?

there is no such a code in ESPHome to separate left and right channels with external DAC unfortunatelly. Stereo signal carry signal separation so LRCLK can understand which channel it should decode and play.
As far as I understood, the problem might be with ESPHome itself. I might be wrong.

UPDATE: Figured out stereo output. Problem was in MAX98357A configuration. By default it is configured to mix outputs using 1M resistor (to VDD) so to configure it to left and right channels, SD needs to be pulled-up to VDD with jumper (0 Ohms) that is going to be LEFT channel and with 370-470K resistor to VDD to output Right channel.
All perfect now.
By the way I get really nice sound quality despite this is only class D amplifier.

and here is my little project printed for stereo WiFi player ))

and here is my code:

captive_portal:

status_led:
  pin:
    number: GPIO2
    inverted: true

i2s_audio:
  - id: i2s_out
    i2s_lrclk_pin: GPIO14 
    i2s_bclk_pin: GPIO27
  - id: i2s_in
    i2s_lrclk_pin: GPIO32 #ws
    i2s_bclk_pin: GPIO33 #sck

# LR to be grounded

media_player:
  - platform: i2s_audio
    name: ESPHome I2S Media Player
    dac_type: external
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO25
    mode: stereo

    
# Example configuration entry
microphone:
  - platform: i2s_audio
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO26 #sd
    adc_type: external
    id: mic_i2s
    pdm: false

voice_assistant:
  microphone: mic_i2s
5 Likes

Would you be kind enough to share the connection diagram of the components of your I2S ESP Stereo… Thank you!

@elik745i those speakers look massive… Is the amp able to drive them nicely?
What are the specs of the speakers?

1 Like

I am also curious about those speakers.
Can you post ohms and watts?

Those were for testing purpose only! For sure to drive those you would need AMP

Great work! Would you be kind enough to share the connection diagram of the components of your I2S ESP Stereo… Thank you!

Are you using the board mentioned here. I am trying to implement something similar with esp.

The connection between DAC and esp32 chip is as given below. Please refer to my other post where I have used different DAC but the result is same. I am getting the stereo quality output.

esp32 --------- UDA1334A
VIN ------------- VIN
GND ----------- GND
GPIO25 ------- DIN
GPIO26 ------- WSEL
GPIO27 ------- BCLK

1 Like

Thank you!

Did you find a way to set the volume via I2S (i.e., via software or config)?