Df mini player arduino

Hi there!!!
I'm developing a project and it has a part of playing audio files at specific events.
I bought a df mini player and have arduino mega and nano. I want some help ( not need the exact code) about the dfplayer functions, keywords and some syntax.

My requirement is,

I have 15 folders, named in two digit format. .00,01,02 etc)

10 audio files in every folder, named as three digit format.( 000,001,002,003,004,005,006,007,008,009).

Now I want a system that plays a random file from a specific folder at specific event

For example, if the time is 10am, it should play a random audio file from folder 10.

Any help would be appreciated...

Don't know what use the Mega is, but the Nano sounds appropriate.

What code have you used so far (read the instructions :+1:) to play a single file?

A quick read of the library code for the DFPlayerMini and it looks like the playFolder() command is what you need.

Thanks for your reply..
Can you please give me any source link for play folder().

Thanks again!!

this is for normal playing. it plays all tracks one by one.

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>


void setup () {
  Serial.begin (9600);
  mp3_set_serial (Serial); 
  mp3_set_volume (15);
}



void loop () {        
  mp3_play ();

}

i have tried this code for random file playing. It worked with SD card module. but it plays only one file in DF player case.

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>

const char * filenames [] = {"/01/" "001.mp3","/01/" "002.mp3","/01/" "003.mp3", "/01/" "004.mp3","/01/" "005.mp3"};
//
void setup () {
  Serial.begin (9600);
  mp3_set_serial (Serial);  
  randomSeed(analogRead(0));
}
 void Music(){
  mp3_set_volume (10);
  
 mp3_play(filenames [random(10)]);
}


void loop () { 
  
  Music();

  delay(10000);
  Serial.println(filenames [random(10)]);
  }

Hii there!!

Please help me with random file playing in specific folder..

Thanks again

Did you try the playFolder() function? If that does not work for you, then does the library mentioned in post #2 of the link I gave (in post #7) not help?

@Power_Broker mentions in that discussion that you can choose a folder and a random track using the playFolder() function. You would need to know beforehand how many files were in each specific folder so that could be passed to the random() function to generate the random track number.

You might want to check out this web page too:

Yes I tried.. but it didn't worked for me..

I tried this and i got error "DFPlayerMini_Fast" has no member named "playFolderTrack16".

#include <SoftwareSerial.h>
#include <DFPlayerMini_Fast.h>
#include <DFPlayer_Mini_Mp3.h>

SoftwareSerial mySerial(10,11); // RX, TX
DFPlayerMini_Fast myMP3;

void setup()
{
  Serial.begin(115200);
  mySerial.begin(9600);

  myMP3.begin(mySerial);
    
  
 long randomInt = random(1,10);
  myMP3.playFolderTrack16(1, 003);
 
delay (10000);
  
}

void loop()
{
  //do nothing
}

There isn't a function called playFolderTrack16() ... it's just playFolder().

What didn't work?

It doesn't make any sound..

No song is playing..

By the way, playFolder(); is throwing an error.

I'm totally confused with dfminiplayer.mp3, dfplayer mini fast, and dfminimp3 libraries.

Can you please help me out to play random files in specific folder???

I've got a DFPlayer Mini here so i'll see if I can hook it up tomorrow and see if I can reproduce the issue(s) you are seeing.

EDIT: Jump forward to reply #60 to skip over the merged discussions.

Hi there!!!!

I'm very much new to this forum and need some help..
Actually I'm designing a project and needs to play a random wav file from a folder at specific event. I'm done with the rest of the project except random wav playing.

Any help would be appreciated..

const char * filenames[] = {"file 1", "file 2", "another file"};

void setup()
{
  Serial.begin(115200);
  while (!Serial);
}

void loop()
{
  Serial.println(filenames[random(3)]);
  delay(1000);
}

Thanks for your quick reply..
But I don't have clear idea to apply this concept to real scenario..
I'll attach the code.. please apply your concept to the code..

Thanks a lot.. .:handshake:

include <TMRpcm.h>
#include <SPI.h>
#include <SD.h>
#define CHIP_SELECT_PIN  53
#define SPEAKER_PIN      11
TMRpcm tmrpcm;

void setup( ) {
tmrpcm.speakerPin = SPEAKER_PIN;
Serial.begin( 9600 );
if ( !SD.begin( CHIP_SELECT_PIN ) ){
  Serial.println( "SD fail" );
 return;
}
  tmrpcm.play( "2.wav" );
  delay( 5 );

}

void loop( ) {
}

Why don't you try for yourself ?
Put the filenames in an array as in my example
Instead of

  tmrpcm.play( "2.wav" );

replace the filename with one selected at random from the array as I did when printing a filename in my example

I notice that you have #included the SD.h file in your sketch and test whether you can start the SD connection. What is that all about ?

Yes, I'm able to play wav files.. but fixed files. (Example: if i set "2.Wav" it plays 2nd wav).
But I need random file playing. Atleast I need some syntax for my requirement.