From 8b4ba4f7d822ab2b091ee586c6cf566cd0b2d31c Mon Sep 17 00:00:00 2001 From: jimaobian Date: Wed, 15 Aug 2018 13:44:47 +0800 Subject: [PATCH] update to 1.0.3 * Fix the bug that read cannot get the right result. * Add USB support * Add more example. --- DFRobotDFPlayerMini.cpp | 115 +++++++++----- DFRobotDFPlayerMini.h | 11 +- ...6P+Embedded+MP3+Audio+Module+Datasheet.pdf | Bin 825549 -> 857021 bytes .../AdvancedSettingViaSerial1.ino | 126 ++++++++++++++++ .../AdvancedSettingWithoutACK.ino | 128 ++++++++++++++++ .../AdvancedSettingWithoutReset.ino | 128 ++++++++++++++++ examples/FullFunction/FullFunction.ino | 8 + examples/GetStarted/getStarted.ino | 8 +- examples/ReadValues/ReadValues.ino | 140 ++++++++++++++++++ 9 files changed, 626 insertions(+), 38 deletions(-) create mode 100644 examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino create mode 100644 examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino create mode 100644 examples/AdvancedSettingWithoutReset/AdvancedSettingWithoutReset.ino create mode 100644 examples/ReadValues/ReadValues.ino diff --git a/DFRobotDFPlayerMini.cpp b/DFRobotDFPlayerMini.cpp index 2468573..bd60a66 100644 --- a/DFRobotDFPlayerMini.cpp +++ b/DFRobotDFPlayerMini.cpp @@ -7,7 +7,7 @@ * @copyright GNU Lesser General Public License * * @author [Angelo](Angelo.qiao@dfrobot.com) - * @version V1.0 + * @version V1.0.3 * @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(); } } - 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 false; + } 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,7 +148,13 @@ 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) { @@ -150,26 +162,35 @@ void DFRobotDFPlayerMini::parseStack(){ 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: @@ -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{ @@ -387,7 +404,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 +426,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 +457,12 @@ int DFRobotDFPlayerMini::readFileCounts(uint8_t device){ } if (waitAvailable()) { - return read(); + if (readType() == DFPlayerFeedBack) { + return read(); + } + else{ + return -1; + } } else{ return -1; @@ -452,7 +484,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 +499,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 +514,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; diff --git a/DFRobotDFPlayerMini.h b/DFRobotDFPlayerMini.h index ec72f19..a78f75c 100644 --- a/DFRobotDFPlayerMini.h +++ b/DFRobotDFPlayerMini.h @@ -7,7 +7,7 @@ * @copyright GNU Lesser General Public License * * @author [Angelo](Angelo.qiao@dfrobot.com) - * @version V1.0 + * @version V1.0.3 * @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); diff --git a/doc/FN-M16P+Embedded+MP3+Audio+Module+Datasheet.pdf b/doc/FN-M16P+Embedded+MP3+Audio+Module+Datasheet.pdf index 150d4138ccf967520a3bede2e28816c7ae284c0a..fdd8c9bb0f19da3625f04006f2432432d116a334 100644 GIT binary patch delta 31710 zcmc)T+m2;Np4V|PoQuBX0a8eFYiI6rqSi=mdOWmXG*)*DkXl^iVJGwm*~ndkdJxj$ z!VkdR^c!%E#4V37@5JXDYwbK#m0k9@Dznng+_BeM5&!rfe*Z&6?ESa@XZ8R7_vU|o z^Y^~_qi_EHH~-+9fB4Nm`sN>h^H09{r{BE#=AZrFpZx6~rpwE-^Rut6|MJyOfBNdv zfA!Uuua958{@vNd`MI}$dG_klKR@37_UdO}{r>D?dwT1OtFPU3wp#A^(L9m(AO7O{FON69 zvz`gOCt))1OxR4q<3YN2A?%YuL-f7l)#GP2_s^_W>rXbD^$tyE+w;RG>x=c}dUbZT zT3vo}Sg*F&dA40mt53F@?Pk9|JA2&CcIhUe{QHMNU)|F^$lg7=>$A_k__zP^vwt&q zef9dcUw!%SR%bumUha;Y)qcIZ*d8{=_4(#@!NJX?m#fK3!|&JY{dTpz++1xA z+pFEpZtcP2{(QGuuh!e~{(gPAyWCyuZnwML)o!!V;r7b?`^|2Dxiz)j!Tp=AYwtGe z?P}fgYa{sI&wjJt-EFSd2ZLX2$N~w|aeuYj8{!-pMK-{8O0n1R z&O?U=-04$?+uh~na=+cKcQ?qs+^zTLo9nG%_7~pS?yh&M-O+RF-OBtMcyHkA&Glxz z_iuBYHhLQuw%gU_a;v#PM8ob6yS*9i&1>DT=7SbAua{vBjo2}4^FqXaf3dkX`^dV{ zzT3MWrI-8ez1-ccFE+>B%|Zwc?xwp~6orN|=lzvgBSG7YyLpG^_2sx82V$+iNI~jC zIMUp=jYQiRp94 zYgAw1i9zN88|XU*+!^Qw>j`Lgz_IOSg=V4~{T`R`4n(ruPR#@XW_`Zga5H3v*3rR@ z2TubZ1}7*X32#!)-EGoiKq=?7KKAA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yjm-~6vX{N!JJI=%$@(=Wb0{vAGdwuow>!Ej@l3TA|{qZ0F>0f;Q G>i+}ZixH9l delta 33 pcmdnH+~n*=qlOm77N!>F7M2#)7Pc1l7LFFq7OocVEj(vu007mU3)}zz diff --git a/examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino b/examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino new file mode 100644 index 0000000..c4da17d --- /dev/null +++ b/examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino @@ -0,0 +1,126 @@ +/*************************************************** +DFPlayer - A Mini MP3 Player For Arduino + + + *************************************************** + 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 for details. + All above must be included in any redistribution + ****************************************************/ + +/***********Notice and Trouble shooting*************** + 1.Connection and Diagram can be found here + + 2.This code is tested on Arduino Uno, Leonardo, Mega boards. + ****************************************************/ + +#include "Arduino.h" +#include "DFRobotDFPlayerMini.h" + +DFRobotDFPlayerMini myDFPlayer; +void printDetail(uint8_t type, int value); + +void setup() +{ + Serial1.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(Serial1)) { //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){ + 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; + } + +} + diff --git a/examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino b/examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino new file mode 100644 index 0000000..ddc0c12 --- /dev/null +++ b/examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino @@ -0,0 +1,128 @@ +/*************************************************** +DFPlayer - A Mini MP3 Player For Arduino + + + *************************************************** + 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 for details. + All above must be included in any redistribution + ****************************************************/ + +/***********Notice and Trouble shooting*************** + 1.Connection and Diagram can be found here + + 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, false)) { //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){ + 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; + } + +} + diff --git a/examples/AdvancedSettingWithoutReset/AdvancedSettingWithoutReset.ino b/examples/AdvancedSettingWithoutReset/AdvancedSettingWithoutReset.ino new file mode 100644 index 0000000..b974090 --- /dev/null +++ b/examples/AdvancedSettingWithoutReset/AdvancedSettingWithoutReset.ino @@ -0,0 +1,128 @@ +/*************************************************** +DFPlayer - A Mini MP3 Player For Arduino + + + *************************************************** + 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 for details. + All above must be included in any redistribution + ****************************************************/ + +/***********Notice and Trouble shooting*************** + 1.Connection and Diagram can be found here + + 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, true, false)) { //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){ + 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; + } + +} + diff --git a/examples/FullFunction/FullFunction.ino b/examples/FullFunction/FullFunction.ino index 2629d96..199dd3e 100644 --- a/examples/FullFunction/FullFunction.ino +++ b/examples/FullFunction/FullFunction.ino @@ -149,6 +149,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 +191,6 @@ void printDetail(uint8_t type, int value){ default: break; } + } + diff --git a/examples/GetStarted/getStarted.ino b/examples/GetStarted/getStarted.ino index 0c7db85..125f824 100644 --- a/examples/GetStarted/getStarted.ino +++ b/examples/GetStarted/getStarted.ino @@ -81,6 +81,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 +123,5 @@ void printDetail(uint8_t type, int value){ default: break; } - + } diff --git a/examples/ReadValues/ReadValues.ino b/examples/ReadValues/ReadValues.ino new file mode 100644 index 0000000..ac10eb5 --- /dev/null +++ b/examples/ReadValues/ReadValues.ino @@ -0,0 +1,140 @@ +/*************************************************** + DFPlayer - A Mini MP3 Player For Arduino + + + *************************************************** + 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 for details. + All above must be included in any redistribution + ****************************************************/ + +/***********Notice and Trouble shooting*************** + 1.Connection and Diagram can be found here + + 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 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; + } + +}