I²S Audio Component with ESP32-S2

I’m trying to figure out the I²S Audio with ESP32-S2. I’m using Wemos S2 mini board.

I assume that there is something with the pins I’ve tried. Currently my non-working config looks like this:

esphome:
  name: esp-audio

esp32:
  board: esp32-s2-saola-1
  framework:
    type: arduino

#... api, ota wifi, etc

i2s_audio:
  i2s_lrclk_pin: GPIO33
  i2s_bclk_pin: GPIO35

media_player:
  - platform: i2s_audio
    name: ESPHome I2S Media Player
    dac_type: external
    i2s_dout_pin: GPIO37
    mode: mono

I read somewhere that on esp32-s2 it needs pull up resistors for i2s SDA and SCL. I have tried 4.7K resistors with GPIO33 and GPIO35 but with no luck.

Has someone used audio with esp32-s2 or does anyone have any advices?

SDA/SCL are for I²C, which basically has no relation to I²S
What amplifier are you using and how did you wire it?

MAX98357A
LRC > i2s_lrclk_pin: GPIO33
BCLK > i2s_bclk_pin: GPIO35
DIN > i2s_dout_pin: GPIO37

I don’t see anything obvious.
Here is my similar working setup, with a MAX98357A and a INMP441 microphone. I’m using 5V for the MAX, but it shouldn’t matter according to the specs.

substitutions:
  device_name: espassist

###########################################

esphome:
  name: "${device_name}"
  friendly_name: ESP32 Assistant

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: arduino

external_components:
  source:
    type: local
    path: custom_components

packages:
  base: !include common/base_nomq.yaml

logger:
#  level: VERBOSE

switch:
  - platform: restart
    name: "Restart"

light:
  - platform: status_led
    name: "Status led"
    pin: GPIO2

sensor:
  - platform: template
    id: esp_memory
    icon: mdi:memory
    name: Free Memory
    lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
    unit_of_measurement: 'kB'
    state_class: measurement
    entity_category: "diagnostic"
  - platform: template
    id: sys_esp_temperature
    name: Internal Temperature
    lambda: return temperatureRead();
    unit_of_measurement: °C
    device_class: TEMPERATURE
    entity_category: "diagnostic"
  - platform: uptime
    name: Uptime
    id: sys_uptime
  - platform: wifi_signal 
    name: RSSI
    id: wifi_signal_db
    entity_category: "diagnostic"

###########################################

i2s_audio:
  - id: i2s_out
    i2s_lrclk_pin: GPIO26
    i2s_bclk_pin: GPIO27
  - id: i2s_in
    i2s_lrclk_pin: GPIO19
    i2s_bclk_pin: GPIO18


media_player:
  - platform: i2s_audio
    id: media_out
    name: Media Player
    dac_type: external
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO14
    mode: mono

microphone:
  - platform: i2s_audio
    adc_type: external
    pdm: false
    id: mic_i2s
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO23

voice_assistant:
  microphone: mic_i2s

binary_sensor:    
  - platform: status
    name: Status
  - platform: gpio
    pin: 
      number: GPIO00
      inverted: true
      mode:
        input: true
        pullup: true
    name: Boot Switch
    internal: true
    on_press:
      - voice_assistant.start:
    on_release:
      - voice_assistant.stop:

Note that I’m using a branch of esphome (GitHub - esphome/esphome at jesserockz-2023-180) for supporting the microphone, but it shouldn’t matter for the media player

5 Likes

Yeah, I don’t have any “real” esp32’s laying around that I could test if the issue is with esp32-s2.

I can see this device in HA and can try to play audio through it but it just says immediately that it became unavailable and then changes to idle.

Logging the device freezes after audio. I assume that it should have some info after that…

[07:57:26][C][captive_portal:088]: Captive Portal:
[07:57:26][C][mdns:108]: mDNS:
[07:57:26][C][mdns:109]:   Hostname: esp-audio
[07:57:26][C][ota:093]: Over-The-Air Updates:
[07:57:26][C][ota:094]:   Address: esp-audio.local:3232
[07:57:26][C][ota:097]:   Using Password.
[07:57:26][C][api:138]: API Server:
[07:57:26][C][api:139]:   Address: esp-audio.local:6053
[07:57:26][C][api:141]:   Using noise encryption: YES
[07:57:26][C][audio:190]: Audio:

It depends what you configured.

For me, it just starts logging sensor values, but if you have none…

[08:57:37][C][mdns:108]: mDNS:
[08:57:37][C][mdns:109]:   Hostname: espassist
[08:57:37][C][ota:093]: Over-The-Air Updates:
[08:57:37][C][ota:094]:   Address: espassist.local:3232
[08:57:37][C][ota:097]:   Using Password.
[08:57:37][C][api:138]: API Server:
[08:57:37][C][api:139]:   Address: espassist.local:6053
[08:57:37][C][api:141]:   Using noise encryption: YES
[08:57:37][C][wifi_signal.sensor:009]: WiFi Signal 'RSSI'
[08:57:37][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[08:57:37][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[08:57:37][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[08:57:37][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[08:57:37][C][audio:190]: Audio:
[08:57:46][D][sensor:103]: 'Uptime': Sending state 31.44700 s with 0 decimals of accuracy
[08:57:49][D][sensor:103]: 'Free Memory': Sending state 226.00000 kB with 1 decimals of accuracy
[08:57:55][D][sensor:103]: 'Internal Temperature': Sending state 53.33333 °C with 1 decimals of accuracy

Good day to all of you. I’m working on project for ceiling wifi speakers and yesterday tried to use WEMOS or LOLIN ESP32-S2 mını along with MAX98357A I2S board hooked up to pins 8,9,10.
First issue I’m facing - complete ınability to flash ESP board through ESPHome, it just kept saying that error, try to reset or hit programming button or so. I thought maybe the problem is with ESP32 board, used second one and got the same issue.
Then I have tried to flash board using Arduıno IDE and it worked by setting board to programming mode. Then tried again using ESPHome page in HA - no success.
Then I have created firmware using offline method in ESPHome page
Used ESP Flasher program for Windows and flashed the board with ESPHome firmware.
Now thing is either Im using too thin wires or something else, but when I try to play something on the speaker (16Ohms Speaker) Music or Radio or text to speech plays intermittent and sometimes does not play at all.
I Looked in logs and while attempting to play mp3, board keeps reconnecting resetting itself, While streaming radio - no probs, but sound is intermittent. Text to Speach does not work at all despite player says that it’s playing.
I will check voltage drop today, maybe I have used very thin wires and that is the reason for power shortage.
Other device I have tried is ESP32 DEVKIT hooked to I2S using development wires and it is hooked to 4Ohm speaker and works just fine.
After using ESP Flasher to flash initial firmware, updating firmware wirelessly works. However on second board refuses to connect to my home wifi and is offline. This could be problems relating to consistency in board to board manufacturing quality, not sure yet. Anyways I have ordered couple other dev boards ESP32s, just to complete the project. Or maybe code for this board is not perfected by developers, as it has so many difficulties flashing and bad sound, not sure.

Any suggestion or help will be much appreciated.

The MAX delivers 3W at 4 ohms.

Hello. It looks like me too. Does not work and freezes from time to time. Have you resolved the issue?

yes, moved to ESP32, regular one, S2 is shait!

1 Like

@koying I’m setting up the a vintage phone with the same mic and amp but I’m getting problems with the wiring and connecting to the the esp
Do you have the pinout or wiring schema?

Also, where can I find these files that your code. Includes?

external_components:
  source:
    type: local
    path: custom_components

packages:
  base: !include common/base_nomq.ya

I would strongly suggest avoiding the new esp32 c2 and others unless you actually need one or more of its unique characteristics that the tried and true esp32 d2 mini can’t offer. People assume when things are newer, then they must be better and that isn’t the case at all here. It’s better suited for some tasks but isn’t always a better alternative over an older esp32 and in some cases your worse off. Use the board that is best suited for the project and one that is fully supported in esphome as the S2 is still in development and not fully supported yet.

You have the code and a photo, I’m not going to do a fritzing, honestly :wink:
The include is just common stuff (wifi, api, …) and the custom_components is irrelevant for this project

I’ve manged to get it all working but when plugged on and off I have to press the EN button (reset?) for it boot and connect, is there any to avoid this behaviour?

also, I can’t seem to use a momentary to start/stop assist conversation

binary_sensor:    
  - platform: status
    name: Status
  - platform: gpio
    pin: 
      number: GPIO02
      inverted: true
    name: Boot Switch
    on_press:
      - voice_assistant.start:
    on_release:
      - voice_assistant.stop:

but If I use GPIO00 like your example It’s works using the boot button, any guess?
thanks

GPIO02 is probably not a great choice.
Try with one of those:

GPIO Input Output Notes
16 OK OK
17 OK OK
18 OK OK
19 OK OK
21 OK OK
22 OK OK
23 OK OK
25 OK OK
26 OK OK
27 OK OK
32 OK OK
33 OK OK
1 Like

@koying, did you need to define two separate i²s audio devices one for speakers and one for microphone? I’m wondering if you could just define a single i2s_audio device and use it for both speakers and mic… does that cause problems?

Thanks for sharing your setup and YAML! I had ordered a bunch of MSM261S4030H0 i2s microphones from AliExpress but I’ve been really struggling to get them to work – no audio. I just ordered some of the INMP441s you had success with and I have my fingers crossed that these are much easier to get working… :wink:

@koying I only just realized that you got that INMP441 working with a hacked version of ESPHome that is no longer available. :frowning:

I’m wondering if there is going to be support for this microphone in ESPHome, officially?

IIRC, I just followed the easy route rather than adding bus issues to the equation.

IIRC, that has been added to ESPHome proper, since.

I got it working finally. Turned out that the microphone I was using was actually bad.

:tada:

Why are you using an external DAC? esp32 internal DAC does not have enough quality? can I just use an analog amplifier connected to the speaker?