Cannot get DFPlayer Mini to work with Arduino (works without arduino)

I have tried to connect this player mini so many times, I can't figure out what I'm doing wrong. When I ground pin 11, my sound file plays just fine. So I think the module is ok. I've tried using the breadboard, and I've tried without the breadboard. I've tried the sample code from DFRobot, and code from folks online. No matter what, I can't get passed initialization.

I've made sure that pins 10,11 are in the code.

Photos of the current non-breadboard setup



I've got the speakers hooked up to spk1 and spk2. Ground into ground on the arduino. 5v in on the top 5v pin. rx with a 1k resistor into 11 pin, and tx to pin 10.

When the arduino boots, I hear the speaker pop and then I get the “non initialized” error from the code.

Any ideas what I'm doing wrong here?

Thanks!

Hi @optikalefx,

thanks for giving me an opportunity to test my DFMini which I bought some months ago ... :wink:

I installed it and it worked immediately with the demo program, however this connection diagram is misleading:

image

because the demo code depends on pin 4 and pin 5
(see SoftwareSerial softSerial(/rx =/4, /tx =/5); );

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

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(////*rx =/*//4, //*tx =/*//5);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

You can either change your wiring RX to pin 4 and TX to pin 5 or change the data in the program to 10 and 11 ...

If this still does not work please post the code you used (in code tags).

Good luck!
ec2021

BTW: You might be interested in this page for further information:

https://wolles-elektronikkiste.de/en/arduino-controlled-dfplayer-mini

Thanks for responding to help! I changed the sample code to 10,11 and it didn't change my result. Not sure what else could be up. Any ideas?

/***************************************************
DFPlayer - A Mini MP3 Player For Arduino
 <https://www.dfrobot.com/product-1121.html>
 
 ***************************************************
 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 "DFRobotDFPlayerMini.h"

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

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

void setup()
{
#if (defined ESP32)
  FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
  FPSerial.begin(9600);
#endif

  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(FPSerial, /*isACK = */true, /*doReset = */true)) {  //Use serial 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(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 DFPlayerUSBInserted:
      Serial.println("USB Inserted!");
      break;
    case DFPlayerUSBRemoved:
      Serial.println("USB Removed!");
      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 compiled and uploaded your code and got this in the Serial Monitor

DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
DFPlayer Mini online.
Time Out!
DFPlayerError:Get Wrong Stack
Time Out!

However after the second "Time Out" message it starts playing the songs from the SD card (each for three seconds) one after another.

Do you get any of these messages?

I don't get those timeout messages. Mine never says DFPlayer Mini online..

Also, I tried copying that website exactly, same issue.

Per the code example on that website, here's the output

Thanks, I found an interesting issue:

A change of volume in setup() (line myDFPlayer.volume(10):wink: did not work. So I added a myDFPlayer.volumeUp(); after it ... and the code did no longer work at all :wink:

So I suspected that the DFPlayer requires some time after initialization and added a delay(500); before changing the volume et voila it worked:

  Serial.println(F("DFPlayer Mini online."));
  delay(500);
  myDFPlayer.volume(5);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3

It might be that your device's behavior is more time critical.

You can give it a try and add the delay as above ... (Just a guess).

P.S.: I had also a similar problem with the "FullFunction" sample code. After adding a delay behind "Serial.println(F("DFPlayer Mini online."));" it worked.

That is interesting. However, I never make it to Serial.println(F("DFPlayer Mini online.")); so I don't quite think that's the issue.

I wonder if I should try this on r3 instead of an r4...

I tested with an R3 clone ... If you have the chance you can at least find out whether it is specific to the R4.

wow, it works on the r3. So something is wrong this module working on the r4

You might check if SoftwareSerial works correctly with the R4.

Feel free to have a look here

https://forum.arduino.cc/t/uno-r4-wifi-not-detecting-gps-module-softwareserial/1158376/10

There may be a hint ...

Good luck!
ec2021

So the answer was to use pins 0 and 1 and Serial1 on the R4. Thanks so much!

1 Like

So I understand it's working now...

I have no personal experience with the R4 but a software driven serial should generally be no problem.

If you like you could try to remove this

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

by this (provided you use pins 10 and 11)

#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial

I am just curious if it depends on the #ifdef statements...

And if your problem has been solved please mark the relevant post as "solution" to signalized the state of your thread to other members.

Enjoy coding!
ec2021

BTW: You can find a lot of useful information for R4 specific features around this link

https://docs.arduino.cc/tutorials/uno-r4-wifi/cheat-sheet/

and finally I found some hints on R$ SoftwareSerial behavior here

https://github.com/arduino/uno-r4-library-compatibility/issues/12

+1 as I too am curious, On a UNO R3 @optikalefx's sketch worked OK.

Thanks for also testing on an UNO R3 like we did above!

However there seem to be (or at least have been ) issues with R4 SoftwareSerial (see the last link in post 12) ...

Did you also encounter problems with the DFPlayer sample code as I described in my post 6? I could handle it by giving a delay between myDFPlayer.begin() and the first command like myDFPlayer.volume(5). Without the delay the command was ignored by the DFPlayer.

Oddly, at first I did; I then added a delay(1000); after

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

It then played as expected. But I then reduced and finally removed the delay, uploaded again - and it still worked.

Note that we have not yet seen the code @optikalefx was unable to get working, so there's scope for ambiguity right there. FWIW here is the first part of what I use as the eight year old DFR 'Get Started' sketch, down to end of setup(), which I assume is what we have been discussing.

I've just run that sketch again on my Uno R3 and it ran correctly.

BTW, note also that I'm using version 1.0.5 of the library, as I believe there's some obscure bug in the latest 1.0.6. I doubt its relevance here but just in case. I posted about it here:

@optikalefx :
"When the arduino boots, I hear the speaker pop.."
My fix for that is to use this instead of the original:

if (!myDFPlayer.begin(mySoftwareSerial, true, false)) 
/***************************************************
DFPlayer - A Mini MP3 Player For Arduino
 <https://www.dfrobot.com/product-1121.html>

 ***************************************************
 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 "DFRobotDFPlayerMini.h"

#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266))   // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif

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

void setup()
{
#if (defined ESP32)
  FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
  FPSerial.begin(9600);
#endif

  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(FPSerial, /*isACK = */true, /*doReset = */true)) {  //Use serial 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(10);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

Yea in Post #7 I mentioned that it wasn't applicable because mine never makes it to Serial.println(F("DFPlayer Mini online.")); to where the delay would be used. I did add a delay anyway and it didn't change anything.

It seems SoftwareSerial does not work with the R4. I can't get any combination of pins to work. Only hardware serial Serial1 0,1 I can get working.

Thanks for your hint regarding the third parameter in myDFPlayer.begin()!

Yesterday I emailed DFROBOT and informed them about two mistakes on their page

https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299#target_7

  • In the sample code RX/TX pins 4 and 5 were used while pins 10 and 11 are wired in the diagram.
  • There was a wrong note beyond the diagram regarding the 1k resistor (which protects the 3.3V IO of the DFPlayer from 5V):

They were very responsive and changed both immediately in the linked page!

ec2021