mirror of
https://github.com/DFRobot/DFRobotDFPlayerMini.git
synced 2026-03-15 04:56:49 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47c0149383 | ||
|
|
ed07ad9da4 | ||
|
|
a81a07c863 | ||
|
|
8803a47a5d | ||
|
|
fccaf97171 | ||
|
|
96d5e14940 | ||
|
|
86ea349894 | ||
|
|
eb30c016bd | ||
|
|
e15e9fcf8c | ||
|
|
90a7483779 | ||
|
|
00b6a67814 | ||
|
|
c286f98d6d | ||
|
|
8b4ba4f7d8 | ||
|
|
c295afa686 | ||
|
|
3613f54569 |
@@ -7,7 +7,7 @@
|
||||
* @copyright GNU Lesser General Public License
|
||||
*
|
||||
* @author [Angelo](Angelo.qiao@dfrobot.com)
|
||||
* @version V1.0
|
||||
* @version V1.0.6
|
||||
* @date 2016-12-07
|
||||
*/
|
||||
|
||||
@@ -31,15 +31,12 @@ uint16_t DFRobotDFPlayerMini::calculateCheckSum(uint8_t *buffer){
|
||||
}
|
||||
|
||||
void DFRobotDFPlayerMini::sendStack(){
|
||||
if (_sending[Stack_ACK]) {
|
||||
if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition
|
||||
while (_isSending) {
|
||||
delay(0);
|
||||
available();
|
||||
waitAvailable();
|
||||
}
|
||||
}
|
||||
else{
|
||||
delay(10);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
Serial.println();
|
||||
@@ -53,6 +50,10 @@ void DFRobotDFPlayerMini::sendStack(){
|
||||
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
|
||||
_timeOutTimer = millis();
|
||||
_isSending = _sending[Stack_ACK];
|
||||
|
||||
if (!_sending[Stack_ACK]) { //if the ack mode is off wait 10 ms after one transmition.
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
void DFRobotDFPlayerMini::sendStack(uint8_t command){
|
||||
@@ -80,15 +81,23 @@ void DFRobotDFPlayerMini::disableACK(){
|
||||
_sending[Stack_ACK] = 0x00;
|
||||
}
|
||||
|
||||
bool DFRobotDFPlayerMini::waitAvailable(){
|
||||
_isSending = true;
|
||||
bool DFRobotDFPlayerMini::waitAvailable(unsigned long duration){
|
||||
unsigned long timer = millis();
|
||||
if (!duration) {
|
||||
duration = _timeOutDuration;
|
||||
}
|
||||
while (!available()){
|
||||
if (millis() - timer > duration) {
|
||||
return handleError(TimeOut);
|
||||
}
|
||||
delay(0);
|
||||
}
|
||||
return _handleType != TimeOut;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){
|
||||
_serial = &stream;
|
||||
|
||||
if (isACK) {
|
||||
enableACK();
|
||||
}
|
||||
@@ -96,20 +105,17 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){
|
||||
disableACK();
|
||||
}
|
||||
|
||||
_serial = &stream;
|
||||
|
||||
if (doReset) {
|
||||
_timeOutDuration += 3000;
|
||||
reset();
|
||||
waitAvailable();
|
||||
_timeOutDuration -= 3000;
|
||||
waitAvailable(2000);
|
||||
delay(200);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// assume same state as with reset(): online
|
||||
_handleType = DFPlayerCardOnline;
|
||||
}
|
||||
|
||||
return (readType() == DFPlayerCardOnline) || !isACK;
|
||||
return (readType() == DFPlayerCardOnline) || (readType() == DFPlayerUSBOnline) || !isACK;
|
||||
}
|
||||
|
||||
uint8_t DFRobotDFPlayerMini::readType(){
|
||||
@@ -142,35 +148,50 @@ uint8_t DFRobotDFPlayerMini::readCommand(){
|
||||
}
|
||||
|
||||
void DFRobotDFPlayerMini::parseStack(){
|
||||
_handleCommand = *(_received + Stack_Command);
|
||||
uint8_t handleCommand = *(_received + Stack_Command);
|
||||
if (handleCommand == 0x41) { //handle the 0x41 ack feedback as a spcecial case, in case the pollusion of _handleCommand, _handleParameter, and _handleType.
|
||||
_isSending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_handleCommand = handleCommand;
|
||||
_handleParameter = arrayToUint16(_received + Stack_Parameter);
|
||||
|
||||
switch (_handleCommand) {
|
||||
case 0x3C:
|
||||
case 0x3D:
|
||||
handleMessage(DFPlayerPlayFinished, _handleParameter);
|
||||
break;
|
||||
case 0x3F:
|
||||
if (_handleParameter & 0x02) {
|
||||
if (_handleParameter & 0x01) {
|
||||
handleMessage(DFPlayerUSBOnline, _handleParameter);
|
||||
}
|
||||
else if (_handleParameter & 0x02) {
|
||||
handleMessage(DFPlayerCardOnline, _handleParameter);
|
||||
}
|
||||
else if (_handleParameter & 0x03) {
|
||||
handleMessage(DFPlayerCardUSBOnline, _handleParameter);
|
||||
}
|
||||
break;
|
||||
case 0x3A:
|
||||
if (_handleParameter & 0x02) {
|
||||
if (_handleParameter & 0x01) {
|
||||
handleMessage(DFPlayerUSBInserted, _handleParameter);
|
||||
}
|
||||
else if (_handleParameter & 0x02) {
|
||||
handleMessage(DFPlayerCardInserted, _handleParameter);
|
||||
}
|
||||
break;
|
||||
case 0x3B:
|
||||
if (_handleParameter & 0x02) {
|
||||
if (_handleParameter & 0x01) {
|
||||
handleMessage(DFPlayerUSBRemoved, _handleParameter);
|
||||
}
|
||||
else if (_handleParameter & 0x02) {
|
||||
handleMessage(DFPlayerCardRemoved, _handleParameter);
|
||||
}
|
||||
break;
|
||||
case 0x40:
|
||||
handleMessage(DFPlayerError, _handleParameter);
|
||||
break;
|
||||
case 0x41:
|
||||
_isSending = false;
|
||||
break;
|
||||
case 0x3C:
|
||||
case 0x3E:
|
||||
case 0x42:
|
||||
case 0x43:
|
||||
@@ -185,7 +206,7 @@ void DFRobotDFPlayerMini::parseStack(){
|
||||
case 0x4D:
|
||||
case 0x4E:
|
||||
case 0x4F:
|
||||
_isAvailable = true;
|
||||
handleMessage(DFPlayerFeedBack, _handleParameter);
|
||||
break;
|
||||
default:
|
||||
handleError(WrongStack);
|
||||
@@ -215,7 +236,6 @@ bool DFRobotDFPlayerMini::available(){
|
||||
Serial.print(F(" "));
|
||||
#endif
|
||||
if (_received[Stack_Header] == 0x7E) {
|
||||
_isAvailable = false;
|
||||
_receivedIndex ++;
|
||||
}
|
||||
}
|
||||
@@ -247,9 +267,6 @@ bool DFRobotDFPlayerMini::available(){
|
||||
if (validateStack()) {
|
||||
_receivedIndex = 0;
|
||||
parseStack();
|
||||
if (_isAvailable && !_sending[Stack_ACK]) {
|
||||
_isSending = false;
|
||||
}
|
||||
return _isAvailable;
|
||||
}
|
||||
else{
|
||||
@@ -264,9 +281,6 @@ bool DFRobotDFPlayerMini::available(){
|
||||
}
|
||||
}
|
||||
|
||||
if (_isSending && (millis()-_timeOutTimer>=_timeOutDuration)) {
|
||||
return handleError(TimeOut);
|
||||
}
|
||||
|
||||
return _isAvailable;
|
||||
}
|
||||
@@ -387,7 +401,12 @@ void DFRobotDFPlayerMini::disableDAC(){
|
||||
int DFRobotDFPlayerMini::readState(){
|
||||
sendStack(0x42);
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@@ -404,10 +423,15 @@ int DFRobotDFPlayerMini::readVolume(){
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t DFRobotDFPlayerMini::readEQ(){
|
||||
int DFRobotDFPlayerMini::readEQ(){
|
||||
sendStack(0x44);
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@@ -430,7 +454,12 @@ int DFRobotDFPlayerMini::readFileCounts(uint8_t device){
|
||||
}
|
||||
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@@ -452,7 +481,12 @@ int DFRobotDFPlayerMini::readCurrentFileNumber(uint8_t device){
|
||||
break;
|
||||
}
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@@ -462,7 +496,12 @@ int DFRobotDFPlayerMini::readCurrentFileNumber(uint8_t device){
|
||||
int DFRobotDFPlayerMini::readFileCountsInFolder(int folderNumber){
|
||||
sendStack(0x4E, folderNumber);
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@@ -472,7 +511,12 @@ int DFRobotDFPlayerMini::readFileCountsInFolder(int folderNumber){
|
||||
int DFRobotDFPlayerMini::readFolderCounts(){
|
||||
sendStack(0x4F);
|
||||
if (waitAvailable()) {
|
||||
return read();
|
||||
if (readType() == DFPlayerFeedBack) {
|
||||
return read();
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @copyright GNU Lesser General Public License
|
||||
*
|
||||
* @author [Angelo](Angelo.qiao@dfrobot.com)
|
||||
* @version V1.0
|
||||
* @version V1.0.6
|
||||
* @date 2016-12-07
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
#define DFPlayerCardOnline 4
|
||||
#define DFPlayerPlayFinished 5
|
||||
#define DFPlayerError 6
|
||||
#define DFPlayerUSBInserted 7
|
||||
#define DFPlayerUSBRemoved 8
|
||||
#define DFPlayerUSBOnline 9
|
||||
#define DFPlayerCardUSBOnline 10
|
||||
#define DFPlayerFeedBack 11
|
||||
|
||||
#define Busy 1
|
||||
#define Sleeping 2
|
||||
@@ -107,7 +112,7 @@ class DFRobotDFPlayerMini {
|
||||
|
||||
bool begin(Stream& stream, bool isACK = true, bool doReset = true);
|
||||
|
||||
bool waitAvailable();
|
||||
bool waitAvailable(unsigned long duration = 0);
|
||||
|
||||
bool available();
|
||||
|
||||
@@ -177,7 +182,7 @@ class DFRobotDFPlayerMini {
|
||||
|
||||
int readVolume();
|
||||
|
||||
uint8_t readEQ();
|
||||
int readEQ();
|
||||
|
||||
int readFileCounts(uint8_t device);
|
||||
|
||||
|
||||
Binary file not shown.
139
examples/AdvancedSetting/AdvancedSetting.ino
Normal file
139
examples/AdvancedSetting/AdvancedSetting.ino
Normal file
@@ -0,0 +1,139 @@
|
||||
/***************************************************
|
||||
DFPlayer - A Mini MP3 Player For Arduino
|
||||
<https://www.dfrobot.com/product-1121.html>
|
||||
|
||||
***************************************************
|
||||
This example shows the basic 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 "DFRobotDFPlayerMini.h"
|
||||
|
||||
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial softSerial(/*rx =*/4, /*tx =*/5);
|
||||
#define FPSerial softSerial
|
||||
#else
|
||||
#define FPSerial Serial1
|
||||
#endif
|
||||
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
void printDetail(uint8_t type, int value);
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if (defined ESP32)
|
||||
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
|
||||
#else
|
||||
FPSerial.begin(9600);
|
||||
#endif
|
||||
|
||||
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(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial 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){
|
||||
delay(0); // Code to compatible with ESP8266 watch dog.
|
||||
}
|
||||
}
|
||||
Serial.println(F("DFPlayer Mini online."));
|
||||
|
||||
myDFPlayer.volume(10); //Set volume value. From 0 to 30
|
||||
myDFPlayer.play(1); //Play the first mp3
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long timer = millis();
|
||||
|
||||
if (millis() - timer > 3000) {
|
||||
timer = millis();
|
||||
myDFPlayer.next(); //Play next mp3 every 3 second.
|
||||
}
|
||||
|
||||
if (myDFPlayer.available()) {
|
||||
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
|
||||
}
|
||||
}
|
||||
|
||||
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 DFPlayerUSBInserted:
|
||||
Serial.println("USB Inserted!");
|
||||
break;
|
||||
case DFPlayerUSBRemoved:
|
||||
Serial.println("USB Removed!");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/***************************************************
|
||||
DFPlayer - A Mini MP3 Player For Arduino
|
||||
<https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
|
||||
<https://www.dfrobot.com/product-1121.html>
|
||||
|
||||
***************************************************
|
||||
This example shows the all the function of library for DFPlayer.
|
||||
@@ -20,23 +20,34 @@
|
||||
****************************************************/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SoftwareSerial.h"
|
||||
#include "DFRobotDFPlayerMini.h"
|
||||
|
||||
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
|
||||
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial softSerial(/*rx =*/4, /*tx =*/5);
|
||||
#define FPSerial softSerial
|
||||
#else
|
||||
#define FPSerial Serial1
|
||||
#endif
|
||||
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
void printDetail(uint8_t type, int value);
|
||||
|
||||
void setup()
|
||||
{
|
||||
mySoftwareSerial.begin(9600);
|
||||
#if (defined ESP32)
|
||||
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
|
||||
#else
|
||||
FPSerial.begin(9600);
|
||||
#endif
|
||||
|
||||
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.
|
||||
if (!myDFPlayer.begin(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial 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!"));
|
||||
@@ -115,7 +126,7 @@ void setup()
|
||||
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
|
||||
Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read file counts in folder SD:/03
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -149,6 +160,12 @@ void printDetail(uint8_t type, int value){
|
||||
case DFPlayerCardOnline:
|
||||
Serial.println(F("Card Online!"));
|
||||
break;
|
||||
case DFPlayerUSBInserted:
|
||||
Serial.println("USB Inserted!");
|
||||
break;
|
||||
case DFPlayerUSBRemoved:
|
||||
Serial.println("USB Removed!");
|
||||
break;
|
||||
case DFPlayerPlayFinished:
|
||||
Serial.print(F("Number:"));
|
||||
Serial.print(value);
|
||||
@@ -185,4 +202,6 @@ void printDetail(uint8_t type, int value){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/***************************************************
|
||||
DFPlayer - A Mini MP3 Player For Arduino
|
||||
<https://www.dfrobot.com/index.php?route=product/product&search=mp3&description=true&product_id=1121>
|
||||
<https://www.dfrobot.com/product-1121.html>
|
||||
|
||||
***************************************************
|
||||
This example shows the basic function of library for DFPlayer.
|
||||
|
||||
Created 2014-8-28
|
||||
Created 2016-12-07
|
||||
By [Angelo qiao](Angelo.qiao@dfrobot.com)
|
||||
|
||||
GNU Lesser General Public License.
|
||||
@@ -15,28 +15,39 @@ DFPlayer - A Mini MP3 Player For Arduino
|
||||
|
||||
/***********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
|
||||
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial softSerial(/*rx =*/4, /*tx =*/5);
|
||||
#define FPSerial softSerial
|
||||
#else
|
||||
#define FPSerial Serial1
|
||||
#endif
|
||||
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
void printDetail(uint8_t type, int value);
|
||||
|
||||
void setup()
|
||||
{
|
||||
mySoftwareSerial.begin(9600);
|
||||
#if (defined ESP32)
|
||||
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
|
||||
#else
|
||||
FPSerial.begin(9600);
|
||||
#endif
|
||||
|
||||
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.
|
||||
if (!myDFPlayer.begin(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial 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!"));
|
||||
@@ -81,6 +92,12 @@ void printDetail(uint8_t type, int value){
|
||||
case DFPlayerCardOnline:
|
||||
Serial.println(F("Card Online!"));
|
||||
break;
|
||||
case DFPlayerUSBInserted:
|
||||
Serial.println("USB Inserted!");
|
||||
break;
|
||||
case DFPlayerUSBRemoved:
|
||||
Serial.println("USB Removed!");
|
||||
break;
|
||||
case DFPlayerPlayFinished:
|
||||
Serial.print(F("Number:"));
|
||||
Serial.print(value);
|
||||
@@ -117,5 +134,5 @@ void printDetail(uint8_t type, int value){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
151
examples/ReadValues/ReadValues.ino
Normal file
151
examples/ReadValues/ReadValues.ino
Normal file
@@ -0,0 +1,151 @@
|
||||
/***************************************************
|
||||
DFPlayer - A Mini MP3 Player For Arduino
|
||||
<https://www.dfrobot.com/product-1121.html>
|
||||
|
||||
***************************************************
|
||||
This example shows the basic function of library for DFPlayer.
|
||||
|
||||
Created 2016-12-07
|
||||
Modified 2018-08-15
|
||||
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 "DFRobotDFPlayerMini.h"
|
||||
|
||||
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial softSerial(/*rx =*/4, /*tx =*/5);
|
||||
#define FPSerial softSerial
|
||||
#else
|
||||
#define FPSerial Serial1
|
||||
#endif
|
||||
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
void printDetail(uint8_t type, int value);
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if (defined ESP32)
|
||||
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
|
||||
#else
|
||||
FPSerial.begin(9600);
|
||||
#endif
|
||||
|
||||
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(FPSerial, /*isACK = */true, /*doReset = */true)) { //Use serial 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 or USB drive!"));
|
||||
while(true){
|
||||
delay(0); // Code to compatible with ESP8266 watch dog.
|
||||
}
|
||||
}
|
||||
Serial.println(F("DFPlayer Mini online."));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long timer = millis();
|
||||
|
||||
if (millis() - timer > 3000) {
|
||||
timer = millis();
|
||||
|
||||
int value;
|
||||
|
||||
// value = myDFPlayer.readState(); //read mp3 state
|
||||
// value = myDFPlayer.readVolume(); //read current volume
|
||||
// value = myDFPlayer.readEQ(); //read EQ setting
|
||||
// value = myDFPlayer.readFileCounts(); //read all file counts in SD card
|
||||
// value = myDFPlayer.readCurrentFileNumber(); //read current play file number
|
||||
value = myDFPlayer.readFileCountsInFolder(3); //read file counts in folder SD:/03
|
||||
|
||||
if (value == -1) { //Error while Reading.
|
||||
printDetail(myDFPlayer.readType(), myDFPlayer.read());
|
||||
}
|
||||
else{ //Successfully get the result.
|
||||
Serial.println(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (myDFPlayer.available()) {
|
||||
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
|
||||
}
|
||||
}
|
||||
|
||||
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 DFPlayerUSBInserted:
|
||||
Serial.println("USB Inserted!");
|
||||
break;
|
||||
case DFPlayerUSBRemoved:
|
||||
Serial.println("USB Removed!");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
88
keywords.txt
Normal file
88
keywords.txt
Normal file
@@ -0,0 +1,88 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For DFRobotDFPlayerMini
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
DFRobotDFPlayerMini KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
volume KEYWORD2
|
||||
volumeUp KEYWORD2
|
||||
volumeDown KEYWORD2
|
||||
EQ KEYWORD2
|
||||
outputDevice KEYWORD2
|
||||
play KEYWORD2
|
||||
next KEYWORD2
|
||||
previous KEYWORD2
|
||||
loop KEYWORD2
|
||||
pause KEYWORD2
|
||||
start KEYWORD2
|
||||
playFolder KEYWORD2
|
||||
enableLoopAll KEYWORD2
|
||||
disableLoopAll KEYWORD2
|
||||
playMp3Folder KEYWORD2
|
||||
readType KEYWORD2
|
||||
advertise KEYWORD2
|
||||
stopAdvertise KEYWORD2
|
||||
playLargeFolder KEYWORD2
|
||||
loopFolder KEYWORD2
|
||||
randomAll KEYWORD2
|
||||
enableLoop KEYWORD2
|
||||
disableLoop KEYWORD2
|
||||
readState KEYWORD2
|
||||
readVolume KEYWORD2
|
||||
readEQ KEYWORD2
|
||||
readFileCounts KEYWORD2
|
||||
readCurrentFileNumber KEYWORD2
|
||||
readFileCountsInFolder KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
DFPLAYER_EQ_NORMAL LITERAL1
|
||||
DFPLAYER_EQ_POP LITERAL1
|
||||
DFPLAYER_EQ_ROCK LITERAL1
|
||||
DFPLAYER_EQ_JAZZ LITERAL1
|
||||
DFPLAYER_EQ_CLASSIC LITERAL1
|
||||
DFPLAYER_EQ_BASS LITERAL1
|
||||
DFPLAYER_DEVICE_U_DISK LITERAL1
|
||||
DFPLAYER_DEVICE_SD LITERAL1
|
||||
DFPLAYER_DEVICE_AUX LITERAL1
|
||||
DFPLAYER_DEVICE_SLEEP LITERAL1
|
||||
DFPLAYER_DEVICE_FLASH LITERAL1
|
||||
DFPLAYER_RECEIVED_LENGTH LITERAL1
|
||||
DFPLAYER_SEND_LENGTH LITERAL1
|
||||
TimeOut LITERAL1
|
||||
WrongStack LITERAL1
|
||||
DFPlayerCardInserted LITERAL1
|
||||
DFPlayerCardRemoved LITERAL1
|
||||
DFPlayerCardOnline LITERAL1
|
||||
DFPlayerUSBInserted LITERAL1
|
||||
DFPlayerUSBRemoved LITERAL1
|
||||
DFPlayerPlayFinished LITERAL1
|
||||
DFPlayerError LITERAL1
|
||||
Busy LITERAL1
|
||||
Sleeping LITERAL1
|
||||
SerialWrongStack LITERAL1
|
||||
CheckSumNotMatch LITERAL1
|
||||
FileIndexOut LITERAL1
|
||||
FileMismatch LITERAL1
|
||||
Advertise LITERAL1
|
||||
Stack_Header LITERAL1
|
||||
Stack_Version LITERAL1
|
||||
Stack_Length LITERAL1
|
||||
Stack_Command LITERAL1
|
||||
Stack_ACK LITERAL1
|
||||
Stack_Parameter LITERAL1
|
||||
Stack_CheckSum LITERAL1
|
||||
Stack_End LITERAL1
|
||||
DFPLAYER_DEVICE_SLEEP LITERAL1
|
||||
DFPLAYER_DEVICE_FLASH LITERAL1
|
||||
@@ -1,9 +1,9 @@
|
||||
name=DFRobotDFPlayerMini
|
||||
version=1.0.2
|
||||
version=1.0.6
|
||||
author=DFRobot
|
||||
maintainer=Angelo <angelo.qiao@dfrobot.com>
|
||||
sentence=Driver for DFPlayer Mini from DFRobot
|
||||
paragraph=Easy-to-use and reliable library for DFPlayer Mini
|
||||
category=Sensors
|
||||
category=Device Control
|
||||
url=https://github.com/DFRobot/DFRobotDFPlayerMini
|
||||
architectures=*
|
||||
|
||||
Reference in New Issue
Block a user