Hacking the DF-Player Mini

A project log for SDA - The best new PDA

Do you miss those old small devices in your palm? Don't be sad, you can always build your own!

brtnstbrtnst 09/15/2018 at 19:500 Comments

Since I am still waiting for the PCBs for the new SDA, I turned my attention to the DFPlayer mini module.
I use it almost daily to listen music from my PDA and it needed some improvements.

Into the DFPlayer

File names

If you used DFPlayer, you know that the filenames of sound files must be named "001.mp3" "002.mp3" and so on, then copied to the SD card and then you can play them by their number.
One would think that the DFPlayer reads the file names but that is not true. When you copy mp3 files with any name, it will still happily play them, but you do not know the order. Truth is, that you need to rename the files, so they got copied in the right order, because DFPlayer does not read the names, it simply lists the directory. And if you do directory listing, you get files in the order filesystem throws them at you. You can do this with a simple shell command:

 find . -maxdepth 1 -name '*.mp3'

Now I can index the files in the order the DFPlayer will read them and store the index in my PDA. With the index, I can view the file names and play the songs on demand.

Playback status

There is still a problem, that I don't know when the DFPlayer stopped its playback. Option one is to read the "busy" pin on the player, but I am out of pins in my expansion port. Second option is to send some message to the player that will give me its status. That is nice, but serial receive API on my PDA is still a bit wonky. Third option is to index duration of the mp3 files when indexing the file names. Then the PDA can wait for the song to stop playing and send command to play next song, while updating the "currently played" information.

I ended up with this:
It lists the files, creates command queue with AWK, pipes it to bash and outputs it to my database file. In the future I can also read and index id3 tags this way.

find . -maxdepth 1 -name '*.mp3' \
| awk 'BEGIN{ a=0 }{ printf "echo \"%d=%s\" & mp3info -p \"%d_len=%%S\\n\" \"%s\" \n", a, substr($0,3),a, substr($0,3), a++ }' \
| bash > mp3-list.dat

Random playback

Last thing that is a bit weird on the DFPlayer is its random playback feature. It is too much random. Imagine you have thirty songs, when the player is choosing what song to play, it does something like play_song(random() % 31). On the first glance this seem right, but fire up random number generator of your choice and try it. You end up repeating one song quite often and that's not what you want from random playback. You need at least to check for repetition and perform another random throw when it happens.

This is the end result, the new player has smarter random playback, you can select the songs by their name (yes, they are still numbered in the screens, but it works with any name, trust me;) and it will show you the current song and position in the song.


Index your SD Card if you want to step-up your DFPlayer game. It is simple and efficient.