11 Commits

Author SHA1 Message Date
qsjhyy
47c0149383 V1.0.6 2023-06-26 13:57:37 +08:00
qsjhyy
ed07ad9da4 compatible with hardware serial port 2023-06-26 13:56:01 +08:00
黄毅圆
a81a07c863 Merge pull request #19 from iZhangHui/master
fix failure to initialize issue
2023-06-26 13:15:31 +08:00
黄毅圆
8803a47a5d Merge pull request #24 from SylvsGit/patch-1
Update DFRobotDFPlayerMini.cpp
2023-06-26 13:10:46 +08:00
黄毅圆
fccaf97171 Merge pull request #42 from MonicaPArroyo/master
keywords.txt added
2023-06-26 13:06:07 +08:00
Mónica P. Arroyo
96d5e14940 keywords.txt added 2022-02-24 12:59:13 -06:00
SylvsGit
86ea349894 Update DFRobotDFPlayerMini.cpp
Fixed erroneous message for USB track Play Finished. (0x3C)
2019-02-18 13:32:40 +01:00
Henry Zhang
eb30c016bd fix failure to initialize issue 2018-11-12 18:49:56 +08:00
jimaobian
e15e9fcf8c update the version in library properties 2018-08-27 19:44:45 +08:00
jimaobian
90a7483779 update Case 2018-08-27 19:36:30 +08:00
jimaobian
00b6a67814 update Case 2018-08-27 19:36:13 +08:00
10 changed files with 158 additions and 283 deletions

View File

@@ -7,7 +7,7 @@
* @copyright GNU Lesser General Public License * @copyright GNU Lesser General Public License
* *
* @author [Angelo](Angelo.qiao@dfrobot.com) * @author [Angelo](Angelo.qiao@dfrobot.com)
* @version V1.0.3 * @version V1.0.6
* @date 2016-12-07 * @date 2016-12-07
*/ */
@@ -34,7 +34,7 @@ void DFRobotDFPlayerMini::sendStack(){
if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition
while (_isSending) { while (_isSending) {
delay(0); delay(0);
available(); waitAvailable();
} }
} }
@@ -88,7 +88,7 @@ bool DFRobotDFPlayerMini::waitAvailable(unsigned long duration){
} }
while (!available()){ while (!available()){
if (millis() - timer > duration) { if (millis() - timer > duration) {
return false; return handleError(TimeOut);
} }
delay(0); delay(0);
} }
@@ -158,6 +158,7 @@ void DFRobotDFPlayerMini::parseStack(){
_handleParameter = arrayToUint16(_received + Stack_Parameter); _handleParameter = arrayToUint16(_received + Stack_Parameter);
switch (_handleCommand) { switch (_handleCommand) {
case 0x3C:
case 0x3D: case 0x3D:
handleMessage(DFPlayerPlayFinished, _handleParameter); handleMessage(DFPlayerPlayFinished, _handleParameter);
break; break;
@@ -191,7 +192,6 @@ void DFRobotDFPlayerMini::parseStack(){
case 0x40: case 0x40:
handleMessage(DFPlayerError, _handleParameter); handleMessage(DFPlayerError, _handleParameter);
break; break;
case 0x3C:
case 0x3E: case 0x3E:
case 0x42: case 0x42:
case 0x43: case 0x43:
@@ -281,9 +281,6 @@ bool DFRobotDFPlayerMini::available(){
} }
} }
if (_isSending && (millis()-_timeOutTimer>=_timeOutDuration)) {
return handleError(TimeOut);
}
return _isAvailable; return _isAvailable;
} }

View File

@@ -7,7 +7,7 @@
* @copyright GNU Lesser General Public License * @copyright GNU Lesser General Public License
* *
* @author [Angelo](Angelo.qiao@dfrobot.com) * @author [Angelo](Angelo.qiao@dfrobot.com)
* @version V1.0.3 * @version V1.0.6
* @date 2016-12-07 * @date 2016-12-07
*/ */

View File

@@ -20,23 +20,34 @@ DFPlayer - A Mini MP3 Player For Arduino
****************************************************/ ****************************************************/
#include "Arduino.h" #include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.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; DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value); void printDetail(uint8_t type, int value);
void setup() 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.begin(115200);
Serial.println(); Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial, false)) { //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("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!")); Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!")); Serial.println(F("2.Please insert the SD card!"));

View File

@@ -1,128 +0,0 @@
/***************************************************
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 "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;
}
}

View File

@@ -20,23 +20,34 @@
****************************************************/ ****************************************************/
#include "Arduino.h" #include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.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; DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value); void printDetail(uint8_t type, int value);
void setup() 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.begin(115200);
Serial.println(); Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); 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("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!")); Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!")); Serial.println(F("2.Please insert the SD card!"));

View File

@@ -22,19 +22,32 @@ DFPlayer - A Mini MP3 Player For Arduino
#include "Arduino.h" #include "Arduino.h"
#include "DFRobotDFPlayerMini.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; DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value); void printDetail(uint8_t type, int value);
void setup() void setup()
{ {
Serial1.begin(9600); #if (defined ESP32)
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
FPSerial.begin(9600);
#endif
Serial.begin(115200); Serial.begin(115200);
Serial.println(); Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(Serial1)) { //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("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!")); Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!")); Serial.println(F("2.Please insert the SD card!"));
@@ -123,4 +136,3 @@ void printDetail(uint8_t type, int value){
} }
} }

View File

@@ -1,127 +0,0 @@
/***************************************************
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 "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){
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;
}
}

View File

@@ -21,23 +21,34 @@
****************************************************/ ****************************************************/
#include "Arduino.h" #include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.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; DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value); void printDetail(uint8_t type, int value);
void setup() 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.begin(115200);
Serial.println(); Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); 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("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!")); Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card or USB drive!")); Serial.println(F("2.Please insert the SD card or USB drive!"));

88
keywords.txt Normal file
View 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

View File

@@ -1,5 +1,5 @@
name=DFRobotDFPlayerMini name=DFRobotDFPlayerMini
version=1.0.3 version=1.0.6
author=DFRobot author=DFRobot
maintainer=Angelo <angelo.qiao@dfrobot.com> maintainer=Angelo <angelo.qiao@dfrobot.com>
sentence=Driver for DFPlayer Mini from DFRobot sentence=Driver for DFPlayer Mini from DFRobot