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:
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.
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.
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'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?
What was the source of your first sketch?
I agree with @Delta_G about TX/Rx appearing to be reversed.
I note you haven't included a 1K resistor from PC TX to module RX.
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.
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?
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
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.
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.