Hi, I'm working on a project to make an audio player that plays a specific song in a specific folder using DFPlayer Mini and Arduino Uno.
I want to have 10 button audio player where first 4 buttons are for selecting a folder and the other 6 buttons to play a specific audio in that given folder.
Here's my current code but doesn't seem to be working.
Can anyone help, please? Thanks!
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#define RX_PIN 10
#define TX_PIN 11
SoftwareSerial mySerial(RX_PIN, TX_PIN); // RX, TX
DFRobotDFPlayerMini player;
const int folderButtons[4] = {2, 3, 4, 5};
const int trackButtons[6] = {6, 7, 8, 9, 12, 13};
int selectedFolder = 1;
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(folderButtons[i], INPUT_PULLUP);
}
for (int i = 0; i < 6; i++) {
pinMode(trackButtons[i], INPUT_PULLUP);
}
mySerial.begin(9600);
if (!player.begin(mySerial)) {
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);
}
player.setTimeOut(500);
player.volume(20); // Set volume (0~30).
}
void loop() {
// Check folder buttons
for (int i = 0; i < 4; i++) {
if (digitalRead(folderButtons[i]) == LOW) {
selectFolder(i + 1);
delay(500); // Debounce delay
}
}
// Check track buttons
for (int i = 0; i < 6; i++) {
if (digitalRead(trackButtons[i]) == LOW) {
playTrack(i + 1);
delay(500); // Debounce delay
}
}
}
void selectFolder(int folderNumber) {
selectedFolder = folderNumber;
}
void playTrack(int trackNumber) {
player.playFolder(selectedFolder, trackNumber);
delay(10);
}
No useful information given.
What is happening and what is wanted to happen?
Schematics would make sure the hardware is properly designed.
Looks like you'll push through all of the tracks in folder 3, over and over.
Is that somewhat like what's going on ?
You haven't said what's not working. Nor shown any error messages.
However it does work here. The chosen track in the chosen folder plays to its end, and then there's silence. Is that what you intend?
I made only trivial changes* but I'll include my code just in case.
However, I was getting intermittent failures at the compiling and/or uploading stage. The error was something like 'AWT Event Exception'. Because of its inconsistency I'd have bet on it being a loose connection, but I haven't been able to reproduce it now, and research appears to attribute it to coding.
- I've just added one I don't regard as trivial.
if (!player.begin(mySerial, true, false)) // To eliminate speaker initial distortion
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#define RX_PIN 10
#define TX_PIN 11
SoftwareSerial mySerial(RX_PIN, TX_PIN); // RX, TX
DFRobotDFPlayerMini player;
const int folderButtons[4] = {2, 3, 4, 5};
const int trackButtons[6] = {6, 7, 8, 9, 12, A0};
int selectedFolder = 1;
void setup()
{
Serial.begin(115200);
delay(200);
for (int i = 0; i < 4; i++)
{
pinMode(folderButtons[i], INPUT_PULLUP);
}
for (int i = 0; i < 6; i++)
{
pinMode(trackButtons[i], INPUT_PULLUP);
}
mySerial.begin(9600);
if (!player.begin(mySerial, true, false)) // To eliminate speaker initial distortion
{
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);
}
player.setTimeOut(2000);
player.volume(20); // Set volume (0~30).
}
void loop()
{
// Check folder buttons
for (int i = 0; i < 4; i++)
{
if (digitalRead(folderButtons[i]) == LOW)
{
selectFolder(i + 1);
delay(500); // Debounce delay
}
}
// Check track buttons
for (int i = 0; i < 6; i++)
{
if (digitalRead(trackButtons[i]) == LOW)
{
playTrack(i + 1);
delay(500); // Debounce delay
}
}
}
void selectFolder(int folderNumber)
{
selectedFolder = folderNumber;
}
void playTrack(int trackNumber)
{
player.playFolder(selectedFolder, trackNumber);
delay(10);
}
Here's my schematics.
The problem is that no sounds comes out and nothing seems to happen even when I press buttons. Electrical connections seems to be fine when I checked with my volt-meter.
Is my schematic wrong? Any suggestions? Thanks!
Thanks, I'll try your code tonight and see if it works.
Can you share your schematic as well?
I've added my schematics, can you spot any issues or how things should be wired? Thanks!
that's a 1k resistor fyi.
My schematic is identical (although I use the module's other Gnd pin , between the speaker pins).
You still haven't given us some basic info:
-
Does it compile and upload without error?
-
Have you ever had sound from this module? Tried another DFR Player module?
-
Forgive the bleeding obvious: is your speaker working?
-
Are you sure your micro-SD card file structure is as specified? Show us a screenshot or directory listing. Format the card, using the Full not Quick option and copy your files back again. Not sure how much reading you've done, but in case you're not already painfully aware, the module is very fussy about the card contents and structure.
-
Does this statement at the end of setup() play OK?
player.playFolder(1, 1);
BTW, I've had no reocccurrence of that obscure error I had earlier.
And I've just run your original sketch successfully.
Thanks for your help. I finally managed to get it working last night.
There were 2 issues, bad DFPlayer and file naming.
After I switched to a different DFPlayer and renamed the files to 001, 002, etc it worked!
It wasn't the sketch or EE connections after all.
Thanks everyone for your help and comments!
Pleased to hear it.
With nothing else changed, have you now tried returning the original module? The wrong file structure alone might have been the sole cause.
how to send to folder number and track number to DF player via UART with a 32GB SD card which has 99 folder each with 100 tracks using keypad 4x3 matrix with audino UNO. keypad will have 0 to 9 keys, * = to correction key, # = to enter/play key. user first selects folder number and then track number press enter /play.playing a specific track in a folder.
Have you studied the data sheet and/or many other posts on this module?
Do you have an initial sketch you can show us, with specific questions about what’s not working? And a schematic of your circuit?
Although there are similarities between your questions and those in the original thread, it would be better to start a new post of your own.