Problem with player mp3 DFPlayer

Hi!

I'm using an esp32 and a DFRobot DFPlayer Mini mp3 player with module library (GitHub - DFRobot/DFPlayer-Mini-mp3). I put the mp3 files on the sd card and I can play when I type "a" on the serial monitor (using the library's next() function), but I can't use the "play()" function. I put play(1) to play the first file, or play(2) for the second and etc but it doesn't work. Has anyone had a similar problem?

Here is my code:

#include <Arduino.h>
#include "DFRobotDFPlayerMini.h"

HardwareSerial mySerial(1);
int i = -1;

DFRobotDFPlayerMini myDFPlayer;


void setup()
{
  mySerial.begin(9600, SERIAL_8N1, 18, 19);
  Serial.begin(115200);
  Serial.println();
  Serial.println(F("Starting DFPlayer module ..."));

  if (!myDFPlayer.begin(mySerial)) {  
    Serial.println(myDFPlayer.readType(), HEX);
    Serial.println(F("Error starting, check:"));
    Serial.println(F("1.The module connection."));
    Serial.println(F("2.If the SD card was inserted correctly."));
    while (true);
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.setTimeOut(500);

  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

  Serial.print(F("Files found on SD card: "));
  Serial.println(myDFPlayer.readFileCounts(DFPLAYER_DEVICE_SD));

  myDFPlayer.EQ(0);    
  myDFPlayer.play(1); 



}
void loop()
{
  char choice = Serial.read();
  if (choice == 'p')
  {
    Serial.println(F("---Play---"));
    myDFPlayer.start();  
    delay(10);
  }
  if (choice == 's')
  {
    Serial.println(F("---Stop---"));
    myDFPlayer.stop();  
    delay(10);

  }
  if (choice == '+')
  {

    myDFPlayer.volumeUp();
    Serial.println("---Turn up the volume---");
    
  }
  if (choice == '-')
  {
    Serial.println("---Reduce the volume---");
    myDFPlayer.volumeDown();
   
  }
  if (choice == 'a')
  {
    Serial.println("---Advance---");
    myDFPlayer.next();
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());   
  }
  if (choice == 'r')
  {
    Serial.println("---Reced---");
    myDFPlayer.previous();
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
  }
  if (choice == 't')
  {
    i += 1;
    Serial.println("---Test---");
    myDFPlayer.loopFolder(i);
    Serial.println(i);
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
    Serial.println(myDFPlayer.readFolderCounts());
  }

  if (choice == 'y')
  {
    i += 1;
    Serial.println("---Test2---");
    myDFPlayer.playFolder(i, 0);
    //myDFPlayer.start();
    Serial.println(i);
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
    Serial.println(myDFPlayer.readFolderCounts());
  }

  if (choice == 'f')
  {
    myDFPlayer.play(1);
    Serial.println("test1");
  }
  

  if (choice == '0')
  {
    myDFPlayer.EQ(0); //0 - Normal
    Serial.println("---Equalizer: Normal---");
  }

  if (choice == '1')
  {
    myDFPlayer.EQ(1); //1 - Pop
    Serial.println("---Equalizer: Pop---");
  }

  if (choice == '2')
  {
    myDFPlayer.EQ(2); //2 - Rock
    Serial.println("---Equalizer: Rock---");
  }

  if (choice == '3')
  {
    myDFPlayer.EQ(3); //3 - Jazz
    Serial.println("---Equalizer: Jazz---");
  }
  if (choice == '4')
  {
    myDFPlayer.EQ(4); //4 - Classic
    Serial.println("---Equalizer: Classic---");
  }
  if (choice == '5')
  {
    myDFPlayer.EQ(5); //5 - Bass
    Serial.println("---Equalizer: Bass---");
  }

}

Thanks!

Do you have it wired directly to the ESP32. The ESP32 is a 3.3V device, the DFPlayer is a 5V device. There are better libraries for the DFPlayer: GitHub - PowerBroker2/DFPlayerMini_Fast: Fast and easy to understand Arduino library to use the DFPlay

What does the output of setup() look like? it should display your file count as well as when you use 'a'.

You should also blindly read the serial port, even if nothing is there and you might want to look into the switch() statement since only one of your many if() statements can possibly be true on any given run through loop()

According to the instructions:

Which says:

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.

@blh64 @johnwasser

Thanks for answering!

The setup() output is this:

17:54:40.934 -> Starting DFPlayer module ...
17:54:42.011 -> DFPlayer Mini online.
17:54:42.245 -> Files found on SD card: -1
17:54:49.844 -> ---Advance---
17:54:49.938 -> -1/1

It displays "-1" as mp3 total. But there are about 9 mp3s in the "MP3" folder on the SDCARD, all renamed as "0001", "0002". I don't know the reason for the "-1"...

However, when advancing the track, it plays exactly "-1".

I tested this code with the new library you gave me, it doesn't play anything, not even using next() and it also shows "-1"...

#include <DFPlayerMini_Fast.h>
#include <Arduino.h>


HardwareSerial mySerial(1);
DFPlayerMini_Fast myMP3;

void setup()
{
  Serial.begin(115200);

#if !defined(UBRR1H)
  mySerial.begin(9600, SERIAL_8N1, 18, 19);
  myMP3.begin(mySerial, true);
#else
  Serial1.begin(9600);
  myMP3.begin(Serial1, true);
#endif
  delay(1000);
  Serial.print(F("Files found in SD: "));
  Serial.println(myMP3.numSdTracks());
  Serial.println("Setting volume to max");
  myMP3.volume(30);
  myMP3.playFromMP3Folder(1);
  delay(5000);
  Serial.println("Looping track 1");
  myMP3.loop(1);
}

void loop()
{
  //do nothing
}

18:02:23.726 -> File found in SD: Sent Stack:
18:02:23.773 -> 7E FF 6 48 0 0 0 FE B3 EF
18:02:23.773 ->
18:02:23.867 -> timeout error
18:02:23.867 -> -1
18:02:23.867 -> Setting volume to max
18:02:23.867 -> Sent Stack:
18:02:23.867 -> 7E FF 6 6 0 0 1E FE D7 EF
18:02:23.867 ->
18:02:23.867 -> Sent Stack:
18:02:23.867 -> 7E FF 6 12 0 0 1 FE E8 EF
18:02:23.867 ->
18:02:28.870 -> Looping track 1
18:02:28.870 -> Sent Stack:
18:02:28.870 -> 7E FF 6 8 0 0 1 FE F2 EF
18:02:28.870 ->

How are you powering this? You set your volume to max so it will draw the maximum current and if your power supply can't deliver, you won't get any audio out. You could test setting it to a much lower value.

It also looks like you are getting a timeout error so did you wire it up correctly? The _fast library allows you to increase the timeout period.

I changed the volume and turned it down, I also set a longer timeout, but it still doesn't work. Using the original library( GitHub - DFRobot/DFRobotDFPlayerMini: Arduino library for DFPlayer ) I also get the "-1" return on the number of tracks, but as I go forward, the tracks are played. I really don't know what it could be...
The tracks are in the mp3 folder at the root of the sdcard, named as "0001.mp3, 0002.mp3".

#include <DFPlayerMini_Fast.h>
#include <Arduino.h>


HardwareSerial mySerial(1);
DFPlayerMini_Fast myMP3;

void setup()
{
  Serial.begin(115200);

#if !defined(UBRR1H)
  mySerial.begin(9600, SERIAL_8N1, 18, 19);
  myMP3.begin(mySerial, true);
#else
  Serial1.begin(9600);
  myMP3.begin(Serial1, true);
#endif
  delay(1000);
  myMP3.setTimeout(1000);
  Serial.print(F("File found in SD: "));
  Serial.println(myMP3.numSdTracks());
  Serial.println("Setting volume to max");
  myMP3.volume(10);
  myMP3.playFromMP3Folder(1);
}

void loop()
{
  char choice = Serial.read();
    if (choice == 'a')
  {
    Serial.println("---Advance---");
    myMP3.playNext();
    Serial.print(myMP3.currentSdTrack());
    Serial.print('/');
    Serial.println(myMP3.numSdTracks());
  }
}

You still have not answered any of the power related questions? How are you powering all this? How are you dealing with 3.3V ESP32 vs a 5V DFPlayer? A schematic would be very helpful.

I'm using this scheme:

Only difference is that I use pins 18 and 19 instead of 16 and 17.

Based on this video:

I seriously doubt the ESP32 can supply enough current on the 3.3V pin to power all that, especially a speaker.

reiterating, next() works, sound is played. What doesn't work is play(), playFolder() and playMp3Folder(). I really don't know what it can be anymore...

I have got to think its the nomenclature you have named the .mp3 files. You are using the correct DF Mini Fast library. Take a deep dive into that SD card and look at them. I found that some of my files I would put in as 0001.mp3 - but the SD would recognize that file and give it ANOTHER .mp3 extension- making the file name:
0001.mp3.mp3

Try to just put them in as 0001, 0002,. 0003 etc. with no .mp3 extension. I would think that next() would work right now but if you call for a specific file to play() and it can't find the nomenclature it freezes up as it doesn't know what to look for.

1 Like

Also, try to get the example.ino code in the DF Mini Fast library working first- that would be the simplest way to determine the above hypothesis. If it works on the first time then the nomenclature is correct- if it doesn't then you can almost be sure its a file extension/naming problem.

Try powering the DFPlayer on its own.

I tried to remove the .mp3 extensions from the files and it doesn't even recognize it anymore.

I tried running example.ino and it didn't really work. The way out is this:

10:21:34.511 -> OK
10:21:35.537 -> Setting volume to max
10:21:35.537 -> Sent Stack:
10:21:35.537 -> 7E FF 6 6 0 0 14 FE E1 EF
10:21:35.537 ->
10:21:35.537 -> Looping track 1
10:21:35.537 -> Sent Stack:
10:21:35.537 -> 7E FF 6 8 0 0 1 FE F2 EF
10:21:35.537 ->

The code:

#include <DFPlayerMini_Fast.h>

HardwareSerial mySoftwareSerial(1);

DFPlayerMini_Fast myMP3;

void setup()
{
  Serial.begin(115200);

#if !defined(UBRR1H)
  mySoftwareSerial.begin(9600, SERIAL_8N1, 18, 19);
  if(myMP3.begin(mySoftwareSerial, true)){
    Serial.println("OK");
  }else{
    Serial.println("ERRO");
  }
#else
  Serial1.begin(9600);
  myMP3.begin(Serial1, true);
#endif
  
  delay(1000);
  
  Serial.println("Setting volume to max");
  myMP3.volume(20);
  
  Serial.println("Looping track 1");
  myMP3.loop(1);
}

void loop()
{
  //do nothing
}

The code needed to change the SoftwareSerial to HardwareSerial because I am using ESP32.

My mp3 folder on SD looks like this:

How long are the length of these .mp3 files? If they are 7.69 kb, 12.4 kb, 8.92 kb, etc. I assume they are very short sound files. Could you try a longer file- like a regular song in .mp3 format and see if that works?
Also I like @er_name_not_found suggestion to try a seperate power source for the DF mini player- at 3.3v you're maxing out the power. It seems weird that that would affect it as its doing the next() command but not the play() but its possible that could be an issue. Worth a shot.

Ever have the battery start to run down on a model car and it will drive but not if you turn on the headlights? It just seems that some functions may just require more wattage than others.

It will run on 3.3V but it likes 4.2V and if you turn up the volume you are drawing >3W so best to allow at least 1A.

Excellent example. I was trying to word that and couldn't express it correctly. I know I use a lot of knockoff DF Mini Players from Amazon and AliExpress and they always use more voltage than the genuine DF Mini from DFRobot.

Out of curiosity I put "0" in playMp3Folder() and played track 1. Then I added a function to print possible errors and when I send "f" to the serial monitor, track 1 plays but the following error appears:

16:49:02.866 -> teste1
16:49:03.290 -> DFPlayerError:Cannot Find File

New code:

#include <Arduino.h>
#include "DFRobotDFPlayerMini.h"

HardwareSerial mySerial(1);
int i = -1;
int teste = 0;
DFRobotDFPlayerMini myDFPlayer;


void setup()
{
  mySerial.begin(9600, SERIAL_8N1, 18, 19);
  Serial.begin(115200);
  Serial.println();
  Serial.println(F("Starting DFPlayer ..."));

  if (!myDFPlayer.begin(mySerial)) { 
    Serial.println(myDFPlayer.readType(), HEX);
    Serial.println(F("Error:"));
    while (true);
  }
  Serial.println(F("DFPlayer Mini online."));


  myDFPlayer.setTimeOut(1000);



  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

  Serial.print(F("Files found SD: "));
  Serial.println(myDFPlayer.readFileCounts());


  myDFPlayer.EQ(0);    
  myDFPlayer.playMp3Folder(0);  

  Serial.println("Volume: + or -");
  Serial.println("Next and previous faixa: a or r");
  Serial.println("Pause and  start: s or p");
  Serial.println("Equalizer: 0 - Normal, 1 - Pop, 2 - Rock, 3 - Jazz, 4 - Classic and 5 - Bass ");


}
void loop()
{
  char choice = Serial.read();
  if (choice == 'p')
  {
    Serial.println(F("---Play---"));
    myDFPlayer.start();  
    delay(10);
  }
  if (choice == 's')
  {
    Serial.println(F("---Stop---"));
    myDFPlayer.stop();  
    delay(10);

  }
  if (choice == '+')
  {

    myDFPlayer.volumeUp();


  }
  if (choice == '-')
  {
    myDFPlayer.volumeDown();

  }
  if (choice == 'a')
  {
    myDFPlayer.next();
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
  }
  if (choice == 'r')
  {
    myDFPlayer.previous();
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
  }
  if (choice == 't')
  {
    i += 1;
    Serial.println("---Test---");
    myDFPlayer.loopFolder(i);
    //myDFPlayer.start();
    Serial.println(i);
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
    Serial.println(myDFPlayer.readFolderCounts());
  }

  if (choice == 'y')
  {
    i += 1;
    Serial.println("---Test2---");
    myDFPlayer.playFolder(i, 5);
    //myDFPlayer.start();
    Serial.println(i);
    Serial.print(myDFPlayer.readCurrentFileNumber());
    Serial.print('/');
    Serial.println(myDFPlayer.readFileCounts());
    Serial.println(myDFPlayer.readFolderCounts());
  }

  if (choice == 'f')
  {
    myDFPlayer.playMp3Folder(teste);
    Serial.println("teste1");
  }


  if (choice == '0')
  {
    myDFPlayer.EQ(0); //0 - Normal
    Serial.println("---Equalizador: Normal---");
  }

  if (choice == '1')
  {
    myDFPlayer.EQ(1); //1 - Pop
 
  }

  if (choice == '2')
  {
    myDFPlayer.EQ(2); //2 - Rock
    Serial.println("---Equalizador: Rock---");
  }

  if (choice == '3')
  {
    myDFPlayer.EQ(3); //3 - Jazz
    Serial.println("---Equalizador: Jazz---");
  }
  if (choice == '4')
  {
    myDFPlayer.EQ(4); //4 - Classic
    Serial.println("---Equalizador: Classic---");
  }
  if (choice == '5')
  {
    myDFPlayer.EQ(5); //5 - Bass
    Serial.println("---Equalizador: Bass---");
  }
  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;
  }
}

I'm going to try to change the power to 5V, but I don't know, it seems to be a problem in the lib.

Not impossible, but probably just seems that way.

Think of what you're doing when you search for a track:
First the player is probably already running
So it's drawing power for the amp, the decoder, and the SD
Then you ask it to look for another track which it's happy to switch to as soon as it finds it, but in the mean time it will continue to do its current thing and draw more power to look for the track on other places on the SD card
It might just run out of energy before you run out of requirements for it.

You are already halfway closer to solving this than most of the people who ask this same question as you are willing to try a recommended path. Please remember that 5V doesn't guarantee you 3W, you still need to be sure it's at least 1A and more amps are better as it will only consume what it needs provided you keep it under 5V.


This 5V brick says it's 2A / 1.5A but I just consider the top 1/3 to be the angel's share, so to me this is a 5V 1A power supply, because I'm only interested in how much power it can deliver all day long.

Like I said before though, amateur advice.

If I've misspoken though I have no doubt that I'll be corrected :rofl:

Upon closer inspection, I need new glasses. This is a 3A at 5V so I'd use it as a 2A