DFPlayer Mini SKU:DFR0299

From Robot Wiki
DFPlayer Mini

Introduction

The DFPlayer Mini is a small and low price MP3 module with an simplified output directly to the speaker. The module can be used as a stand alone module with attached battery, speaker and push buttons or used in combination with an Arduino UNO or any other with RX/TX capabilities.


Specification

  • supported sampling rates (kHz): 8/11.025/12/16/22.05/24/32/44.1/48
  • 24 -bit DAC output, support for dynamic range 90dB , SNR support 85dB
  • fully supports FAT16 , FAT32 file system, maximum support 32G of the TF card, support 32G of U disk, 64M bytes NORFLASH
  • a variety of control modes, I/O control mode, serial mode, AD button control mode
  • advertising sound waiting function, the music can be suspended. when advertising is over in the music continue to play
  • audio data sorted by folder, supports up to 100 folders, every folder can hold up to 255 songs
  • 30 level adjustable volume, 6 -level EQ adjustable


PinOut

DFPlayer_Mini_Pin
Number Name Description Note
1 VCC Input Voltage DC 3.2-5.0V; Typical: DC4.2
2 RX UART serial input
3 TX UART serial output
4 DAC_R Audio output right channel Drive earphone and amplifier
5 DAC_L Audio output left channel Drive earphone and amplifier
6 SPK2 Speaker Drive speaker less than 3W
7 GND Ground Power Ground
8 SPK1 Speaker Drive speaker less than 3W
9 IO1 Trigger port 1 Short pree to play previous(long press to decrease volume)
10 GND Ground Power Ground
11 IO2 Trigger port 2 Short pree to play next(long press to increase volume)
12 ADKEY1 AD port 1 Trigger play first segment
13 ADKEY2 AD port 2 Trigger play fifth segment
14 USB+ USB+ DP USB Port
15 USB- USB- DM USB Port
16 Busy Playing Status Low means playing\High means no

Tutorial

Connection Diagram

DFPlayer_Mini_Pin


Copy your mp3 into you micro SD card

For Mac User

NOTE: If you are using Mac OS X to copy the mp3, the file system will automatically add hidden files like: "._0001.mp3" for index, which this module will handle as valid mp3 files. It is really annoying. So you can run following command in terminal to eliminate those files.
dot_clean /Volumes/<SDVolumeName>
Please replace the <SDVolumeName> to the volume name of your SD card.

Sample Code

We've created an Arduino library for DFPlayer Mini to simplify the method for you to make it work.

Connect the hardware as the picture above shown and play with the sample code.

Please search DFRobotDFPlayerMini in Library Manager or directly download DFRobotDFPlayerMini library. (How to install library)

GetStarted example in the library

This example shows the basic function of library for DFPlayer. Play next music every 3 seconds.
/***************************************************
DFPlayer - A Mini MP3 Player For Arduino
 <https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
 
 ***************************************************
 This example shows the basic function of library for DFPlayer.
 
 Created 2016-12-07
 By [Angelo qiao](Angelo.qiao@dfrobot.com)
 
 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************
 1.Connection and Diagram can be found here
 <https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
 2.This code is tested on Arduino Uno, Leonardo, Mega boards.
 ****************************************************/

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.volume(10);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop()
{
  static unsigned long timer = millis();
  
  if (millis() - timer > 3000) {
    timer = millis();
    myDFPlayer.next();  //Play next mp3 every 3 second.
  }
  
  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }
}

void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }

}

FullFunction Example in the library

/***************************************************
 DFPlayer - A Mini MP3 Player For Arduino
 <https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
 
 ***************************************************
 This example shows the all the function of library for DFPlayer.
 
 Created 2016-12-07
 By [Angelo qiao](Angelo.qiao@dfrobot.com)
 
 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************
 1.Connection and Diagram can be found here
<https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
 2.This code is tested on Arduino Uno, Leonardo, Mega boards.
 ****************************************************/

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  
  //----Set volume----
  myDFPlayer.volume(10);  //Set volume value (0~30).
  myDFPlayer.volumeUp(); //Volume Up
  myDFPlayer.volumeDown(); //Volume Down
  
  //----Set different EQ----
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
//  myDFPlayer.EQ(DFPLAYER_EQ_POP);
//  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
//  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
//  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
//  myDFPlayer.EQ(DFPLAYER_EQ_BASS);
  
  //----Set device we use SD as default----
//  myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
//  myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
//  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
//  myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
  
  //----Mp3 control----
//  myDFPlayer.sleep();     //sleep
//  myDFPlayer.reset();     //Reset the module
//  myDFPlayer.enableDAC();  //Enable On-chip DAC
//  myDFPlayer.disableDAC();  //Disable On-chip DAC
//  myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
  
  //----Mp3 play----
  myDFPlayer.next();  //Play next mp3
  delay(1000);
  myDFPlayer.previous();  //Play previous mp3
  delay(1000);
  myDFPlayer.play(1);  //Play the first mp3
  delay(1000);
  myDFPlayer.loop(1);  //Loop the first mp3
  delay(1000);
  myDFPlayer.pause();  //pause the mp3
  delay(1000);
  myDFPlayer.start();  //start the mp3 from the pause
  delay(1000);
  myDFPlayer.playFolder(15, 4);  //play specific mp3 in SD:/15/004.mp3; Folder Name(1~99); File Name(1~255)
  delay(1000);
  myDFPlayer.enableLoopAll(); //loop all mp3 files.
  delay(1000);
  myDFPlayer.disableLoopAll(); //stop loop all mp3 files.
  delay(1000);
  myDFPlayer.playMp3Folder(4); //play specific mp3 in SD:/MP3/0004.mp3; File Name(0~65535)
  delay(1000);
  myDFPlayer.advertise(3); //advertise specific mp3 in SD:/ADVERT/0003.mp3; File Name(0~65535)
  delay(1000);
  myDFPlayer.stopAdvertise(); //stop advertise
  delay(1000);
  myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(1~10); File Name(1~1000)
  delay(1000);
  myDFPlayer.loopFolder(5); //loop all mp3 files in folder SD:/05.
  delay(1000);
  myDFPlayer.randomAll(); //Random play all the mp3.
  delay(1000);
  myDFPlayer.enableLoop(); //enable loop.
  delay(1000);
  myDFPlayer.disableLoop(); //disable loop.
  delay(1000);

  //----Read imformation----
  Serial.println(myDFPlayer.readState()); //read mp3 state
  Serial.println(myDFPlayer.readVolume()); //read current volume
  Serial.println(myDFPlayer.readEQ()); //read EQ setting
  Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
  Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
  Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03
}

void loop()
{
  static unsigned long timer = millis();
  
  if (millis() - timer > 3000) {
    timer = millis();
    myDFPlayer.next();  //Play next mp3 every 3 second.
  }
  
  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }
}

void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}

Information derections

Serial Mode

Support for asynchronous serial communication mode via PC serial sending commands

  • Instruction Description
Commands Function Description Parameters(16 bit)
0x01 Next
0x02 Previous
0x03 Special tracking(NUM) 0-2999
0x04 Increase volume
0x05 Decrease volume
0x06 Specify volume 0-30
0x07 Specify EQ 0/1/2/3/4/5 Normal/Pop/Rock/Jazz/Classic/Bass
0x08 Specify playback mode(0/1/2/3) repeat/folder repeat/single repeat/random
0x09 Specify playback source( 0/1/2/3/4) U/TF/AUX/SLEEP/FLASH
0x0A Enter into standby-low power loss
0x0B Normal working
0x0C Reset module
0x0D Playback
0x0E Pause
0x0F Specify folder to playback 1-10(need to set by user)
0x10 Volume adjust set [DH=1:Open volume adjust][DL:set volume gain 0-31]
0x11 Repeat play [1:start repeat play][0:stop play]
0x12 Specify MP3 tracks folder 0-9999
0x13 Commercials 0-9999
0x14 Support 15 folder See detailed description below
0x15 Stop playback, play background
0x16 Stop playback
  • Serial Query Cmd
Commands Function Description Parameters(16bit)
0x3C STAY
0x3D STAY
0x3E STAY
0x3F Send initialization parameters 0-0x0F(each bit represent one device of the low-four bits)
0x40 Returns an error, request retransmission
0x41 Reply
0x42 Query the current status
0x43 Query the current volume
0x44 Query the current status EQ
0x45 Query the current palyback mode This version retains this feature
0x46 Query the current software version This version retains this feature
0x47 Query the total number of TF card files
0x48 Query the total number of U-disk files
0x49 Query the total number of FLASH card files
0x4A keep on
0x4B Queries the current track of TF card
0x4C Queries the current track of U-disk
0x4D Queries the current track of Flash

AD KEY Mode

We use the AD module keys, instead of the traditional method of matrix keyboard connection, it is to take advantage of increasingly powerful MCU AD functionality, Our module default configuration 2 AD port, 20 key resistance distribution.

  • Refer diagram
DFPlayer_Mini

I/O Mode

Here comes the most simple way to use this module.

  • Refer diagram
DFPlayer_Mini


note: short time press means pre/next,and long time press means vol- ,vol +

FAQ

Q 1. When my Arduino Uno send command to DFPlayer mini, the speaker will murmur, seems like noise, how to deal with it?

A: Please connect one 1k resistor between Arduino Tx and MP3 RX since DFPlayer Mini Module operating voltage is 3.3V.
  • Besides, one of our customers found to use another power supply for the MP3 module can get a pure sound. Be sure to make all the power's ground bound together. his post


Q 2. Is there any note for the name of the folder or the music file?

A: The function playMp3Folder (1); plays the audio file named "0001***.mp3(or other supported format)". You may have to note these:
(1). The audio file name should named with a four-digit number start, like:
  • 0001.mp3
  • 0002Chasing The Sun.mp3
  • 0003.mp3
  • 0004Try.mp3


MP3-1.png


(2). The audio file should be placed in the "MP3"folder which was located in the TF card's root directory;


MP3-2.png


Q 3. How to use advertisment function in arduino IDE? I need to pause playing0001. mp3 (background music), store the position, play another short mp3 (advertisment announce), resume background from pause position. How i can make it?

A: There is an example about it, plz follow the link.


Q 4. Has anyone used C Code for Atmega with DFplayer? Not for Arduino...

A: Shared by one of our user on Forum. DFplayer Serial Command



For any questions and more cool ideas to share, please visit DFRobot Forum





Shopping car.png BUY from DFPlayer - A Mini MP3 Player For Arduino or DFRobot Distributor List