DFplayer unable to begin and not playing

I currently own a MP3-TF-16P module, and from my extensive research on the internet i find it works like a dfplayer mini. however, whenever i upload my code onto my R4 minima, wifi, my arduino nano and my R3, it does not post. in a few occasions i am able to get it to connect (i have no idea what i did nor what i changed) but it doesn't play anything.

main issue: it prints out " Unable to begin, 1.Please recheck the connection! 2.Please insert the SD card!" in the serial monitor.

my code:

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

SoftwareSerial mySoftwareSerial(3, 2); // 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.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;
  }

}

physical wiring:

pardon my (perhaps) short temper and inadequate information, i'm just very frustrated at this whole thing not working.

THINGS THAT I HAVE TRIED ALREADY:

changing TX and RX to many other combinations.
finding many other code examples.
used another sd card
changed all the filenames on my sd card and used a different method (e.g. playMp3Folder, playFolder, loop, play...)
reuploading everything on my sd card
tried using different mp3 files to see whether it's a reading problem

Verify your RX/TX pins are wired correctly on both ends. You have mentioned three boards, but had not said which you are using.

Are there more than two combinations?

If 2 is TX, the jumper should connect to the module RX.

How has your uSD card been formatted?

How are your MP3 files named?

Have you tried momentarily grounding either the IO_1 or IO_2 pin to take the Arduino out of the equation?

Edit: also, in your picture, you have Uno's pin 3 running through a 1K resistor to the module's pin 2. Pin 2 on the module is Rx. In your code, you are defining the SoftwareSerial's Rx pin as pin 3. Oops. You need to hook up the Uno's SoftwareSerial Tx pin (which you have defined as pin 2) through the 1K resistor to the module's pin 2. And then the Uno's SoftwareSerial Rx pin (which you have defined as pin 3) directly to the module's pin 3.

i connected them to digital pins 2 and 3.

"more than two combinations" i tried using other digital pins and i'm just bad at clarifying that.

the microSD card is formatted as FAT32

MP3 file is named 0001.mp3 in the sd card (no folder) or 001.mp3 in a folder named 01.

also, i tried switching the pins physically and in the code and the same error pops up, so it's probably not a hardware issue.

How has the uSD card formatted? With which tool? These modules can be picky about that.

In any case, I notice that you declined to answer whether or not you had tried momentarily grounding IO_1 or IO_2, so I'll bow out now.

oh my god i didn't see "momentarily grounding IO1 and IO2" sorry but yeah i haven't tried that

it's formatted with the windows default file explorer and idk whether it works

edit: by grounding IO1 and IO2 i managed to get the file to play but i have no idea how to actually pair this with my arduino such that it can be controlled software-side

1 Like

This page shows various ways to control the DFPlayerMini, including SoftwareSerial...

i did try the software serial method but that didn't work, so is there a good way to implement the other control methods using code?

Probably had something incorrect.

I use the I/O mode and send "short press" or "long press" to IO_1 or IO_2 to move to next file or (rarely) change volume.

"probably had something incorrect" yep i'm exactly trying to find what i did wrong

is short press just temporarily setting the pin to low for like 50ms and long press is approx 300ms? i want to try and see the exact timing

I start with a shorting jumper in my hand and tap the IO_x pin to skip to next file. Then I hold the jumper a little longer until it effects volume. Using that "time" I wire the IO_x pin to a digital pin and use some code to "tap" or "long press" the IO_x pin.

the following worked on a Nono using AltSoftSerial but code using same pins 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

photo


note

 Nano pin 8 serial RX to DFPlayer TX
 Nano pin 9 serial TX to DFPlayer RX

also grounding IO2 played next MP3 file on SD card etc etc

SD card formatted using Windows 10 - I seem to remember mention of player only working with card 32G size or less

tried your code and it worked.

FOR EVERYONE ELSE:

pins 2 and 3, for some reason, cannot be used for this exact purpose for some unknown reason. either use pins 8,9 or pins 10,11 as a safer option.

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