MP3-TF-16P aka DFPlayer Mini .. another cheap sound module

Hello, All!

Please tell me how to calculate the checksum?

I need a module from a total of seven control commands:

  1. Play.
    0X7E, 0xFF, 0x06, 0X03, 00, 00, 0x01, 0xFE, 0xF7, 0XEF

  2. Loop.
    0X7E, 0xFF, 0x06, 0X11, 00, 00, 0x01, ?? , ?? , 0XEF

  3. Pause.
    0X7E, 0xFF, 0x06, 0X0E, 00, 00, 0x00, ?? , ?? , 0XEF

  4. Volume level 0.
    0X7E, 0xFF, 0x06, 0X06, 00, 00, 0x00, ?? , ?? , 0XEF

  5. Volume level 10.
    0X7E, 0xFF, 0x06, 0X06, 00, 00, 0x0A, ?? , ?? , 0XEF

  6. Volume level 20.
    0X7E, 0xFF, 0x06, 0X06, 00, 00, 0x14, ?? , ?? , 0XEF

  7. Volume level 30.
    0X7E, 0xFF, 0x06, 0X06, 00, 00, 0x1E, ?? , ?? , 0XEF

I am familiar (thank you, Ironic62) with the format of these commands, but do not know how to calculate the checksum.

Help me, please ...

Thank you.

Denis.

@Denis

It's easy to calculate checksum if you understand hex well. Here is an example below.
FF+06+03+00+00+01=0109 0-0109=FE F7

FN-M16P Embedded MP3 Audio Module Datasheet.pdf (808 KB)

Hi guys,

Following your instructions (I'm greatly indepted to you, especially onesky), I could make my DFPlayer work quite easily. Now I can play .wav files, but what I would need is the Sounds overlapping. The Intercut Advertisement feature of the DFPlayer to stop a track, store the Position in the track, Play another file, then resume the paused file from the stored Position seems to me the perfect solution, but alas I cannot make it work. All the other serial commands I send seem to work with the Github library functions, but not the intercut.

I made a Directory ADVERT on the SD-Card like described in the spec, still no luck :frowning:

Has anyone experience with this particular feature?

Cheers and thanks!

Hi!

I recently bought a few of these and have come to realize that the RX and TX pins are swapped on my particular modules in comparison to the pin map image that's online, just in case anyone is having issues with their dfplayer mini - I hope to save you some time :slight_smile:

I have a problem.

It makes it even when softserial well as HWserial
When connecting RX hear the hum. After disconnecting the RX hum is mute.

Check here

I have had no trouble getting this module to work in random play mode with a Nano using the dfplayer_mini_mp3 library. My current card has two folders on it but the mp3_random command plays files from both folders.

I have a project in mind to provide sound ambience in a garden depending on whether it is day or night. I have no doubt that I could organise the files into two groups and get the software to play the files in each group sequentially depending on the light but (and here's the rub) I want to play the files randomly.

I have taken a look at dfplayerminimp3ad library but it does not have an ad-random command.

I could use the arduino random function in the sketch but I would prefer to use the built-in random of the dfplayer if possible.

Here's how I see it working:

An LDR and pullup resistor using analogRead can do the day/night detecting. Alternatively a shield with an LDR and comparator could be used via digitalRead.

Ideally it would entail putting the day files in one folder and the night files in another.
When the light reduces below the threshhold, the night folder would be randomly played, else the day folder would be randomly played.

My problem is how to tell the dfplayer which folder to use. The dfplayer manual says that up to ten folders can be serially selected but does not go into detail beyond saying user specified.

Can anyone please offer me details on how to select a specific folder and what folder naming conventions (if any) I need to adopt. I am a serial and library noob - please keep it simple.

I use this module. This is the same as dfplayer mini?

bbb.JPG

It might use the same chipset (not visible), but judging by the pinout it's not the DPFplayer.

Deniska407:
Hello, All!

Please tell me how to calculate the checksum?

I need a module from a total of seven control commands:

8<---

Help me, please ...

Thank you.

Denis.

I found this sketch very useful:

///              MP3 PLAYER PROJECT
//////////////////////////////////////////
//[SL]  FILE: mp3.ino
//[SL]  from http://educ8s.tv/wp-content/uploads/2015/10/mp3.zip
//[SL]  found at http://educ8s.tv/arduino-mp3-player/
//[SL]  "//[SL]" indicates remarks and questions by SimLego
//////////////////////////////////////////


#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

# define ACTIVATED LOW

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;



void setup () {

pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);
//[SL] Shouldn't it be pinMode(..., INPUT_PULLUP)?

mySerial.begin (9600);
delay(1000);
playFirst();
isPlaying = true;


}



void loop () { 

 if (digitalRead(buttonPause) == ACTIVATED)
  {
    if(isPlaying)
    {
      pause();
      isPlaying = false;
    }else
    {
      isPlaying = true;
      play();
    }
  }


 if (digitalRead(buttonNext) == ACTIVATED)
  {
    if(isPlaying)
    {
      playNext();
    }
  }

   if (digitalRead(buttonPrevious) == ACTIVATED)
  {
    if(isPlaying)
    {
      playPrevious();
    }
  }
}

void playFirst()
//[SL] Plays first entry.
//[SL] Probably to be called first time only(???)
{
  execute_CMD(0x3F, 0, 0);
    //[SL] "Send initialization parameters"
  delay(500);
  setVolume(20);
  delay(500);
  execute_CMD(0x11,0,1);
    //[SL] "Repeat play" - PDF documentation quite cryptic
  delay(500);
}

void pause()
{
  execute_CMD(0x0E,0,0);
  delay(500);
}

void play()
{
  execute_CMD(0x0D,0,1); 
    //[SL] "Playback" - only as opposed to Pause?
  delay(500);
}

void playNext()
{
  execute_CMD(0x01,0,1);
  delay(500);
}

void playPrevious()
{
  execute_CMD(0x02,0,1);
  delay(500);
}

void setVolume(int volume)
{
  execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
    //[SL] Most documentation say 0~30
    //[SL] 48 (ie 0x30) works, but sound comes out very distorted.
  delay(2000);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}

The last function, void execute_CMD(byte CMD, byte Par1, byte Par2), automatically takes care of checksum calculations.

I also like the fact that the sketch is self-containing (except from the include file SoftwareSerial.h), because I do hate hunting for files and libraries, often to get stuck in version conflicts.

(Of course, in larger projects I would name the functions more specific than play(), pause(), and so on...)

But apart from that, this is a very good sketch to begin with IMO.

There is an Arduino compatible board with integrated DFPlayer mini, using the SD-card version, check it out here:
DIYino

Among the links you can also find one to LSOS by neskweek on GitHub which has a strongly upgraded DFPlayer library.

I am trying to get the DFPlayer Mini to work with a Simblee, which is not compatible with Software.Serial.h. So I am looking for some simple code to send the serial commands with check sum. Any help??

Hello
I try to use DFPlayer modul but I have a problem.
I would like to play a sound in endless loop but when the sound end the modul send USART message and it do noise in sound. Can anybody say how can I disable the USART message.
I send this command:7e ff 06 08 00 00 04 fe efef
Regards
John

Are you using the DFPlayer to play MP3 or Wav? It might be important.

I've been experimenting with the DFPlayer mini and I can't find a way to play two songs at the same time, do you have any idea of how to do it?

Not possible unless you have two players and then use a summing opamp. The sum of the two signals should then be sent to an audio amplifier and then sent to the speaker.

I am trying to use this chip in a stand-alone format but unsuccesfully.

  • use 3 'D' batteries in series as PS.
  • did the simple switch wiring shown in the spec sheet.
  • use a 32Gb micro SD card formatted as FAT32.
  • named a single folder in the root as "mp3".
  • added two mp3 files to the folder, and resampled them down from 128kb to 22kb.

No sound comes from the speaker.
The chip indicating LED remains unlit even after briefly connecting pin 11 to ground to start a sequence.

  • the same results with 3 chip replacements!

What am I doing wrong?

What did you name the MP3 files? Do are the named with the 0001x.mp3, 0002x.mp3, ..., (etc.) naming convention?

There are two 'types' of directory normal and large, Folders must be named "01","02","03" etc. There are also 'special' directory names of which "mp3" is one.

Normal directories can hold 255 files that must be named 001xxx.mp3, 002xxx.mp3 etc.

Large directories can hold 3000 files which must be named 0001xx.mp3, 0002xxxxx.mp3 etc. The special mp3 folder is considered a large folder so the names in it must also be of the 0001.mp3 form.

Files in normal directories are played using the 0x0f command those in large folders with the 0x14 command and those in the mp3 folder with the 0x12 command.

Of the two libraries available DFPlayer_Mini_Mp3 and DFRobotDFPlayerMini I prefer the later as it seems to do more of 'what's written on the packet'.
Reading the DFRobotDFPlayerMini.h is very instructive and easy to read, the following are listed-

void playFolder(uint8_t folderNumber, uint8_t fileNumber);

void playLargeFolder(uint8_t folderNumber, uint16_t fileNumber);

void playMp3Folder(int fileNumber);

You can drive this module from a Pro-mini via the proper serial port, just put a 1k resistor in the tx line FROM the Pro-mini. It also has two pins for USB, wiring them to a USB A socket with the Vcc line connected allows reading files from a USB pen.

Select which with the outputDevice(device) command the following are defined
#define DFPLAYER_DEVICE_U_DISK 1
#define DFPLAYER_DEVICE_SD 2

Wiring them to a USB B socket WITHOUT the Vcc connected allows connecting to a PC where the SD drive appears as a drive.

The following is working code which plays from both the SD and the USB. the usb contains a Large directory

#include <DFRobotDFPlayerMini.h>

//#include <DFPlayer_Mini_Mp3.h>

//variables
int n;         // track being played
int pinState;  // for reading pins
int volume = 30;    // current volume level
int newVolume; // volume reading from pot
int busy = A7;
int pot = A3;
int threshold; // switching point for analog inputs
DFRobotDFPlayerMini mp3;  //enable the player

void setup () {
  Serial.begin (9600);
  mp3.begin(Serial);
  mp3.volume(30);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(busy, INPUT);
  pinMode(busy, INPUT);  pinMode(pot, INPUT);
}

void adjustVolume() {
  newVolume = analogRead(pot);
  newVolume = map(newVolume, 0, 1023, 0, 30);
  if (newVolume != volume)
  {
    mp3.volume(newVolume);
    volume = newVolume;
  }
}

void play( int folder, int n) {
  if (folder >0){
    mp3.playFolder(folder, n);
  }else{
    mp3.playLargeFolder(abs(folder), n);
  }
  
}

void loop () {
  int folder;
  for (int i = 2; i < 7; i++) {
    if (digitalRead(i) == 0) {
      if (i < 6) {
        mp3.outputDevice(DFPLAYER_DEVICE_SD);
        folder = 1;//  int val of directory name string
        play(folder, i - 2);
      }
      else {
        mp3.outputDevice(DFPLAYER_DEVICE_U_DISK);
        int folder = -1;//  int val of directory name string
        play(folder, i - 2);
      }

    }
    adjustVolume();

  }
}

Thank you both Power_Broker and Davidl for this much needed explanation and details.

I will go back, as soon as I can, to my set-up with your instructions in mind,
to verify that I was following the right procedures when setting this microSD.

From your notes, should I understand that there is nothing wrong about me using a 32Gb microSD?

Regards!

32G SD should be fine
From the DFrobot site

Fully supports FAT16 , FAT32 file system, maximum support 32G of the TF card, support 32G of U disk, 64M bytes NORFLASH

Dave