I am currently trying to connect an esp32 to the DFPlayer mini, but i am unable to get a connection to the DFPlayer.
However I am able to play music with the Arduino UNO in the following setup:
with RX resistor (1k, 10k, 100k) and (1k + 680Ohm, as seen in picture)
The following code returns "Connecting to DFPlayer Mini failed!".
I am 100% sure i connected everything right, as it is working with a specific setup on the arduino.
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 10; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 11; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Create the Player object
DFRobotDFPlayerMini player;
void setup() {
// Init USB serial port for debugging
Serial.begin(9600);
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) {
Serial.println("OK");
// Set volume to maximum (0 to 30).
player.volume(30);
// Play the "0001.mp3" in the "mp3" folder on the SD card
player.playMp3Folder(1);
} else {
Serial.println("Connecting to DFPlayer Mini failed!");
}
}
void loop() {
}
Nothing works. I even had problems with the arduino. Non of the setups i found online, expect the one from the picture, worked.
Not working. I dont get an "Connecting to DFPlayer Mini failed!" error anymore.
But even if the player is physically not connected the code is not returning an error.
So i assuem its juts dissabling validation
// My edit of yours. Compiles & runs here, Thu 9 May 2024 12:17.
//#include "Arduino.h" // Redundant, so I usually omit.
#include "DFRobotDFPlayerMini.h"
//#include <SoftwareSerial.h> // You're no longer using it.
DFRobotDFPlayerMini myDFPlayer;
// void printDetail(uint8_t type, int value);
// I usually find that function and and its lengthy definition
// superfluous. Replace both later if you want.
void setup()
{
Serial2.begin(9600);
Serial.begin(115200);
delay(200); // My preference for print stability
// if (!myDFPlayer.begin(Serial1, /*isACK = */true, /*doReset = */true)) { //Use serial to communicate with mp3.
// What was your source of that? I've removed the test entirely for
// now, assuming your priority is getting it working.
if (!myDFPlayer.begin(Serial2)) {// Start communication with DFPlayer
// myDFPlayer.begin(Serial1, true, false); // Start communication with DFPlayer
Serial.println("ERROR");
}
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
delay(1000); // Add this to allow player to fully initialise
myDFPlayer.volume(15); //Set volume value. From 0 to 30
Serial.println("setup ended"); // I like this reassurance
}
void loop()
{
// myDFPlayer.play(001); // Ensure that your files have been renamed to 001, 002, etc.
myDFPlayer.play(1);
// Note: the 'name' is irrelevant to the module (but not to you,
// of course). That command plays the first file that was copied
// or moved to the uSD; chronologically. Could be called
// anything.
delay(5000); // If you actually want to hear anything each time
// through the loop! To hear entire tracks...another discussion.
}
ESP PIN 4 = TX -> Player RX
ESP PIN5 = RX -> Player TX
// My edit of yours. Compiles & runs here, Thu 9 May 2024 12:17.
//#include "Arduino.h" // Redundant, so I usually omit.
#include "DFRobotDFPlayerMini.h"
//#include <SoftwareSerial.h> // You're no longer using it.
DFRobotDFPlayerMini myDFPlayer;
#define RXD2 5
#define TXD2 4
// void printDetail(uint8_t type, int value);
// I usually find that function and and its lengthy definition
// superfluous. Replace both later if you want.
void setup()
{
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.begin(115200);
delay(200); // My preference for print stability
// if (!myDFPlayer.begin(Serial1, /*isACK = */true, /*doReset = */true)) { //Use serial to communicate with mp3.
// What was your source of that? I've removed the test entirely for
// now, assuming your priority is getting it working.
if (!myDFPlayer.begin(Serial2)) {// Start communication with DFPlayer
// myDFPlayer.begin(Serial1, true, false); // Start communication with DFPlayer
Serial.println("ERROR");
}
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
delay(1000); // Add this to allow player to fully initialise
myDFPlayer.volume(15); //Set volume value. From 0 to 30
Serial.println("setup ended"); // I like this reassurance
}
void loop()
{
// myDFPlayer.play(001); // Ensure that your files have been renamed to 001, 002, etc.
myDFPlayer.play(1);
// Note: the 'name' is irrelevant to the module (but not to you,
// of course). That command plays the first file that was copied
// or moved to the uSD; chronologically. Could be called
// anything.
delay(5000); // If you actually want to hear anything each time
// through the loop! To hear entire tracks...another discussion.
}
Did you read the thread, which was using a Mega 2560? Or just copy the code without change. My sketch used Serial 1 (pins 18/19) so you’d have to change for your board. If that’s an ESP32 why does your schematic show a UNO?
Also, I’m not clear which version of my sketch you used: the abbreviated one (without the test) or my EDIT? That is your original with my one line correction., so that does include the module test.