Using DFRobot DFMini Player with Arduino Mega

Hi everyone,
Apologies for cross-posting. I have posted this on the Audio Topic but have not had any reply. I thought I would try here. Please note I am not an expert and make a lot of silly mistakes, learning as I go.
I am have trouble connecting a DFRobot Mini Mp3 player to an Arduino Mega board. I have the following code:

#include "DFRobotDFPlayerMini.h"

DFRobotDFPlayerMini myDFPlayer;

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(Serial1)) {  //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(10);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop()
{
  
}

And have connected the Arduino and the MP3 player as follows:

Arduino Mega DFMiniPlayer:
5VCC------------------------------> VCC
GND-------------------------------> GND
RX---------------------------------->pin 18 TX
TX---------------------------------->pin 19 RX

Speaker DFMiniPlayer:
SPK1------------------------------>SPK1
SPK2------------------------------>SPK 2

I am using a FAT32 32GB SD Card.



Any assistance will be greatly appreciated!
Sarina

@sarinacm I have closed your other topic

Please do not create duplicate topics. The other one could have been moved here instead

so sorry !

I have tried with another library and still no luck. Any help will be greatly appreciated!


DFPlayerMini_Fast myMP3;

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

  Serial.println(myMP3.begin(Serial1));

  if(!myMP3.begin(Serial1))
  {
    Serial.println("Not working");
  }
  
  Serial.println("Setting volume to max");
  myMP3.volume(30);
  delay(20);
  
  Serial.println("Playing track 1 for 5 sec");
  myMP3.play(1);
  delay(5000);

  Serial.println("Sleeping for 5 sec");
  myMP3.sleep();
  delay(5000);

  Serial.println("Waking up");
  myMP3.wakeUp();

  Serial.println("Looping track 1");
  myMP3.loop(1);
}

void loop()
{
  //do nothing
}```

I get the following output but no sound

17:16:58.618 -> 1
17:16:58.618 -> Setting volume to max
17:16:58.664 -> Playing track 1 for 5 sec
17:17:03.651 -> Sleeping for 5 sec
17:17:08.641 -> Waking up
17:17:08.641 -> Looping track 1

Hi Delta_G

Thank you so much for your reply, I see that in my frazzled state, I did not add what is not working, my sincere apologies. In short, nothing is working . The DFplayer is not initialising no matter what I do. I am pretty sure that I have watched every Youtube video and read most of the Forum posts and still no luck. I just end up with the Unable to begin message being printed to the serial monitor. I am using the DFRobot DFR0299 mini MP3 player and a 50MM 40HM 3W speaker. I have no idea where I am going wrong. Like I said, I have a lot to learn and would genuinely appreciate any help.

Sarina

You need to include the SoftwareSerial library. I'm using a UNO but I edited your code and it now works fine:

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

SoftwareSerial mySerial(8, 9); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

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

  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  if (!myDFPlayer.begin(mySerial))
  {
    //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(20);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop()
{

}

But I've found it reliable in several projects, including a JukeBox managing nearly 3,000 files over 26 folders.

Possibly more important for sarinacm, it works!

  1. As you'll have seen, I successfully use SoftwareSerial on my UNOs. But although I'm therefore unfamiliar with Hardware Serial, if you want tol stick with it then then shouldn't the string 'HardwareSerial' at least appear somewhere in your code.

  2. A 40 ohm speaker and a volume setting of 10 would be pretty quiet. I typically use the recommended 8 ohm types, and a volume of 20.

  3. I've tried several libraries, including your latest, but found the original DFR library the most versatile - and much better documented than DFPlayerMini_Fast. BTW, I assume you have included it, although not shown in your code?

  4. What was the source of your first sketch?

  5. I agree with @Delta_G about TX/Rx appearing to be reversed.

  6. I note you haven't included a 1K resistor from PC TX to module RX.

But I would think the "managing" does?

Hi Terrypin and Delta_G,

For starters, I cannot tell you both how much I appreciate your assistance, I genuinely do.

I have switched the RX and TX cables around many times. I have also tried the different RX and TX pins on my board as well as another identical MP3 mini.

I have also tried with and without the resistor. I am stumped. I can rewire everything tomorrow and take detailed photos ( I am from South Africa, there is a rather large time delay, so sorry for the delays in my reply). Maybe you can then spot whatever I am doing wrong.

I agree on rather using the hardware serial, it has proven to be a lot faster for my ESP8266 wifi module and a lot more stable.

Is am sure I am doing something silly, I just cant seem to figure it out.

Sarina

And points 2, 4 & 6 of my post #13?

Have you now corrected Tx/Rx? Which library are you now using?

Please show your latest code.

Edit:
7. Are you confident about your file organisation on the micro-SD? The module is very fussy. From your play command I assume you have a file named 0001.mp3 (or WAV, or WMA) , or 0001xxxxwhatever.mp3. Either in the root or within a folder called mp3.

With your volume at 20 (and ideally an 8 ohm speaker), if the file is correctly named and organised, if you still near nothing then format the mSD and reload the file(s), and try again.

BTW, I assume you have successfully played the file from the mSD directly in a player program?

Serial1 -- pins 18,19


#include "DFRobotDFPlayerMini.h"

DFRobotDFPlayerMini myDFPlayer;

void setup() 
{
  Serial.begin(9600);
  myDFPlayer.begin(Serial1, true);

  // Serial.println(myDFPlayer.begin(Serial1));
  if(!myDFPlayer.begin(Serial1))
  {
   Serial.println("Problem");
   while (true);
  }

  if(myDFPlayer.begin(Serial1))
  {
    Serial.println("Good");
  }
}

void loop ()
{
  myDFPlayer.play(1); // a brief track
  delay(5000);
}

Curses - it's Not Happening.

OK - nevermind the preceding.
Fixed It.
Verified, 100% --

#include "DFRobotDFPlayerMini.h"

DFRobotDFPlayerMini myDFPlayer;

void setup() 
{
  Serial.begin(9600);
  Serial1.begin(9600);
  delay(2500);
  myDFPlayer.begin(Serial1, true);

  Serial.println(myDFPlayer.begin(Serial1));
  if(!myDFPlayer.begin(Serial1))
  {
   Serial.println("Problem");
   while (true);
  }

  if(myDFPlayer.begin(Serial1))
  {
    Serial.println("Good");
  }
}

void loop ()
{
  myDFPlayer.play(1); // a brief track, but may drive you nuts
  delay(5000);
}

Dear Runaway_pancake,

Thank you so very much for this, it has helped me a lot. I now have this:

(Apologies for the video, i just did not how to describe the sound)
Do you mind me asking why you added the delay ?

I have copied and pasted your code and upped the volume. So something is working but I cant hear the music. Is it the speaker ?


DFRobotDFPlayerMini myDFPlayer;

void setup() 
{
  Serial.begin(9600);
  Serial1.begin(9600);
  delay(2500);
  myDFPlayer.begin(Serial1, true);

  Serial.println(myDFPlayer.begin(Serial1));
  if(!myDFPlayer.begin(Serial1))
  {
   Serial.println("Problem");
   while (true);
  }

  if(myDFPlayer.begin(Serial1))
  {
    Serial.println("Good");
  }
}

void loop ()
{
  myDFPlayer.volume(30);
  myDFPlayer.play(1); // a brief track, but may drive you nuts
  delay(5000);
}```

Again , thank you so much!

Dear Delta_G , thank you so much for your help. I have posted further down that I have made some progress and shared a video. I just wanted to reply directly to say thank you.
Sarina

Dear Terrypin,
Thank you so much for your help so far , just wanted to reply directly to say thank you .

Appreciate your politeness, but would prefer to get replies to my outstanding points from yesterday!
:slightly_smiling_face:

I see you've made progress but we might be able to help resolve outstanding questions with fuller information.

Meanwhile, I successfully ran @runaway_pancake's sketch after editing it for my UNO. So I would use it as the basis for your further diagnostics.

Hi Again, apologies, here you go
2. A 40 ohm speaker and a volume setting of 10 would be pretty quiet. I typically use the recommended 8 ohm types, and a volume of 20.
--> I don't think I have an 8 ohm on hand. I did change the volume to 30 in the last sketch. This is the exact speaker I am using :

3. I've tried several libraries, including your latest, but found the original DFR library the most versatile - and much better documented than DFPlayerMini_Fast. BTW, I assume you have included it, although not shown in your code?
--> I have yes, I have also tried quite a few libraries, I initially started with the official library from DFRobtot.
4. What was the source of your first sketch?
---> I am not sure I understand the question, the first sketch I ever used was the sketch provided by DFRobot: DFPlayer Mini Mp3 Player - DFRobot Wiki
5. I agree with @Delta_G about TX/Rx appearing to be reversed.
-----> There is a lot of information on the internet, I tried so many things , I have swapped these but have tested many configurations and they all failed.
6. I note you haven't included a 1K resistor from PC TX to module RX.
-----> I have tested with and without the resistor several times , I have added the resistor in my last test with the code from @runaway_pancake . I sometimes battle a bit with breadboard and then soldering everything in place to add to the smartquilt (long story) so it is easier to work without a bread board but harder to work with a resistor, the jumper cable jacks can be real finicky.

Hope this clears it up.
Sarina

Thanks Sarina.

DFR gave no example using Hardware Serial so I was just wondering if you copy/pasted it from some other source.

So you have a 4 ohm speaker, not 40 ohm. That should be OK.

And the other points, from my post #18? Here they are again:


I can't offer much after watching your video, except that there may be a power supply issue. Assuming two things:

  1. You're now using runaway_pancakes sketch in every detail
  2. You've eliminated the obvious by confirming that you can play file 0001.mp3 in your media player

Then try adding a small (6.8/10/22 ohm) resistor in series with the speaker.

And/or try powering the DFR module (and therefore the speaker) with an independent supply between 4.5 - 5.0 V.

Here is my code


DFRobotDFPlayerMini myDFPlayer;

void setup() 
{
  Serial.begin(9600);
  Serial1.begin(9600);
  delay(2500);
  myDFPlayer.begin(Serial1, true);

  Serial.println(myDFPlayer.begin(Serial1));
  if(!myDFPlayer.begin(Serial1))
  {
   Serial.println("Problem");
   while (true);
  }

  if(myDFPlayer.begin(Serial1))
  {
    Serial.println("Good");
  }
}

void loop ()
{
  myDFPlayer.volume(30);
  myDFPlayer.play(1); // a brief track, but may drive you nuts
  delay(5000);
}

Yes I can play the MP3 straight from the SD Card on my laptop , I will give the resistor a try, I only have 1k resistors with me but should have some others at work.

yeah they don't offer a hardware serial option, I learned about the hardware serial when I was setting up an API using ESPWifi and the ESP8266 wifi module , so just adapted the code.
One again, thank you very much for your help.
Thank you again.