basic implementation of DFplayer mini

Hello everybody,

I’need help to program my Arduino nano to start playback of very short files ( 2-3 seconds) stored on DFplayer.

I’want to use hardware serial pin 1 and 2 .

I’tried two libraries DFMiniMp3.h and DFRobotDFPlayerMini.h with no success.

Lack of information of how to use them make me fool !
When I’ short pin 11 or 12, play back is ok and i’hear the sound on speaker,

I’m sure that i’miss something on the setup can you help ?

Thanks !

My code:

#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini myDFPlayer;

void setup() {

Serial.begin(9600);
}

void loop() {
myDFPlayer.play(1); //Play the first mp3
delay (6000);
}

I'want to use hardware serial pin 1 and 2

What do you mean by that ? Hardware serial is on 0 and 1

DFRobotDFPlayerMini has a begin() function which you haven’t called.

Ok J-M-L, i'was talking about the first and second pin marked as tx an rx .

arduarn, where do you find list of functions related to specific library ?

Jeeprock:
arduarn, where do you find list of functions related to specific library ?

If you look in your Arduino sketchpad folder, you should see a folder for libraries. Look in there for the library that you installed and then look at the main .h file or just read the corresponding source files.

In your case you'll need something like myDFPlayer.begin(Serial);

arduarn:
If you look in your Arduino sketchpad folder, you should see a folder for libraries. Look in there for the library that you installed and then look at the main .h file or just read the corresponding source files.

In your case you'll need something like myDFPlayer.begin(Serial);

Ok, "something like..." doesn"t help me much (I'dont blame you ! ) . Cause i'm not a programmer...

I'just need to send to the DFplayer module which mp3 track I'want it to playback using the internal Uart of the nano (dedicated Tx/Rx pins) . My project is a remote radio control that will tell me few message like "System activated" or "Deactivated" in response to a dtmf code .

Thanks for your help !

If you go to the DFRobot product page there is a section down the page titled "Documentation"
One will take you to the Wiki. The Wiki has a lot of information on how to connect etc, it also has a couple of examples using the DFRobotDFPlayerMini library.

One example is getting started. Basically it gets you up and running with the basic functions

FullFunction shows every function available in the library. Read the comments section for more info.

In the case of your added request, look at the function myDFPlayer.playLargeFolder().
It's in the Full example, with comments on how to use it.

Tank you darrob, after reading it seem more clear for me.

One more question:

1-Even if i'have success with that library, can i'use tx/rx pins on the board

using " SoftwareSerial mySoftwareSerial(2, 1); // RX, TX "

instead of

" SoftwareSerial mySoftwareSerial(10, 11); // RX, TX " ?

Jeeprock:
1-Even if i'have success with that library, can i'use tx/rx pins on the board
using " SoftwareSerial mySoftwareSerial(2, 1); // RX, TX "

again the hardware ones are 0 and 1... and you don't need the software Serial instance since it's a hardware one ---> just use Serial

Note you might have to unplug whatever is connected to 0 and 1 during the upload of the code

Jeeprock:
Tank you darrob, after reading it seem more clear for me.

One more question:

1-Even if i’have success with that library, can i’use tx/rx pins on the board

using " SoftwareSerial mySoftwareSerial(2, 1); // RX, TX "

instead of

" SoftwareSerial mySoftwareSerial(10, 11); // RX, TX " ?

Save yourself a lot of heartache, and stick with SoftwareSerial on 10 and 11 or any other digital pins.

I have an application running now on 11 and 12, with 10 being connected to the BUSY pin of the DF Player.

And I’m not using any libraries either, the command bytes are easy enough to create in code and squirt out with a for-loop using SoftwareSerial.write()

Here’s some ideas…

First the DF commands

////////////////////////////////////////////////////////////////////////////////////
// MP3 Player commands and queries
// DFPlayer - datasheet(https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299)
// The DFPlayer receives commands in a 10-byte string
// The DFPlayer has a checksum (2-bytes) before the last byte
// 7E FF 06 {command} {feedback mode} {data_Hi} {data_Lo} {CS_Hi} {CS_Lo} EF 

byte MP3_Recv[10];                  // MP3 response array
byte MP3_Send[10];                 // MP3 command array
 
// Commands
#define NEXT              0x01      // Play the next track : No data - set parameter to 0
#define PREV              0x02      // Play the previous track : No data - set parameter to 0
#define PLAY_W_INDEX      0x03      // Play track number from root directory : DATA = track number 0-2999
#define VOL_UP            0x04      // Volume up 1 level : No data - set parameter to 0
#define VOL_DN            0x05      // Volume down 1 level : No data - set parameter to 0
#define VOL_SET           0x06      // Set Volume level : DATA = volume from 0 up to 30 (0x1E)
#define EQ_MODE           0x07      // Set Equalisation Preset
  #define EQ_Normal         0x00
  #define EQ_Pop            0x01
  #define EQ_Rock           0x02
  #define EQ_Jazz           0x03
  #define EQ_Classical      0x04
  #define EQ_Bass           0x05
#define MODE              0x08      // Set Playback Mode 
  #define MODE_Repeat       0x00
  #define MODE_FolderRepeat 0x01
  #define MODE_SingleRepeat 0x02
  #define MODE_Random       0x03
#define DEV_SEL           0x09      // Storage Device Select
  #define DEV_USB           0x00
  #define DEV_TF            0x01
  #define DEV_AUX           0x02
  #define DEV_SLEEP         0x03
  #define DEV_FLASH         0x04
#define SLEEP             0x0A      // standby low power mode
#define WAKE              0x0B      // 
#define RESET             0x0C      // Reset Chip
#define RESUME            0x0D      // Play
#define PAUSE             0x0E      // Pause
#define PLAY_F_T          0x0F      // Play Folder/Track : DATA = 0x7E 06 0F 00 {folder} {track} {CSH} {CSL} EF 
#define VOL_ADJ           0x10      // {DH=1:Open Volume Adjust}{DL:Set Gain 0-31}
#define REPEATPLAY        0x11      // 0=OFF, 1=ON

// Queries
#define SENDPAR           0x3F      // Send Initialisation Parameters 0-0x0F
                                    // each bit represent one device of the low-four bits ???
#define RETURNSERR        0x40      // Returns an Error : Request Retransmission ????
#define REPLY             0x41      // ????
#define Q_STATUS          0x42      // Query the current status
#define Q_VOL             0x43      // Query the current volume
#define Q_EQ              0x44      // Query the current equalisation mode
#define Q_MODE            0x45      // Query the current playback mode 
#define Q_VERS            0x46      // Query the current software version
#define Q_TFFILES         0x48      // Query the number of TF card files
#define Q_UFILES          0x47      // Query the number of USB disk files  
#define Q_FFILES          0x49      // Query the number of FLASH files
#define KEEPON            0x4A      // ????
#define Q_TFTRACK         0x4B      // Query the current track of TF card
#define Q_UTRACK          0x4C      // Query the current track of USB disk
#define Q_FTRACK          0x4D      // Query the current track of Flash

Then you can use the commands like…

MP3Cmnd(PLAY_W_INDEX, TrackSelect);

with…

void MP3Cmnd(byte command, unsigned int param) {

// create the command string to send to the player
MP3_Send[0] = 0x7E;                          // start byte
MP3_Send[1] = 0xFF;                          // version
MP3_Send[2] = 0x06;                          // length
MP3_Send[3] = command;                       // single byte command
MP3_Send[4] = 0x00;                          // feedback mode
MP3_Send[5] = (unsigned byte)(param >> 8);   // data high byte
MP3_Send[6] = (unsigned byte)(param);          // data low byte (truncated 16 to 8 bit)
// bytes [7] & [8] are the negated checksum of bytes [1] to [6]
unsigned int CSum = -(MP3_Send[1] + MP3_Send[2] + MP3_Send[3] + MP3_Send[4] + MP3_Send[5] + MP3_Send[6]);
MP3_Send[7] = (unsigned byte)(CSum >> 8);    // checksum high byte
MP3_Send[8] = (unsigned byte)(CSum);         // checksum low byte (truncated 16 to 8 bit)
MP3_Send[9] = 0xEF;                          // end byte

// send the command data to the MP3 module
  for (int i=0; i<10; i++) {
    MP3.write(MP3_Send[i]); 
  }
  delay(100); 
} // void MP3Cmnd()

No need for any library code at all, keeps it simple.

Well ! success !

Started from scratch with sample code (that code need both line of tx/rx )

I’was wiring only tx before !

ps: daba i’will explore your suggestion more…

Thanks everybody !

Last update:I’found my way !

Sure that this will be useful for someone !

Test code with no frills only for basic playback (tested )

#include “DFRobotDFPlayerMini.h”

#include “SoftwareSerial.h” //if you want use other than pin 1 and 2 for serial

SoftwareSerial mySoftwareSerial(9,8); // RX, TX any pins you need

DFRobotDFPlayerMini myDFPlayer;

void setup() {
mySoftwareSerial.begin(9600);//set speed for SoftwareSerial

Serial.begin(9600); //set speed for Hardware Serial pin 1 and 2 tx/rx

myDFPlayer.begin(Serial);//select Serial to send comand to dfplayer

// or (select only one)

//myDFPlayer.begin(mySoftwareSerial);//select SoftwareSerial to send comand to dfplayer

}

// loop will playback track 1 repeatedly at 2 seconds interval:

void loop() {
myDFPlayer.volume(30); //Set volume value. From 0 to 30
myDFPlayer.play(1);
delay(2000);

}