@bassweasel
I've used DFRobot Extensively
I'll give you a code that works and some instructions to follow
-
This code is based on the basic code that you'll get from the DFRobot website.
However that code is really seriously lacking in accuracy when it comes to troubleshooting the DFRobot Player mini
-
so i decided to add a few more troubleshooting features of my own, and i'll explain them to you and what they mean and what they prove at each step.
Feel free to get rid of anything that you don't want, this worked for me , it may not be something you need or want.
-
First of all, Here is the code, Insert it as appropriate into your code
#include <Arduino.h> //Arduino Base Library
#include <DFRobotDFPlayerMini.h> //Controls DFRobot MP3 Player (Audio)
#include <SoftwareSerial.h> // Software Serial Library
SoftwareSerial mySoftwareSerial(17, 16); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
/*/////////////////////////////////////////////////////////////////////////////////////////
BEGIN SETUP
*//////////////////////////////////////////////////////////////////////////////////////////
void setup()
{ // OPENS void setup Function
//-----------------------------------------------------------------------------------------
// BAUD Rate Setup
//-----------------------------------------------------------------------------------------
mySoftwareSerial.begin(9600); // Setup of Serial BAUD Rate for DFRobot Player
Serial.begin(115200); // Setup of Serial BAUD Rate for serial Monitor
//-----------------------------------------------------------------------------------------
// Audio Initialization Sequence - Serial Monitor Output
//-----------------------------------------------------------------------------------------
Serial.println();
Serial.println(F("WELCOME - DFROBOT PLAYER DEMO"));
Serial.println(F("PLEASE WAIT - INITIALIZING DFROBOT PLAYER "));
//-----------------------------------------------------------------------------------------
// IF ERROR - Serial Monitor Output
//-----------------------------------------------------------------------------------------
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println(F("ERROR - MP3 SOMETHING IS WRONG - TROUBLESHOOT:"));
while (true);
}
//-----------------------------------------------------------------------------------------
// IF NO ERROR - Serial Monitor Output
//-----------------------------------------------------------------------------------------
Serial.println(F("AUDIO ONLINE - DFROBOT PLAYER STARTED SUCCESSFULLY"));
//-----------------------------------------------------------------------------------------
// SET THE OVERALL SYSTEM VOLUME
//-----------------------------------------------------------------------------------------
myDFPlayer.volume(25); // Value = From 0 to 30
///////////////////////////////////////////////////////////////////////////////////////////
Serial.println(F("================================================================"));
Serial.println(F(" READING SD CARD ATTRIBUTES"));
Serial.println(F("================================================================"));
Serial.print(F(" - READ STATE = "));
Serial.print(myDFPlayer.readState()); //read mp3 state . Reading or Not Reading
value = myDFPlayer.readState();
Serial.println(F(" (1 = Reading/ 0 = NOT Reading)"));
//-----------------------------------------------------------------------------------------
Serial.print(F(" - STORAGE VOLUME CAPACITY = "));
Serial.print(myDFPlayer.readVolume()); //read current volume capacity
Serial.print(F(" MB"));
Serial.println(F(""));
//-----------------------------------------------------------------------------------------
Serial.print(F(" - READ FILE COUNTS "));
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card //Produces 0
value = myDFPlayer.readFileCounts(); //read all file counts in SD card
//-----------------------------------------------------------------------------------------
Serial.print(F(" - READ CURRENT FILE NUMBER "));
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
value = myDFPlayer.readCurrentFileNumber();
//-----------------------------------------------------------------------------------------
Serial.print(F(" - readFileCountsInFolder"));
Serial.println(myDFPlayer.readFileCountsInFolder(1)); //read file counts in folder SD:/03 PRODUCES ERROR
Serial.println(F("================================================================"));
Serial.println(F("================================================================"));
Serial.println(F(" BEGINNING SOUND SEQUENCE"));
Serial.println(F("================================================================"));
Serial.println(F(" - DETAILS :"));
Serial.println("AUDIO ONLY - Started");
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// SOUND SEQUENCE
myDFPlayer.playMp3Folder(3); // Play MP3 File (0003)
//delay(3);
Serial.println("AUDIO ONLY - Completed");
//-----------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
} // CLOSES void setup Function
///////////////////////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////////////////////
BEGIN LOOP
*//////////////////////////////////////////////////////////////////////////////////////////
void loop()
{ // OPENS void loop Function
} // CLOSES void loop Function
///////////////////////////////////////////////////////////////////////////////////////////
Most of it is self Explanatory
- Before we go into the explanation of the code Understand this.
-
check out this link for the pinouts for DFRobot Player Mini Useful info.
-
You now want to hook up the Rx and Tx lines to the data pins of your arduino.
In my sketch i am using the library "Software Serial" if you are using ESP32 you
can consider using the inbuilt Hardware Serial Pins
-
NOW LET ME EXPLAIN WHAT THE CODE DOES...
it should be straight forward to drop everything into it's correct place
but let me explain anyway....
FIRST THE PRE SETUP (GLOBAL SECTION)
These are the included libraries that go right at the top
Arduino controls the board
DFRobotPlayerMini.h is the MP3 player library
NOW PAY ATTENTION TO THIS....
SoftwareSerial.h controls the Serial Transmission between the Arduino Dev board
and the Rx and Tx Pins on your DFRobot Player
DO NOT CONFUSE THIS FOR THE SERIAL COMMUNICATION ON SERIAL MONITOR
it has nothing to do with that .
#include <Arduino.h> //Arduino Base Library
#include <DFRobotDFPlayerMini.h> //Controls DFRobot MP3 Player (Audio)
#include <SoftwareSerial.h> // Software Serial Library
This sets up softwareserial.h as being referred to by the object name of "mySoftwareSerial" and defines the data pins (change these to suit your pin needs)
it also sets up your DFRobot Player for later use
SoftwareSerial mySoftwareSerial(17, 16); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
Now we start the SETUP Function
Here we setup the BAUD Rates for the DFRobot Player and the Serial Monitor
as indicated in the comments
/*/////////////////////////////////////////////////////////////////////////////////////////
BEGIN SETUP
*//////////////////////////////////////////////////////////////////////////////////////////
void setup()
{ // OPENS void setup Function
//-----------------------------------------------------------------------------------------
// BAUD Rate Setup
//-----------------------------------------------------------------------------------------
mySoftwareSerial.begin(9600); // Setup of Serial BAUD Rate for DFRobot Player
Serial.begin(115200); // Setup of Serial BAUD Rate for serial Monitor
//-----------------------------------------------------------------------------------------
NOW THIS PART IS GOING TO HELP YOU TROUBLESHOOT
If you run Serial Monitor and DO see this message upon system
startup then :
- This does not mean that your DFRobot Player actually started.
- it Just proves that your baud rate and serial library is working as well your print
statements,
Seeing this has absolutely not relevance to the DFRobot player.
//-----------------------------------------------------------------------------------------
// Audio Initialization Sequence - Serial Monitor Output
//-----------------------------------------------------------------------------------------
Serial.println();
Serial.println(F("WELCOME - DFROBOT PLAYER DEMO"));
Serial.println(F("PLEASE WAIT - INITIALIZING DFROBOT PLAYER "));
//-----------------------------------------------------------------------------------------
If you run Serial Monitor and DO NOT see this message upon system
startup then you need to do the following :
- check Power to the Dev Board
- Check that your baud rates are correct and that serial monitor has the correct Baud
Rate
- Check that the library is installed
Now is the point where the Rx and Tx pins are going to have data going over them
and an attempt to communicate with the DFRobot will actually happen
//-----------------------------------------------------------------------------------------
// IF ERROR - Serial Monitor Output
//-----------------------------------------------------------------------------------------
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println(F("ERROR - MP3 SOMETHING IS WRONG - TROUBLESHOOT:"));
while (true);
}
//-----------------------------------------------------------------------------------------
now.. if the Attempt is NOT SUCCESSFUL, this message will occur
if you are seeing this. You do not need to troubleshoot as before, as seeing this
message PROVES that the serial stuff is setup,
There may however be a problem with the SoftwareSerial.h library though
or the code or the MP3 player could be faulty
-
TOUCH THE METAL CASING AND SEE IF IT'S HOT
if it is , you've created a short circuit
-
check voltage on the DFRobot Between GND and Vcc for Presence of 5V DC
-
check with an Oscilloscope if there is any Data Transmission going down your
Rx and Tx Pins
Verify this both at the DFRobot end and at the Dev board end, Maybe the Dev board
is not sending the signal or is faulty
NOW, IF THERE IS NO ERROR this will happen
//-----------------------------------------------------------------------------------------
// IF NO ERROR - Serial Monitor Output
//-----------------------------------------------------------------------------------------
Serial.println(F("AUDIO ONLINE - DFROBOT PLAYER STARTED SUCCESSFULLY"));
//-----------------------------------------------------------------------------------------
this DOES NOT mean that it started successfully and fully.
it merely means and proves
-
there is a Data signal going to the DFRobot Player and it has been received Successfully.
-
it doesn't necessarily prove that audio can play
-
at this point you want to ensure that you do actually have A SPEAKER ATTACHED.
to SPK+ and SPK- on the DFRobot Player
it is as this point where the code on the DFRobot site will stop and give you the illusion
that everything is now working BUT IT'S NOT
What could happen from here to still be faulty
- speaker could not be attached
- SD Card could be Faulty
- SD Card could be formatted incorrectly
- DFRobot Player could have a fault with playing the file
- The file could be in the wrong place and the code doesn't know how to find it
etc etc...
so i have now implemented a few things that absolutely prove that it works
First. I set the system volume
//-----------------------------------------------------------------------------------------
// SET THE OVERALL SYSTEM VOLUME
//-----------------------------------------------------------------------------------------
myDFPlayer.volume(25); // Value = From 0 to 30
Now... READ STATE
a value of -1 or 1 means that it has read the data on the SD Card
a value of 0 means it cannot read the data, You may have a corrupted file or faulty SD Card
///////////////////////////////////////////////////////////////////////////////////////////
Serial.println(F("================================================================"));
Serial.println(F(" READING SD CARD ATTRIBUTES"));
Serial.println(F("================================================================"));
Serial.print(F(" - READ STATE = "));
Serial.print(myDFPlayer.readState()); //read mp3 state . Reading or Not Reading
value = myDFPlayer.readState();
Serial.println(F(" (1 = Reading/ 0 = NOT Reading)"));
//-----------------------------------------------------------------------------------------
This one is not yet perfected and not definitive but it does prove something.
Here you are using the READ VOLUME command. it's supposed to read
the volume capacity of your SD Card (to my knowledge)
i used it on a 64GB Card and it returns the value of 512
i have included a text line so that it reads 512MB
if you get that , it is literally reading the card attributes and the fact that your
card returns the values gives another level of confirmation that it works.
If you get a value of 0 Your card has failed to provide attribute information.
Possible Faulty DFRobot or SD Card
//-----------------------------------------------------------------------------------------
Serial.print(F(" - STORAGE VOLUME CAPACITY = "));
Serial.print(myDFPlayer.readVolume()); //read current volume capacity
Serial.print(F(" MB"));
Serial.println(F(""));
//-----------------------------------------------------------------------------------------
Next...
let's cover 3 in 1
the idea here is that it's going to interrogate the SD Card and count how many
files you have in it
which one gives you a value will depend if you have it in root or in the mp3 folder.
read file counts if if you have it in root
read file counts in folder is if it's in the folder
read current file number is not yet perfected , i'm still working on it, You can remove
it if you like.
//-----------------------------------------------------------------------------------------
Serial.print(F(" - READ FILE COUNTS "));
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card //Produces 0
value = myDFPlayer.readFileCounts(); //read all file counts in SD card
//-----------------------------------------------------------------------------------------
Serial.print(F(" - READ CURRENT FILE NUMBER "));
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
value = myDFPlayer.readCurrentFileNumber();
//-----------------------------------------------------------------------------------------
Serial.print(F(" - readFileCountsInFolder"));
Serial.println(myDFPlayer.readFileCountsInFolder(1)); //read file counts in folder SD:/03 PRODUCES ERROR
Serial.println(F("================================================================"));
so at the end of all this...
You have serial monitor output that starts the troubleshooting
You know you've setup serial stuff correctly
You know that Rx and Tx lines are communicating
You know that no error occurred
You have file attributes and file information displayed to you therefore
DFRobot player is communicating with the board
and the SD Card is functioning and setup properly
You now just need Audible confirmation of the file playing
Serial.println(F("================================================================"));
Serial.println(F(" BEGINNING SOUND SEQUENCE"));
Serial.println(F("================================================================"));
Serial.println(F(" - DETAILS :"));
Serial.println("AUDIO ONLY - Started");
///////////////////////////////////////////////////////////////////////////////////////////
Getting this message just means IT'S ATTEMPTING TO PLAY THE FILE
then this happens
///////////////////////////////////////////////////////////////////////////////////////////
// SOUND SEQUENCE
myDFPlayer.playMp3Folder(3); // Play MP3 File (0003)
//delay(3);
Serial.println("AUDIO ONLY - Completed");
//-----------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
the line
myDFPlayer.playMp3Folder(3);
Plays your file number 0003.mp3 IF IT'S IN A FOLDER CALLED mp3 (Case Sensitive)
if its' in root, you do this
myDFPlayer.play(3);
if you get to this line
Serial.println("AUDIO ONLY - Completed");
and you didn't hear Audio
- Check speaker connection
- check voltage to DFRobot
- Check system volume
- Check the file number in the code is correct and exists
At this stage there should be almost no reason that the file wouldn't play
Beyond that, You can put some of this stuff in the Loop Function if you need it to repeat.
Let me know if you have any questions