There are two 'types' of directory normal and large, Folders must be named "01","02","03" etc. There are also 'special' directory names of which "mp3" is one.
Normal directories can hold 255 files that must be named 001xxx.mp3, 002xxx.mp3 etc.
Large directories can hold 3000 files which must be named 0001xx.mp3, 0002xxxxx.mp3 etc. The special mp3 folder is considered a large folder so the names in it must also be of the 0001.mp3 form.
Files in normal directories are played using the 0x0f command those in large folders with the 0x14 command and those in the mp3 folder with the 0x12 command.
Of the two libraries available DFPlayer_Mini_Mp3 and DFRobotDFPlayerMini I prefer the later as it seems to do more of 'what's written on the packet'.
Reading the DFRobotDFPlayerMini.h is very instructive and easy to read, the following are listed-
void playFolder(uint8_t folderNumber, uint8_t fileNumber);
void playLargeFolder(uint8_t folderNumber, uint16_t fileNumber);
void playMp3Folder(int fileNumber);
You can drive this module from a Pro-mini via the proper serial port, just put a 1k resistor in the tx line FROM the Pro-mini. It also has two pins for USB, wiring them to a USB A socket with the Vcc line connected allows reading files from a USB pen.
Select which with the outputDevice(device) command the following are defined
#define DFPLAYER_DEVICE_U_DISK 1
#define DFPLAYER_DEVICE_SD 2
Wiring them to a USB B socket WITHOUT the Vcc connected allows connecting to a PC where the SD drive appears as a drive.
The following is working code which plays from both the SD and the USB. the usb contains a Large directory
#include <DFRobotDFPlayerMini.h>
//#include <DFPlayer_Mini_Mp3.h>
//variables
int n; // track being played
int pinState; // for reading pins
int volume = 30; // current volume level
int newVolume; // volume reading from pot
int busy = A7;
int pot = A3;
int threshold; // switching point for analog inputs
DFRobotDFPlayerMini mp3; //enable the player
void setup () {
Serial.begin (9600);
mp3.begin(Serial);
mp3.volume(30);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(busy, INPUT);
pinMode(busy, INPUT); pinMode(pot, INPUT);
}
void adjustVolume() {
newVolume = analogRead(pot);
newVolume = map(newVolume, 0, 1023, 0, 30);
if (newVolume != volume)
{
mp3.volume(newVolume);
volume = newVolume;
}
}
void play( int folder, int n) {
if (folder >0){
mp3.playFolder(folder, n);
}else{
mp3.playLargeFolder(abs(folder), n);
}
}
void loop () {
int folder;
for (int i = 2; i < 7; i++) {
if (digitalRead(i) == 0) {
if (i < 6) {
mp3.outputDevice(DFPLAYER_DEVICE_SD);
folder = 1;// int val of directory name string
play(folder, i - 2);
}
else {
mp3.outputDevice(DFPLAYER_DEVICE_U_DISK);
int folder = -1;// int val of directory name string
play(folder, i - 2);
}
}
adjustVolume();
}
}