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:
Pause:
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x0E, 0x00, 0x00, 0x00, 0xFE, 0xED, 0xEF };
Resume:
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