DFPlayer Mini MP3 player with ESPHome

Is anyone controlling a DFPlayer Mini MP3 player with an ESP8266/ESP32 using ESPHome? It’s a small MP3 player board with an SD card slot that can be connected directly to a speaker and controlled via serial commands. For example, like this taken from an Arduino example:

// Play track 0013.mp3 of Dfplayer microSD
char command[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x0D, 0xFE, 0xEB, 0xEF };

There is a feature request to add support in ESPHome, but it seems like it should be possible to control using the UART bus or maybe a custom UART device using one of the Arduino libraries such as DFPlayerMini Fast.

My use case is to play pre-recorded messages like “Just a moment. I’ll be right there.” on an ESP32-cam based doorbell, triggered via an actionable Android notification.

Has anyone tackled this? Otherwise, any suggestions?

Thanks.

1 Like

I have that module and I’m gonna take care of that feature if nobody does it first. I need some spare time. Like two weeks plus the esphome releases cycle.
Anyway if it is really that simple it should work with UART switch and you don’t have to write any C code.

What are the required features?

3 Likes

Great to hear that you’re planning to add the feature.

I’ve ordered a DFPlayer Mini which should arrive in about a week. I’d be happy to help with testing if needed.

I didn’t notice your question at first:

The features I need for my use case are pretty limited. I think that the only commands I need are:

  • Specify tracking
  • Specify volume
  • Playback
  • Query the current status
  • Reset module

Of course, if someone really wanted to build an MP3 player, they would need many more.

Looking at that Arduino example I posted, I’m a bit confused as to what all is included. This could be totally wrong, but here’s what I think that I can work out:

0x7E - Start bit
0xFF - ?
0x06 - Specify volume
0x03 - Specify tracking
0x00 - Feedback = No
0x00 - [I think that this should be the volume; confusing that it is zero.]
0x0D - Track number 13
0xFE - Checksum?
0xEB - ?
0xEF - End bit

I made that feature request. I’ll order a DFPlayer today.

Any suggestions on a speaker to connect to this?

Out of curiosity, @silfa718, what’s your use case?

I am making my daughters play kitchen set more interactive. Right now i have lights for the playset’s fridge, oven, microwave that turn on/off when the doors are open controlled by led strip lights connected to an esp8266…thanks to ESPHome. I hope to install the led strips next week into the playset.

What I want to do next is add sound effects of a microwave running and “ding” when done, perhaps the sound of water when her hands get by the sink. Since I have the esp8266 already at the playset I wanted to get that to also play the sound effects.

2 Likes

What a cool dad! :slight_smile:

Actually, it sounds like your feature requirements would be very similar to mine.

Thanks…

The led project is a test before I do outdoor leds for the house.

Whats your project?

A video doorbell with the possibility to trigger pre-recorded messages such as “I’ll be right there” from actionable notifications on my phone.

Having fun with this, I hope to send a PR before weekend.

In case anyone is tinkering with this, I had to add a 10k pull down resistor between TX (Using D0) on ESP8266 and RX on DFPlayer Mini, otherwise it will not work at 3.3v.

1 Like

Sounds like great progress. Thanks.

Is it able to play different mp3’s at the sametime?

You can store many MP3s in the SD card, but only one can actually be playing at any given time.

That’s awesome! Thanks.

I’ve been using one for the speaker in my bathroom- adding esphome support makes it a whole lot easier to manage.

If it’s not too much trouble could you add in the ‘play random track’ feature? It’s the myDFPlayer.randomAll(); in the arduino library.

1 Like

Just checking in @glmnet. How’s it going with the DFPlayer?

1 Like

Ahh yes I have done some progress.
I decided to partially support the component but not adding much magic to it, as the commands it accepts are very specific, there is no much to do, e.g.

  • there are commands to play a file, no mather the name
  • there are other commands to play files but you have to put then in numbered folders and then number the files inside the folders
  • the random didn’t make sense to me so far
  • volume works ok
  • the playback end notification triggers for every song being played, there are commands to play in loop, folders or files, but I did not test how they all work

So that’s why I decided to give the commands ‘as is’ and see what happens, but I still need to code some stuff and do the PR - go in code revision with Otto and fix stuff write docs, etc.

The good thing is I am pretty sure I know where to end, how to finish.

1 Like

Sounds good. Thanks a lot for the update.

it’s amazing, I also am testing dfplayer for your sake glmnet but esphome can’t find “dfplayer:” components. how can I apply it ?

I always appreciate for esphome development enthusiasm. thx a lot.

Well I’ve already sent a PR for dfplayer. However since it’s still in code review phase it is not available in the dev branch. Otto seems to be busy so I don’t know when this will happen.
Meanwhile you can test for sure:
One way to test is by creating a custom_components folders next to your yaml files, then inside a dfplayer folder and put the dfplayer files inside (init.py and the others)
Get the files and read the docs

Don’t forget to delete this folder once ESPHome ships dfplayer otherwise you’ll be always using this version

4 Likes