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 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.
/***************************************************
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;
}
}
A change of volume in setup() (line myDFPlayer.volume(10) did not work. So I added a myDFPlayer.volumeUp(); after it ... and the code did no longer work at all
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.
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.