Having trouble getting dfmini player to read sd card

I am trying to program an arduino to play a playlist of MP3 files, and I cannot figure out what is going wrong. Here is the mp3 player we are using: DfMini Player Mp3 Board
YX5200

Here is the code up until I get an error:

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

SoftwareSerial mySoftwareSerial(5, 4); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
RTC_DS3231 rtc;

void printDetail(uint8_t type, int value);

unsigned long last = 0;
int h, m;
boolean reproduciendo = false;

void setup() {
  mySoftwareSerial.begin(9600);
  Serial.begin(9600);

  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  if (!myDFPlayer.begin(mySoftwareSerial, true, true)) {  //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) {
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(30);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

This is specifically where the error occurs as I get the output in my serial monitor "unable to begin, 1. please recheck the connection!, 2.please insert the SD card!"


  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) {
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));

We have spent days changing things and trying to figure out what is going on without success. I would really appreciate any insight!

The SD cards are formatted FA32 and the file names are ####.mp3

Thank you!

Your topic does not indicate a problem with IDE 2.x and hence has been moved to a more suitable location on the forum.

1 Like

Ignoring wiring problems (since you haven't given us a wiring diagram or schematic), try momentarily grounding IO1 (pin 9) or IO2 (pin 11) on the DFplayer module to see if it can even read the files on your card. Because I'm leaning towards it not being able to do so.

1 Like

assume you are using a Arduino UNO?
this works on a Nano so should work on a UNO

// Arduino Nano Classic  DFRobotDFPlayer player

// **** Once the card is formatted, MP3 files can be copied to it. 
// **** They are played in the order in which they were copied to the card
// names make no difference

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

// Nano connections
// Nano VIN (5V) to DFPlayer VCC
// Nano GND to DFPlayer GND
// Nano pin 8 serial RX to DFPlayer TX
// Nano pin 9 serial TX to DFPlayer RX
// Nano pin 4 to DFPlayer BUSY

AltSoftSerial mySoftwareSerial(8, 9); // nano RX, TX
#define BUSY 4

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup() {
  pinMode(4, INPUT_PULLUP);       // GPIO 4 is Busy signal
  mySoftwareSerial.begin(9600);   // DFPlayer serial
  Serial.begin(115200);
  delay(3000);
  Serial.println();
  Serial.println(F("\nNano 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(25);  //Set volume value. From 0 to 30
  //myDFPlayer.play(1);     //Play the first mp3
  delay(10);
  Serial.println("enter track to play (1, 2, 3, etc)");
}

void loop() {
  static unsigned long timer = millis();
  static int busy = -1;
  // check if player Busy status has changed
  if (digitalRead(BUSY) != busy) {
    if ((busy = digitalRead(BUSY)))
      Serial.println("busy " + String(busy) + " NOT playing");
    else
      Serial.println("busy " + String(busy) + " playing");
    ;
  }

  if (millis() - timer > 3000) {
    timer = millis();
    //myDFPlayer.next();  //Play next mp3 every 3 second.
  }
  // if new track (integer) entered play it
  if (Serial.available()) {
    int x = Serial.parseInt();                // read track number
    Serial.println("playing " + String(x));
    myDFPlayer.play(x);                       // play track
    while (Serial.available()) Serial.read(); // clear EOL etc
    delay(10);
  }

  // if player status changed display
  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;
  }
}

serial monitor output

Nano DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
DFPlayer Mini online.
enter track to play (1, 2, 3, etc)
busy 1 NOT playing
playing 1
busy 0 playing
playing 2
busy 1 NOT playing
busy 0 playing
playing 3
busy 1 NOT playing
busy 0 playing
1 Like

Please show the full code. Later code might contribute to an error,

As requested, a schematic is also helpful (perhaps hand drawn).

EDIT:
Meanwhile try running the following edits I've made to your code. This sketch works fine on a Uno or nano. The major change is that I've commented out all your RTC code. I also changed to my usual Arduino RX/TX pins (10/11) for my convenience. Also read my comments.

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

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
// SoftwareSerial mySoftwareSerial(5, 4); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//RTC_DS3231 rtc; // my edit, to focus on DFR player

void printDetail(uint8_t type, int value);

unsigned long last = 0;
int h, m;
boolean reproduciendo = false;

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(9600); // my preference
  //
  //  if (!rtc.begin())
  //  {
  //    Serial.println("Couldn't find RTC");
  //    Serial.flush();
  //    abort();
  //  }

  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // ??? That seems to have no relevance to the code below it.
  if (!myDFPlayer.begin(mySoftwareSerial, true, false))  // my edit; avoids noise.
    // if (!myDFPlayer.begin(mySoftwareSerial, true, true))    //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)
    {
      delay(0); // Code to compatible with ESP8266 watch dog.
      // Is the device an ESP8266?
    }
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(20);  // 30 too loud and potentially cause of voltage drop
  // myDFPlayer.volume(30);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop() // My edit, as not provided by OP
{

}

1 Like

Make sure your SD card is formatted to FAT16 or FAT32, as DFPlayer Mini doesn’t support exFAT. Also, try renaming files to '0001.mp3', '0002.mp3', etc., and place them directly in the root directory. Have you checked the wiring and power supply as well?

1 Like

Thanks for your responses! We seem to have solved it by changing "myDFPlayer.play(1)" to "myDFPlayer.playMp3Folder(1)". Next time I will make sure to include the entire code and schematic!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.