I'm using an esp32 and a DFRobot DFPlayer Mini mp3 player with module library (GitHub - DFRobot/DFPlayer-Mini-mp3). I put the mp3 files on the sd card and I can play when I type "a" on the serial monitor (using the library's next() function), but I can't use the "play()" function. I put play(1) to play the first file, or play(2) for the second and etc but it doesn't work. Has anyone had a similar problem?
Here is my code:
#include <Arduino.h>
#include "DFRobotDFPlayerMini.h"
HardwareSerial mySerial(1);
int i = -1;
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
mySerial.begin(9600, SERIAL_8N1, 18, 19);
Serial.begin(115200);
Serial.println();
Serial.println(F("Starting DFPlayer module ..."));
if (!myDFPlayer.begin(mySerial)) {
Serial.println(myDFPlayer.readType(), HEX);
Serial.println(F("Error starting, check:"));
Serial.println(F("1.The module connection."));
Serial.println(F("2.If the SD card was inserted correctly."));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.setTimeOut(500);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
Serial.print(F("Files found on SD card: "));
Serial.println(myDFPlayer.readFileCounts(DFPLAYER_DEVICE_SD));
myDFPlayer.EQ(0);
myDFPlayer.play(1);
}
void loop()
{
char choice = Serial.read();
if (choice == 'p')
{
Serial.println(F("---Play---"));
myDFPlayer.start();
delay(10);
}
if (choice == 's')
{
Serial.println(F("---Stop---"));
myDFPlayer.stop();
delay(10);
}
if (choice == '+')
{
myDFPlayer.volumeUp();
Serial.println("---Turn up the volume---");
}
if (choice == '-')
{
Serial.println("---Reduce the volume---");
myDFPlayer.volumeDown();
}
if (choice == 'a')
{
Serial.println("---Advance---");
myDFPlayer.next();
Serial.print(myDFPlayer.readCurrentFileNumber());
Serial.print('/');
Serial.println(myDFPlayer.readFileCounts());
}
if (choice == 'r')
{
Serial.println("---Reced---");
myDFPlayer.previous();
Serial.print(myDFPlayer.readCurrentFileNumber());
Serial.print('/');
Serial.println(myDFPlayer.readFileCounts());
}
if (choice == 't')
{
i += 1;
Serial.println("---Test---");
myDFPlayer.loopFolder(i);
Serial.println(i);
Serial.print(myDFPlayer.readCurrentFileNumber());
Serial.print('/');
Serial.println(myDFPlayer.readFileCounts());
Serial.println(myDFPlayer.readFolderCounts());
}
if (choice == 'y')
{
i += 1;
Serial.println("---Test2---");
myDFPlayer.playFolder(i, 0);
//myDFPlayer.start();
Serial.println(i);
Serial.print(myDFPlayer.readCurrentFileNumber());
Serial.print('/');
Serial.println(myDFPlayer.readFileCounts());
Serial.println(myDFPlayer.readFolderCounts());
}
if (choice == 'f')
{
myDFPlayer.play(1);
Serial.println("test1");
}
if (choice == '0')
{
myDFPlayer.EQ(0); //0 - Normal
Serial.println("---Equalizer: Normal---");
}
if (choice == '1')
{
myDFPlayer.EQ(1); //1 - Pop
Serial.println("---Equalizer: Pop---");
}
if (choice == '2')
{
myDFPlayer.EQ(2); //2 - Rock
Serial.println("---Equalizer: Rock---");
}
if (choice == '3')
{
myDFPlayer.EQ(3); //3 - Jazz
Serial.println("---Equalizer: Jazz---");
}
if (choice == '4')
{
myDFPlayer.EQ(4); //4 - Classic
Serial.println("---Equalizer: Classic---");
}
if (choice == '5')
{
myDFPlayer.EQ(5); //5 - Bass
Serial.println("---Equalizer: Bass---");
}
}
What does the output of setup() look like? it should display your file count as well as when you use 'a'.
You should also blindly read the serial port, even if nothing is there and you might want to look into the switch() statement since only one of your many if() statements can possibly be true on any given run through loop()
NOTE: If you are using Mac OS X to copy the mp3, the file system will automatically add hidden files like: "._0001.mp3" for index, which this module will handle as valid mp3 files. It is really annoying.
17:54:40.934 -> Starting DFPlayer module ...
17:54:42.011 -> DFPlayer Mini online.
17:54:42.245 -> Files found on SD card: -1
17:54:49.844 -> ---Advance---
17:54:49.938 -> -1/1
It displays "-1" as mp3 total. But there are about 9 mp3s in the "MP3" folder on the SDCARD, all renamed as "0001", "0002". I don't know the reason for the "-1"...
However, when advancing the track, it plays exactly "-1".
I tested this code with the new library you gave me, it doesn't play anything, not even using next() and it also shows "-1"...
18:02:23.726 -> File found in SD: Sent Stack:
18:02:23.773 -> 7E FF 6 48 0 0 0 FE B3 EF
18:02:23.773 ->
18:02:23.867 -> timeout error
18:02:23.867 -> -1
18:02:23.867 -> Setting volume to max
18:02:23.867 -> Sent Stack:
18:02:23.867 -> 7E FF 6 6 0 0 1E FE D7 EF
18:02:23.867 ->
18:02:23.867 -> Sent Stack:
18:02:23.867 -> 7E FF 6 12 0 0 1 FE E8 EF
18:02:23.867 ->
18:02:28.870 -> Looping track 1
18:02:28.870 -> Sent Stack:
18:02:28.870 -> 7E FF 6 8 0 0 1 FE F2 EF
18:02:28.870 ->
How are you powering this? You set your volume to max so it will draw the maximum current and if your power supply can't deliver, you won't get any audio out. You could test setting it to a much lower value.
It also looks like you are getting a timeout error so did you wire it up correctly? The _fast library allows you to increase the timeout period.
I changed the volume and turned it down, I also set a longer timeout, but it still doesn't work. Using the original library( GitHub - DFRobot/DFRobotDFPlayerMini: Arduino library for DFPlayer ) I also get the "-1" return on the number of tracks, but as I go forward, the tracks are played. I really don't know what it could be...
The tracks are in the mp3 folder at the root of the sdcard, named as "0001.mp3, 0002.mp3".
You still have not answered any of the power related questions? How are you powering all this? How are you dealing with 3.3V ESP32 vs a 5V DFPlayer? A schematic would be very helpful.
reiterating, next() works, sound is played. What doesn't work is play(), playFolder() and playMp3Folder(). I really don't know what it can be anymore...
I have got to think its the nomenclature you have named the .mp3 files. You are using the correct DF Mini Fast library. Take a deep dive into that SD card and look at them. I found that some of my files I would put in as 0001.mp3 - but the SD would recognize that file and give it ANOTHER .mp3 extension- making the file name:
0001.mp3.mp3
Try to just put them in as 0001, 0002,. 0003 etc. with no .mp3 extension. I would think that next() would work right now but if you call for a specific file to play() and it can't find the nomenclature it freezes up as it doesn't know what to look for.
Also, try to get the example.ino code in the DF Mini Fast library working first- that would be the simplest way to determine the above hypothesis. If it works on the first time then the nomenclature is correct- if it doesn't then you can almost be sure its a file extension/naming problem.
I tried to remove the .mp3 extensions from the files and it doesn't even recognize it anymore.
I tried running example.ino and it didn't really work. The way out is this:
10:21:34.511 -> OK
10:21:35.537 -> Setting volume to max
10:21:35.537 -> Sent Stack:
10:21:35.537 -> 7E FF 6 6 0 0 14 FE E1 EF
10:21:35.537 ->
10:21:35.537 -> Looping track 1
10:21:35.537 -> Sent Stack:
10:21:35.537 -> 7E FF 6 8 0 0 1 FE F2 EF
10:21:35.537 ->
How long are the length of these .mp3 files? If they are 7.69 kb, 12.4 kb, 8.92 kb, etc. I assume they are very short sound files. Could you try a longer file- like a regular song in .mp3 format and see if that works?
Also I like @er_name_not_found suggestion to try a seperate power source for the DF mini player- at 3.3v you're maxing out the power. It seems weird that that would affect it as its doing the next() command but not the play() but its possible that could be an issue. Worth a shot.
Ever have the battery start to run down on a model car and it will drive but not if you turn on the headlights? It just seems that some functions may just require more wattage than others.
It will run on 3.3V but it likes 4.2V and if you turn up the volume you are drawing >3W so best to allow at least 1A.
Excellent example. I was trying to word that and couldn't express it correctly. I know I use a lot of knockoff DF Mini Players from Amazon and AliExpress and they always use more voltage than the genuine DF Mini from DFRobot.
Out of curiosity I put "0" in playMp3Folder() and played track 1. Then I added a function to print possible errors and when I send "f" to the serial monitor, track 1 plays but the following error appears:
Think of what you're doing when you search for a track:
First the player is probably already running
So it's drawing power for the amp, the decoder, and the SD
Then you ask it to look for another track which it's happy to switch to as soon as it finds it, but in the mean time it will continue to do its current thing and draw more power to look for the track on other places on the SD card
It might just run out of energy before you run out of requirements for it.
You are already halfway closer to solving this than most of the people who ask this same question as you are willing to try a recommended path. Please remember that 5V doesn't guarantee you 3W, you still need to be sure it's at least 1A and more amps are better as it will only consume what it needs provided you keep it under 5V.
This 5V brick says it's 2A / 1.5A but I just consider the top 1/3 to be the angel's share, so to me this is a 5V 1A power supply, because I'm only interested in how much power it can deliver all day long.
Like I said before though, amateur advice.
If I've misspoken though I have no doubt that I'll be corrected