ESP32, ESPHOME and MediaPlayer mostly not playing

Hi there,

So I feel I have exhausted all options on making a ESP32 Wroom-32 board working as a stable Music Player with external DAC Max98357 I2S. It will only play right after I either reset it or unplug it. It can play MP3 locally, streams from radios, and TTS, but only a few times before it has to be reset or just decides to randomly work. I have tried various pinouts, various boards in config and various framework versions. It will still only play a few things if at all, and when stopping it, I need to do a full reset before anything will work again. Is there something wrong with the ESP Wroom-32.
There is very little information on this, both posted here and on the net in general. Like what is a safe board to use, what is a stable config or is using ESPs as media players not really a thing?
When “playing” the log will say that it is playing this and that URL, but there is simply no audio. Maybe its the DAC, but I have made two boards like this with the same DAC and the same ESP. Both are behaving the same. The speakers I use are both 4ohm and 3W, and gain has been both floating and tied to gnd. I just wish it could behave stable since I have a lot of usecases for this. What is peoples experience with ESP32 as Media Players, and what combinations are workig stable?
I have ordered a new type of DACs and ESP Wrover boards that may or may not be better suited for this. BTW. All connections are soldered on.

Thank you for any insights.

  name: "leon-media-esp"
  friendly_name: Leon Media

esp32:

  board: upesy_wroom
  framework:
    type: arduino
    version: latest

 

# Enable logging

logger:

# Enable Home Assistant API

api:

  encryption:
    key: "xx"

web_server:

  port: 80

  auth:
    username: 'xx'
    password: 'xx'

ota:

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Exx8"
    password: "xx"

captive_portal:

i2c:

i2s_audio:
  - id: i2s_out
    i2s_lrclk_pin: 26
    i2s_bclk_pin: 27

media_player:

  - platform: i2s_audio
    name: Leon Player
    dac_type: external
    i2s_audio_id: i2s_out

    i2s_dout_pin: 14

    mode: mono
    on_pause:
      - media_player.stop

button:

  # Restart the ESP
  - platform: restart
    name: "Restart"

Didn’t try this out myself yet, but just a few thoughts for narrowing things down:

  • power supply big enough?
  • pins 25 and 26 are connected to the internal DAC of the esp32, you are using 26 and 27, maybe the overlap of the 26 pin sometimes creates a hickup? => try to switch 26 to 23 e.g.
  • can you try the same hardware setup with pure arduino code instead? I had experiences in the past where peripherals worked better with arduino code, while the esphome implementation was buggy

Yes, power-supply is ok. On a logger it uses maximum 150 mA @ 5V
I will try using other pins, and I did think about the possibility, but seems like most example-code out there is using these pins.
I am not very well versed in normal Arduino-code, and I am not sure how to set it up to work in HA. I have dumpet the bin-files and tried to flash using ESPhome-Flasher, but both modern and legacy files turned made errors and made it boot-loop. But I was able to use the same files in Web-flasher tool somehow with no problems. I was hoping that a cabled flash would maybe be better. Really not sure what I should aim for in Arduino-code. I guess being able to play streams and mp3 over internet reliable will rule out hardware issues between ESP32 and the external DAC?

Could it be the default power saving, not specified in your code?
Try setting it to none.

Really? That actually seem to do the trick, and it makes sense since the Wroom is especially built to be low-power, which also explains the low wifi-signal it had. I have now reverted to recommended repository for the Arduino-code, because ESPHome seemed to crash in the background when using these two boards with “latest” code. At least it is working much better now, but daring to say it was a fix is scary since I might jinx it. Now I am able to switch between Radio, Local Files and TTS for more than 30 minutes. In case it works: A big thank you for your intuition and knowledge. And also for all other suggestions. I was away all day, so didn’t have the time to test much.

2 Likes

can you plz share your pins setup. I am trying to do the same. But some streams are not playing

If just some streams are not play may due to the sample rate.
I’m facing the same issue as it will not play anything after idle for not sure how long.
Once restart it, it can play again.
Tring to add wifi power save mode to none. See if that helps.

I am curious. What kind of bitrate and samplerate are you able to achieve from an ESP32/wDAC? Is it able to play back 24/96 streams? Maybe I have been spending a bit more money on Raspberry Pis with HD-Audio hats (fully integrated in HA via Volumio). Can I can do the same with a $5 ESP32 + DAC. I cannot imagine the quality would be the same however. The Rpi has way more horsepower. Am I wrong?

Yes, the quality is very high. You relly don’t need alot horsepower to decode MP3. I use both use at least 160 kbps, without any issues.

I bet it didn’t help anything. at least it didnt for me. I am still stuck with this. Now using Wrover and enable PSRAM. Still same shit.

That was not the trick. Still the same.

I was more curious about its ability to decode 24/96 FLAC files. This is the format I use to record my huge vinyl LP collection. With a few exceptions, I stopped using mp3s years ago.

Greetings. I am also now realizing my first experiment with esp32, using this instruction My Local Voice Assistant Device With Wake Word In Home Assistant | Smart Home Circle.
I have repeated the circuitry in full accordance with his schematic. According to the principle - if everything works for him, why to be clever and change something. I don’t have anything related to tts yet (I have core version and it’s not so easy to install it all on it), but the functions of media player and beautiful colored lights work successfully. Of course, as always, with some peculiarities.
I also noticed a few times that my smart speaker would freeze up, but that wasn’t the main problem. I couldn’t run music or activate any dynamic program of blinking LEDs, as it caused crackling and interference in the sound. I tried to analyze settings, timings, power supply, to figure out what I was doing wrong. But it turned out to be a matter of circuitry, and I think it affects a lot of things in operation. I have the microphone and amplifier boards soldered with rather short wires, no more than 5 centimeters. But when I moved them and touched them with my hands, these sound distortions disappeared. I came to the point where I soldered an additional wire to the “ground” (minus power supply) and wrapped the signal wires with it, making something like a twisted pair or shielding.
The interference is gone!
What I’m getting at. I had a thought that unstable esp32 operation may be caused by the fact that this interference not only affects the sound, but also the processor itself, leading to failures. I think you should use as short wires as possible, possibly shielded, and generally do the mounting inside the device case taking into account the effects of electromagnetic fields, which will eventually improve wifi radio reception as well.
In the near future I am planning to build a second speaker (in a different cabinet, I use factory satellite speakers from an old home theater), and I will try to take into account the experience in the circuitry. I will try to write about the results, how much it will affect the stability of operation.

2 Likes

Interference is no joke. I banged my head for several days teying to rid my speaker of static and crackling too.
I have been trying to build a new smart speaker that uses esp32 with an amplifier and then also share the amplifier with one of those BT audio receiver’s. This way i could TTS or do announcements from HA but, anyone could pair to the speaker with their phone and use it to play music.

I can use either DAC or BT just fine but, when i put wire them both to the amp I get static and interference!!

Its an annoying problem.

I think a good result would be to use old ide or fdd cables, where each data wire alternates with ground. Or for example, how the cables from motherboard to monitor are arranged in laptops, where shielded twisted pair is used. I think any of us has some old and no longer needed computer hardware, tablets, TVs, etc., which can be used for homemade products. All this breadboard assembly on wires, which is used for arduino DIY, is suitable only for preliminary performance testing and can not be used in working devices. Sometimes this is a serious problem for computer and electronics manufacturers, when they have to change the shape of wires on the PCB to avoid interference and malfunction, and we used to not think about it.
Here, it’s good time to think how to make a good stable working device :slight_smile:

An important note. I have found that many radio stations from the media - radio browser cause esp-speaker to hang or reboot when trying to start a stream. This is because there are different streams mixed in there, but not all the speaker can play (e.g. aac). The same applies to local files, apparently not all mp3 bitrates are played correctly (high bitrate mp3 and flac). Some just won’t play, some will cause speaker to crash:

WARNING speaker-1 @ 192.168.0.228: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for speaker-1 @ 192.168.0.228
WARNING Disconnected from API
INFO Successfully connected to speaker-1 @ 192.168.0.228 in 0.005s
INFO Successful handshake with speaker-1 @ 192.168.0.228 in 2.184s
[21:05:41][D][media_player:059]: 'esp_speaker' - Setting
[21:05:41][D][media_player:069]:   Volume: 0.48
[21:05:41][D][light:036]: 'Light' Setting:
[21:05:41][D][light:051]:   Brightness: 50%
[21:05:41][D][light:059]:   Red: 100%, Green: 0%, Blue: 100%
[21:09:57][I][ota:117]: Boot seems successful, resetting boot loop counter.
[21:09:57][D][esp32.preferences:114]: Saving 1 preferences to flash...
[21:09:57][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

Now I’ve selected a few tested streams for myself, and the speaker has been working stably without hangs and crashes for the last two days, playing music and some tts during scripted events.
So it looks like the software part itself is working steady, except for the limitations of the capabilities of the esp32 board itself. It’s just something to keep in mind when working with it.

For newbies like me, or those who just haven’t looked into it, let me explain. HomeAssistant does not create an audio stream, it only passes the address of the stream from outside to the speaker, or creates a link to the media file to be played. The same applies to voice assistant messages and other tts events. They are rendering to an audio file, which is saving locally, and then a link to it is passing to the speaker and it plays it. If it can. We can only see the status, like “playing” or “idle”. Unfortunately this is all the available feedback on the status of the speaker at the moment.

I am having the same problem and tried with different pinout. Always the result is the same: starts working but after several minutes or seconds (random) stops working. Then I have to reset it to start working again.
I connected the osciloscope and this is the “i2s_dout_pin” pin when works:

image

and this is when fails (it is just like a square signal):

I am using UDA1334a and same result if is not connected. I think the problem is in the output of the ESP32 board. I am using a ESP32 WROOM devkit c 38 pin.

Му reply in another topic, there is a link to sound sample.

You should be just as good. :wink:

Definitely I think the problem is in the ESPHome firmware. I tried with a ESP32-WROVER and same result: work but it stops working after a couple of minutes. However, I have tried squeezelite-ESP32 and works really well in the WROVER. I can send a mp3 by a homeassistant script for the doorbell and more else:

  • Send Spotify streaming
  • Connect by bluetooth as a common speaker does and send the streaming.

The only thing I’m missing is a homeassistant switch that activates an output pin of the WROVER board

I found how to activate a pin and it is not needed to do it from Home Assistant. Going to NVS editor (enable the tab if it is not visible) and define set_GPIO as “33=amp”. This activates a relay that turns on the speaker. Now squeezelite-ESP32 is perfect for me!

1 Like