I already have everything made and wired up but i cant find any libraries or examples of this being done before so i have no idea where to start. If anyone has any reference material or knows the librariy and or code to do this it woud be greatly apreciated.
Thanks
Edit: I'm using an arduino pro micro if that is helpful
I see that the sample code for the DF Robot MP3 player has "FullFunction" code that can that will play/pause and skip/previous, that could be easily adapted to buttons, if one only knew how to hook up and code buttons.
PE --
The DAC_L and DAC_R are the Stereo channels for headphones. A separate power amp can be used with them (for speakers). Or you can use the SPKR terminals for Mono.
But that doesn’t answer the original question. One that many have, including me. The code provided by DFRobot simply plays each track for a fixed time. What is needed is how to play full tracks, successively, obviously varying in duration, and use buttons in the loop() to interrupt in various ways, such as pause/resume, play next, play previous, change volume, etc. Neither the ‘get started’ or ‘advanced, full function’ examples do this.
@Terrypin the code provided by DFRobot in their wiki is just an example to get you started.
If you want to play whole tracks, then you can change the example code so that inside the main loop, you monitor the BUSY pin to see when a track has finished playing, and then issue the command to play the next track.
Have a look at the source code to their library and you will see lots of functions to help with what you want to do.
I've spent hours studying their code, in vain. In the full list of commands, copied below, there is no reference to the BUSY pin. As a non-programmer, working largely in copy/paste mode, I depend on thorough and practical examples.
Do you have practical experience of coding for this module? If so, care to share a simple example?
ORIGINAL DFRobot Mini MP3 LIBRARY: COMMANDS
-------------------------------------------
----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.EQ(DFPLAYER_EQ_POP);
myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
myDFPlayer.EQ(DFPLAYER_EQ_BASS);
----Set device we use SD as default----
myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
----Mp3 control----
myDFPlayer.sleep(); //sleep
myDFPlayer.reset(); //Reset the module
myDFPlayer.enableDAC(); //Enable On-chip DAC
myDFPlayer.disableDAC(); //Disable On-chip DAC
myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
----Mp3 play----
myDFPlayer.next(); //Play next mp3
myDFPlayer.previous(); //Play previous mp3
myDFPlayer.play(1); //Play the first mp3
myDFPlayer.loop(1); //Loop the first mp3
myDFPlayer.pause(); //pause the mp3
myDFPlayer.start(); //start the mp3 from the pause
myDFPlayer.playFolder(15, 4); //play specific mp3 in SD:/15/004.mp3; Folder Name(1~99); File Name(1~255)
myDFPlayer.enableLoopAll(); //loop all mp3 files.
myDFPlayer.disableLoopAll(); //stop loop all mp3 files.
myDFPlayer.playMp3Folder(4); //play specific mp3 in SD:/MP3/0004.mp3; File Name(0~65535)
myDFPlayer.advertise(3); //advertise specific mp3 in SD:/ADVERT/0003.mp3; File Name(0~65535)
myDFPlayer.stopAdvertise(); //stop advertise
myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(1~10); File Name(1~1000)
myDFPlayer.loopFolder(5); //loop all mp3 files in folder SD:/05.
myDFPlayer.randomAll(); //Random play all the mp3.
myDFPlayer.enableLoop(); //enable loop.
myDFPlayer.disableLoop(); //disable loop.
//----Read imformation----
Serial.println(myDFPlayer.readState()); //read mp3 state
Serial.println(myDFPlayer.readVolume()); //read current volume
Serial.println(myDFPlayer.readEQ()); //read EQ setting
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03
}
There's a risk of confusion here. That image shows their USB module (DF1201S), but I think the OP is using the micro-SD module (DFR0299). And that's the version in your earlier link.
My assumption is that the thread is about the micro-SD card version.
If anyone ends up here with questions about the USB version, I can probably help. I abandoned the SD version (in frustration over the very issues raised here) and finished the project below with the USB version, using DFRobot's less obscure library.
The OP’s post was uninformative. No feedback in 11 days so IMO we still don’t even know whether either of the DFRobot modules is being used?
cedarlakeinstruments recommended the USB version.
That was endorsed by DaveX. But then confused things with his subsequent post with a picture of the USB version but a link to the SD version,
runaway_pancake posted advice about the SD version.
Your first post also spoke exclusively about the SD version (the only one with a BUSY pin) and implied that coding it was a piece of cake.
Happy to assume the thread was now focusing on the SD version, I challenged that opinion. The list of commands I posted is for the SD version, as shown by its heading. (‘Mini’ is a helpful indication, if the product code or ‘SD’ does not make it clear). To repeat: it makes no reference to the BUSY pin.
In case anyone ends up here looking with problems on the USB version (perhaps even the_cat!), I took the opportunity to offer my help.
Looking forward to your answer about your practical experience, in the hope of seeing an example for the SD version.
The DFPlayer_Mini's 'BUSY' pin is noted in their description of its pins,
right after 'Pin Map':
"BUSY | Playing Status | Low means Playing, High means No"
They don't go into it more than that.
Thanks Faraday. I'll experiment with the BUSY pin if I can't succeed with the library. Although I'll be largely just guessing how it interfaces with the Arduino program. Presumably that can only occur when BUSY is HIGH, i.e. not playing? Which prompts various questions, such as: is it 'playing' without interruption after issuing 'enableLoopAll()' or 'randomAll()'? Which would seem to imply it cannot be paused, etc. Maybe there's always a brief 'not busy' gap after every file played? Trial and error will no doubt answer these sort of questions. But it's disappointing that DFRobot's documentation seems aimed only at technicians/programmers.
Also, doesn't the library command available() serve the same purpose?
Meanwhile, yes, I can currently play successive tracks, or randomly. By using the appropriate command in setup(), and either confining it there with a while() or simply emptying loop(). But the penny that hasn't yet dropped is how to add the same sort of logic in loop() that I used in the USB version. See my earlier photo. That was a lot of work, so my aim is to rewire it for the SD version, taking me from 208 tracks to about 3,000 with the SD's far greater capacity.
EDIT: I've shown my current code below as a solid base for further discussion.
Apart from the major one raised above, it includes two questions puzzling me, shown in the top comments.
// Tuesday 8 March 2022; Plays from specified track, then randomly
// Still have not got the loop() logic working
// Copuple of puzzles meanwhile
// Can't fathom why it consistently stops after 7 tracks?
// Also can presently only show track that just FINISHED;
// I want to see the track number that's PLAYING.
/***************************************************
DFPlayer - A Mini MP3 Player For Arduino
<https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
***************************************************
This example shows the all the function of library for DFPlayer.
Created 2016-12-07
By [Angelo qiao](Angelo.qiao@dfrobot.com)
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
****************************************************/
/***********Notice and Trouble shooting***************
1.Connection and Diagram can be found here
<https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
****************************************************/
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) //Use softwareSerial to communicate with mp3.
{
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);
}
Serial.println(F("DFPlayer Mini online."));
// myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms
//----Set volume----
myDFPlayer.volume(15); //Set volume value (0~30).
// myDFPlayer.enableLoopAll();
myDFPlayer.randomAll();
delay(3000);
myDFPlayer.play(100);
// Currently playing file number
Serial.println(myDFPlayer.readCurrentFileNumber());
// Now plays all, in sequence, in setup.
// Now plays all, in random sequence, in setup.
// while (1 == 1); // Stops program from proceeding
}
void loop()
{
if (myDFPlayer.available())
{
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
Serial.println(myDFPlayer.readCurrentFileNumber());
}
//
if (myDFPlayer.available())
{
// if (digitalRead(6) == LOW)
if (digitalRead(6) == LOW)
myDFPlayer.previous();
}
if (myDFPlayer.available())
{
// if (digitalRead() == LOW)
if (digitalRead(3) == LOW)
myDFPlayer.pause();
}
} // End of loop
void printDetail(uint8_t type, int value)
{
switch (type)
{
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value)
{
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
Oops, sorry. I didn't check things closely. I googled "MP3 player from DF Robot" from @cedarlakeinstruments's first post and then distracted by the link from his second post and their their most excellent use-case of an analogRead Button-resistor tree scheme. I didn't check the item numbers.
I try not to put too much more thought into replying than goes into the questions.
With BUSY you can start an MP3 playing and then digitalRead (using while or do_while), which I speculate, is probably faster than repeatedly issuing a serial instruction.