DFPlayer mini play specific track

Working on a project with a Xenon and a df player mini. Eventually I will incorporate an NFC reader to play each track, but for now I want to simplify things by using a button. Following the documentation for the player, I specified the folder and track number, but all I get is a small crackle from my speaker when I press that particular button. If I play the track using the pins from the player itself, it plays fine, I can press the button for that track and it won’t interrupt the song, but if I press a button for another song, it stops playing, and I get the crackle again.

Here are the two commands, highlighted, that I’m using. I will share my code when I get back to my computer.


I’ve got the DFplayer working on a Photon.

and if it helps here is the code

Shared DFplayer code

It uses the DFRobotDFplayermini libary, and as I don’t that a working Xenon mesh yet I don’t know how portable code from the photon to xenon is likely to be… maybe someone will suggest the likely probability of success.

Basicaly a point to note the track numbers are based on order of which track is written to the card, not what you chose to name it. My code uses a photon to publish a track number to the particle cloud and another to subscribe and then play that track number. Working a treat, using a 3x4 keypad. I just enter the track number and press *.

Hope that helps


1 Like

Thanks @VideoLiam, I saw that library but thought I would simplify the whole thing since there is a lot of stuff I don’t need in that library. I’ll take a look at your code though, thank you.

I have them named 001-005, so that shouldn’t be an issue, I’m assigning each pin to a numbered track so that shouldn’t cause an issue either.

Hi Mjones,

The DFplayer will not care what you call the tracks, it cares about the order they are written to on the SD card,

By all means call them 1,2,3… but if you write them to the card out of order, expect strange results…


I was referring to windows automatically ordering them numerically 1-5. Are you saying it will ignore that if I write them out of that order?

As far as working with a Xenon, your sketch compiles fine on a Xenon, so I’ll flash it and test.

If you have three digit files you need to use the command to play track from folder and pass the two digit folder number (or pre-set the folder) (command 0x0F Specify folder and file to playback * [DH]=Folder, [DL]=File).
The other play commands expects your files to be numbered with four digits (0x03 in SD root or 0x12 in an mp3 folder).

1 Like

I went ahead and modified your sketch for the pins I wanted to used instead of incoming data from a subscription, it works perfectly. I’ll still go in and deconstruct everything, it helps me understand exactly how this works rather than just using someones code without understanding it. Next for this project is to get the PN532 set up and working with (what I hope are the correct) NFC tags I ordered.

Scruffr, I took them out of any folders, and checked that they were number correctly against the pins that I have assigned. Everything works as expected.

1 Like


DFPlayer uses command 0x0F to play files with 3-digit file name prefixes.

  • These files can be located in folders named 01 to 99.
  • Valid prefixes are 001 to 255.

DFPlayer uses command 0x14 to play files with 4-digit file name prefixes.

  • These files can be located in folders named 01 to 15.
  • Valid prefixes are 0001 to 4095.
  • Mfr. suggests a max of 3000 tracks per folder for performance reasons.

Never mix 3 and 4 digit prefixes in the same folder or DFPlayer command 0x0F gets confused. For example a request to play track 001 might play the prefix 001, 0010, 0011, 0012, 0013 … or 0019 because they all begin with 001.

I use the term “file name prefix” because, while the name ‘001’ is valid, so is '001 Singing in the Rain". DFPlayer supports any file name that FAT32 supports. It only looks at the prefixes.

The following commands are also available, but there is no DFPlayer command to play ALL of the tracks within these folders.

DFPlayer command 0x12 plays files with 4-digit prefixes in a folder named MP3.

DFPlayer command 0x03 plays files with 4-digit prefixes in the media’s root folder.

Based on your stated purpose, ignore DFPlayer commands 0x11, 0x08, and 0x17.


This is very interesting, and could help me expand this project a little bit. Do you know if it’s possible to specify a folder and play a random song within that folder? Where can I find a complete list of commands for this player?

DFPlayer command 0x18 does a random play, but I can’t recall the details.

I just reread your initial note, and you reference some crackling. I experienced crackling whenever the DFPlayer did a reset. I know removing and reinstalling media causes a reset. I wonder if the buttons are doing the same thing. In any case, I have not seen any crackling with software play commands.

I thought I’d share some more information:

A couple of basic commands:


        uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x0E, 0x00, 0x00, 0x00, 0xFE, 0xED, 0xEF };


        uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x0D, 0x00, 0x00, 0x00, 0xFE, 0xEE, 0xEF };

About DFPlayer folder/track limits …

  • DFPlayer commands only have two bytes for data.
  • The command to play 3-digit prefixes uses one byte to reference the folder, and one byte to reference the file prefix. That is why file prefixes are limited to 255.
  • The command to play 4-digit prefixes uses four bits to reference the folder, and 12 bits to reference the file prefix. That’s where the 1-15, and 1-4095 limits come from.
  • You can do bitwise logic, but I find it much easier to use simple math.
    • Given a folder value of 13 and a track value of 3192 we can create a uint16_t with the 4-bit/12-bit value with the simple calculation: ((track*4096) + folder)
      • Details
        decimal (13*4096 = 53248) = binary (1101000000000000)
        decimal (3192) = binary (110001111000)
        decimal (53248 + 3192 = 56440) = binary (1101110001111000)
    • Now we can separate the uint16_t into two bytes with the following calculations:
      • MSB = decimal (56440 / 256 = 220) = binary (11011100)
      • LSB = decimal (56440 % 256) = 120) = binary (01111000)
        % performs a division, but returns the remainder (aka modulus)

Sample logic to format the command to play a file with a 3-digit file name prefix:

        uint16_t cs = 0xFEFB - (0x0F + this->dState.selection.folder + this->dState.selection.track); // compute checksum
        // format the command
   	uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x0F, 0x00, this->dState.selection.folder, (uint8_t)this->dState.selection.track, (uint8_t)(cs / 256), (uint8_t)(cs % 256), 0xEF};

Sample logic to format the command to play a file with a 4-digit file name prefix;

	uint16_t dbyte = ((this->dState.selection.folder * 4096) + this->dState.selection.track);

	uint16_t cs = 0xFEFB - (0x14 + (dbyte / 256) + (dbyte % 256)); // compute checksum

        // format the command
	uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x14, 0x00, (uint8_t)(dbyte / 256), (uint8_t)(dbyte % 256), (uint8_t)(cs / 256), (uint8_t)(cs % 256), 0xEF};

This document contains the latest list of commands for the DFPlayer Mini. I got the document directly from the manufacturer.
DFPlayer Mini

1 Like

I’ve done more thinking about your question regarding a command to randomly play the contents of a folder.

  1. The 0x18 command appears to be the only DFPlayer command that randomly plays content, and that command plays tracks from the entire media … there is no option to select a folder.

  2. The 0x4E command can be used to query the number of tracks in a folder.

  3. The 0x08 command can be used to play tracks in a folder by track number.

    • This command does NOT reference tracks by the file name prefix.
    • If you ask this command to play track 7 in folder 9, it will enumerate the files in folder nine and play the 7th file that it finds … regardless of the files name. The file doesn’t even need to have a file name prefix.
  4. Using the above two commands, you could:

    • write code to randomly pick a track number between 1 and
    • play the track number that corresponds to the random track number
  5. When DFPlayer finishes playing a track, it returns either an 0x3C or 0x3D frame (depending on the media type … USB or SD).

    • For continuous random play, you would need to detect these frames so you knew when to issue ne next 0x08 command to play the next random track number.
    • If 0x08 is like the other commands that play individual tracks, DFPlayer will return duplicate ‘end-of-track’ frames, so you may need to handle that.

So, I think everything you’d need is there … if you decide to go this direction.


That doesn’t sound too terribly difficult, and I don’t want continuous random play, so I’ll play around with this and see what I come up with. Thanks for all the input.