mirror of
https://github.com/DFRobot/DFRobotDFPlayerMini.git
synced 2026-03-15 13:06:50 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90a7483779 | ||
|
|
00b6a67814 | ||
|
|
c286f98d6d | ||
|
|
8b4ba4f7d8 | ||
|
|
c295afa686 | ||
|
|
3613f54569 | ||
|
|
beeba2c69d | ||
|
|
cfb9428978 | ||
|
|
c36911d7b3 | ||
|
|
0cf620c20d | ||
|
|
7b5087e1af | ||
|
|
c0bd68111b | ||
|
|
20343d62ed | ||
|
|
31d5ec18d6 | ||
|
|
6f4f402c71 | ||
|
|
c9f758979b | ||
|
|
6111ae2018 | ||
|
|
772d326841 | ||
|
|
fabbb011df | ||
|
|
9826577d39 |
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- "2.7"
|
||||||
|
env:
|
||||||
|
- BOARD=uno
|
||||||
|
- BOARD=leonardo
|
||||||
|
- BOARD=esp01
|
||||||
|
|
||||||
|
install:
|
||||||
|
- python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- cd examples/FullFunction
|
||||||
|
- platformio ci -l ../.. FullFunction.ino --board=$BOARD
|
||||||
|
- cd ../GetStarted
|
||||||
|
- platformio ci -l ../.. getStarted.ino --board=$BOARD
|
||||||
|
|
||||||
@@ -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
|
* @version V1.0.3
|
||||||
* @date 2016-12-07
|
* @date 2016-12-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -24,21 +24,19 @@ void DFRobotDFPlayerMini::uint16ToArray(uint16_t value, uint8_t *array){
|
|||||||
|
|
||||||
uint16_t DFRobotDFPlayerMini::calculateCheckSum(uint8_t *buffer){
|
uint16_t DFRobotDFPlayerMini::calculateCheckSum(uint8_t *buffer){
|
||||||
uint16_t sum = 0;
|
uint16_t sum = 0;
|
||||||
for (int i=Stack::Version; i<Stack::CheckSum; i++) {
|
for (int i=Stack_Version; i<Stack_CheckSum; i++) {
|
||||||
sum += buffer[i];
|
sum += buffer[i];
|
||||||
}
|
}
|
||||||
return -sum;
|
return -sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DFRobotDFPlayerMini::sendStack(){
|
void DFRobotDFPlayerMini::sendStack(){
|
||||||
if (_sending[Stack::ACK]) {
|
if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition
|
||||||
while (_isSending) {
|
while (_isSending) {
|
||||||
|
delay(0);
|
||||||
available();
|
available();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
delay(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@@ -51,7 +49,11 @@ void DFRobotDFPlayerMini::sendStack(){
|
|||||||
#endif
|
#endif
|
||||||
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
|
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
|
||||||
_timeOutTimer = millis();
|
_timeOutTimer = millis();
|
||||||
_isSending = _sending[Stack::ACK];
|
_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){
|
void DFRobotDFPlayerMini::sendStack(uint8_t command){
|
||||||
@@ -59,9 +61,9 @@ void DFRobotDFPlayerMini::sendStack(uint8_t command){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DFRobotDFPlayerMini::sendStack(uint8_t command, uint16_t argument){
|
void DFRobotDFPlayerMini::sendStack(uint8_t command, uint16_t argument){
|
||||||
_sending[Stack::Command] = command;
|
_sending[Stack_Command] = command;
|
||||||
uint16ToArray(argument, _sending+Stack::Parameter);
|
uint16ToArray(argument, _sending+Stack_Parameter);
|
||||||
uint16ToArray(calculateCheckSum(_sending), _sending+Stack::CheckSum);
|
uint16ToArray(calculateCheckSum(_sending), _sending+Stack_CheckSum);
|
||||||
sendStack();
|
sendStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,20 +74,30 @@ void DFRobotDFPlayerMini::sendStack(uint8_t command, uint8_t argumentHigh, uint8
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DFRobotDFPlayerMini::enableACK(){
|
void DFRobotDFPlayerMini::enableACK(){
|
||||||
_sending[Stack::ACK] = 0x01;
|
_sending[Stack_ACK] = 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DFRobotDFPlayerMini::disableACK(){
|
void DFRobotDFPlayerMini::disableACK(){
|
||||||
_sending[Stack::ACK] = 0x00;
|
_sending[Stack_ACK] = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::waitAvailable(){
|
bool DFRobotDFPlayerMini::waitAvailable(unsigned long duration){
|
||||||
_isSending = true;
|
unsigned long timer = millis();
|
||||||
while (!available());
|
if (!duration) {
|
||||||
return _handleType != HandleType::TimeOut;
|
duration = _timeOutDuration;
|
||||||
|
}
|
||||||
|
while (!available()){
|
||||||
|
if (millis() - timer > duration) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delay(0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
|
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){
|
||||||
|
_serial = &stream;
|
||||||
|
|
||||||
if (isACK) {
|
if (isACK) {
|
||||||
enableACK();
|
enableACK();
|
||||||
}
|
}
|
||||||
@@ -93,16 +105,20 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
|
|||||||
disableACK();
|
disableACK();
|
||||||
}
|
}
|
||||||
|
|
||||||
_serial = &stream;
|
if (doReset) {
|
||||||
_timeOutDuration += 3000;
|
reset();
|
||||||
reset();
|
waitAvailable(2000);
|
||||||
waitAvailable();
|
delay(200);
|
||||||
_timeOutDuration -= 3000;
|
}
|
||||||
delay(200);
|
else {
|
||||||
return (readType() == DFPlayerCardOnline) || !isACK;
|
// assume same state as with reset(): online
|
||||||
|
_handleType = DFPlayerCardOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (readType() == DFPlayerCardOnline) || (readType() == DFPlayerUSBOnline) || !isACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleType DFRobotDFPlayerMini::readType(){
|
uint8_t DFRobotDFPlayerMini::readType(){
|
||||||
_isAvailable = false;
|
_isAvailable = false;
|
||||||
return _handleType;
|
return _handleType;
|
||||||
}
|
}
|
||||||
@@ -112,7 +128,7 @@ uint16_t DFRobotDFPlayerMini::read(){
|
|||||||
return _handleParameter;
|
return _handleParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::handleMessage(HandleType type, uint16_t parameter){
|
bool DFRobotDFPlayerMini::handleMessage(uint8_t type, uint16_t parameter){
|
||||||
_receivedIndex = 0;
|
_receivedIndex = 0;
|
||||||
_handleType = type;
|
_handleType = type;
|
||||||
_handleParameter = parameter;
|
_handleParameter = parameter;
|
||||||
@@ -120,9 +136,10 @@ bool DFRobotDFPlayerMini::handleMessage(HandleType type, uint16_t parameter){
|
|||||||
return _isAvailable;
|
return _isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::handleError(HandleType type, uint16_t parameter){
|
bool DFRobotDFPlayerMini::handleError(uint8_t type, uint16_t parameter){
|
||||||
handleMessage(type, parameter);
|
handleMessage(type, parameter);
|
||||||
_isSending = false;
|
_isSending = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DFRobotDFPlayerMini::readCommand(){
|
uint8_t DFRobotDFPlayerMini::readCommand(){
|
||||||
@@ -131,33 +148,48 @@ uint8_t DFRobotDFPlayerMini::readCommand(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DFRobotDFPlayerMini::parseStack(){
|
void DFRobotDFPlayerMini::parseStack(){
|
||||||
_handleCommand = *(_received + Stack::Command);
|
uint8_t handleCommand = *(_received + Stack_Command);
|
||||||
_handleParameter = arrayToUint16(_received + Stack::Parameter);
|
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) {
|
switch (_handleCommand) {
|
||||||
case 0x3D:
|
case 0x3D:
|
||||||
handleMessage(HandleType::DFPlayerPlayFinished, _handleParameter);
|
handleMessage(DFPlayerPlayFinished, _handleParameter);
|
||||||
break;
|
break;
|
||||||
case 0x3F:
|
case 0x3F:
|
||||||
if (_handleParameter & 0x02) {
|
if (_handleParameter & 0x01) {
|
||||||
handleMessage(HandleType::DFPlayerCardOnline, _handleParameter);
|
handleMessage(DFPlayerUSBOnline, _handleParameter);
|
||||||
|
}
|
||||||
|
else if (_handleParameter & 0x02) {
|
||||||
|
handleMessage(DFPlayerCardOnline, _handleParameter);
|
||||||
|
}
|
||||||
|
else if (_handleParameter & 0x03) {
|
||||||
|
handleMessage(DFPlayerCardUSBOnline, _handleParameter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x3A:
|
case 0x3A:
|
||||||
if (_handleParameter & 0x02) {
|
if (_handleParameter & 0x01) {
|
||||||
handleMessage(HandleType::DFPlayerCardInserted, _handleParameter);
|
handleMessage(DFPlayerUSBInserted, _handleParameter);
|
||||||
|
}
|
||||||
|
else if (_handleParameter & 0x02) {
|
||||||
|
handleMessage(DFPlayerCardInserted, _handleParameter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x3B:
|
case 0x3B:
|
||||||
if (_handleParameter & 0x02) {
|
if (_handleParameter & 0x01) {
|
||||||
handleMessage(HandleType::DFPlayerCardRemoved, _handleParameter);
|
handleMessage(DFPlayerUSBRemoved, _handleParameter);
|
||||||
|
}
|
||||||
|
else if (_handleParameter & 0x02) {
|
||||||
|
handleMessage(DFPlayerCardRemoved, _handleParameter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x40:
|
case 0x40:
|
||||||
handleMessage(HandleType::DFPlayerError, _handleParameter);
|
handleMessage(DFPlayerError, _handleParameter);
|
||||||
break;
|
|
||||||
case 0x41:
|
|
||||||
_isSending = false;
|
|
||||||
break;
|
break;
|
||||||
case 0x3C:
|
case 0x3C:
|
||||||
case 0x3E:
|
case 0x3E:
|
||||||
@@ -174,7 +206,7 @@ void DFRobotDFPlayerMini::parseStack(){
|
|||||||
case 0x4D:
|
case 0x4D:
|
||||||
case 0x4E:
|
case 0x4E:
|
||||||
case 0x4F:
|
case 0x4F:
|
||||||
_isAvailable = true;
|
handleMessage(DFPlayerFeedBack, _handleParameter);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
handleError(WrongStack);
|
handleError(WrongStack);
|
||||||
@@ -190,20 +222,20 @@ uint16_t DFRobotDFPlayerMini::arrayToUint16(uint8_t *array){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::validateStack(){
|
bool DFRobotDFPlayerMini::validateStack(){
|
||||||
return calculateCheckSum(_received) == arrayToUint16(_received+Stack::CheckSum);
|
return calculateCheckSum(_received) == arrayToUint16(_received+Stack_CheckSum);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DFRobotDFPlayerMini::available(){
|
bool DFRobotDFPlayerMini::available(){
|
||||||
while (_serial->available()) {
|
while (_serial->available()) {
|
||||||
|
delay(0);
|
||||||
if (_receivedIndex == 0) {
|
if (_receivedIndex == 0) {
|
||||||
_received[Stack::Header] = _serial->read();
|
_received[Stack_Header] = _serial->read();
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Serial.print(F("received:"));
|
Serial.print(F("received:"));
|
||||||
Serial.print(_received[_receivedIndex],HEX);
|
Serial.print(_received[_receivedIndex],HEX);
|
||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
#endif
|
#endif
|
||||||
if (_received[Stack::Header] == 0x7E) {
|
if (_received[Stack_Header] == 0x7E) {
|
||||||
_isAvailable = false;
|
|
||||||
_receivedIndex ++;
|
_receivedIndex ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,17 +246,17 @@ bool DFRobotDFPlayerMini::available(){
|
|||||||
Serial.print(F(" "));
|
Serial.print(F(" "));
|
||||||
#endif
|
#endif
|
||||||
switch (_receivedIndex) {
|
switch (_receivedIndex) {
|
||||||
case Stack::Version:
|
case Stack_Version:
|
||||||
if (_received[_receivedIndex] != 0xFF) {
|
if (_received[_receivedIndex] != 0xFF) {
|
||||||
return handleError(WrongStack);
|
return handleError(WrongStack);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Stack::Length:
|
case Stack_Length:
|
||||||
if (_received[_receivedIndex] != 0x06) {
|
if (_received[_receivedIndex] != 0x06) {
|
||||||
return handleError(WrongStack);
|
return handleError(WrongStack);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Stack::End:
|
case Stack_End:
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Serial.println();
|
Serial.println();
|
||||||
#endif
|
#endif
|
||||||
@@ -235,9 +267,6 @@ bool DFRobotDFPlayerMini::available(){
|
|||||||
if (validateStack()) {
|
if (validateStack()) {
|
||||||
_receivedIndex = 0;
|
_receivedIndex = 0;
|
||||||
parseStack();
|
parseStack();
|
||||||
if (_isAvailable && !_sending[Stack::ACK]) {
|
|
||||||
_isSending = false;
|
|
||||||
}
|
|
||||||
return _isAvailable;
|
return _isAvailable;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -375,7 +404,12 @@ void DFRobotDFPlayerMini::disableDAC(){
|
|||||||
int DFRobotDFPlayerMini::readState(){
|
int DFRobotDFPlayerMini::readState(){
|
||||||
sendStack(0x42);
|
sendStack(0x42);
|
||||||
if (waitAvailable()) {
|
if (waitAvailable()) {
|
||||||
return read();
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -392,11 +426,15 @@ int DFRobotDFPlayerMini::readVolume(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DFRobotDFPlayerMini::readEQ(){
|
int DFRobotDFPlayerMini::readEQ(){
|
||||||
sendStack(0x44);
|
sendStack(0x44);
|
||||||
while (!available());
|
|
||||||
if (waitAvailable()) {
|
if (waitAvailable()) {
|
||||||
return read();
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -419,7 +457,12 @@ int DFRobotDFPlayerMini::readFileCounts(uint8_t device){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (waitAvailable()) {
|
if (waitAvailable()) {
|
||||||
return read();
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -441,7 +484,12 @@ int DFRobotDFPlayerMini::readCurrentFileNumber(uint8_t device){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (waitAvailable()) {
|
if (waitAvailable()) {
|
||||||
return read();
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -451,7 +499,27 @@ int DFRobotDFPlayerMini::readCurrentFileNumber(uint8_t device){
|
|||||||
int DFRobotDFPlayerMini::readFileCountsInFolder(int folderNumber){
|
int DFRobotDFPlayerMini::readFileCountsInFolder(int folderNumber){
|
||||||
sendStack(0x4E, folderNumber);
|
sendStack(0x4E, folderNumber);
|
||||||
if (waitAvailable()) {
|
if (waitAvailable()) {
|
||||||
return read();
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DFRobotDFPlayerMini::readFolderCounts(){
|
||||||
|
sendStack(0x4F);
|
||||||
|
if (waitAvailable()) {
|
||||||
|
if (readType() == DFPlayerFeedBack) {
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -459,11 +527,11 @@ int DFRobotDFPlayerMini::readFileCountsInFolder(int folderNumber){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DFRobotDFPlayerMini::readFileCounts(){
|
int DFRobotDFPlayerMini::readFileCounts(){
|
||||||
readFileCounts(DFPLAYER_DEVICE_SD);
|
return readFileCounts(DFPLAYER_DEVICE_SD);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DFRobotDFPlayerMini::readCurrentFileNumber(){
|
int DFRobotDFPlayerMini::readCurrentFileNumber(){
|
||||||
readCurrentFileNumber(DFPLAYER_DEVICE_SD);
|
return readCurrentFileNumber(DFPLAYER_DEVICE_SD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* @version V1.0.3
|
||||||
* @date 2016-12-07
|
* @date 2016-12-07
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -35,26 +35,35 @@
|
|||||||
|
|
||||||
//#define _DEBUG
|
//#define _DEBUG
|
||||||
|
|
||||||
enum HandleType{
|
#define TimeOut 0
|
||||||
TimeOut,
|
#define WrongStack 1
|
||||||
WrongStack,
|
#define DFPlayerCardInserted 2
|
||||||
DFPlayerCardInserted,
|
#define DFPlayerCardRemoved 3
|
||||||
DFPlayerCardRemoved,
|
#define DFPlayerCardOnline 4
|
||||||
DFPlayerCardOnline,
|
#define DFPlayerPlayFinished 5
|
||||||
DFPlayerPlayFinished,
|
#define DFPlayerError 6
|
||||||
DFPlayerError
|
#define DFPlayerUSBInserted 7
|
||||||
};
|
#define DFPlayerUSBRemoved 8
|
||||||
|
#define DFPlayerUSBOnline 9
|
||||||
|
#define DFPlayerCardUSBOnline 10
|
||||||
|
#define DFPlayerFeedBack 11
|
||||||
|
|
||||||
enum DFPlayerErrorType{
|
#define Busy 1
|
||||||
Busy = 1,
|
#define Sleeping 2
|
||||||
Sleeping,
|
#define SerialWrongStack 3
|
||||||
SerialWrongStack,
|
#define CheckSumNotMatch 4
|
||||||
CheckSumNotMatch,
|
#define FileIndexOut 5
|
||||||
FileIndexOut,
|
#define FileMismatch 6
|
||||||
FileMismatch,
|
#define Advertise 7
|
||||||
Advertise
|
|
||||||
};
|
|
||||||
|
|
||||||
|
#define Stack_Header 0
|
||||||
|
#define Stack_Version 1
|
||||||
|
#define Stack_Length 2
|
||||||
|
#define Stack_Command 3
|
||||||
|
#define Stack_ACK 4
|
||||||
|
#define Stack_Parameter 5
|
||||||
|
#define Stack_CheckSum 7
|
||||||
|
#define Stack_End 9
|
||||||
|
|
||||||
class DFRobotDFPlayerMini {
|
class DFRobotDFPlayerMini {
|
||||||
Stream* _serial;
|
Stream* _serial;
|
||||||
@@ -88,38 +97,26 @@ class DFRobotDFPlayerMini {
|
|||||||
|
|
||||||
uint8_t device = DFPLAYER_DEVICE_SD;
|
uint8_t device = DFPLAYER_DEVICE_SD;
|
||||||
|
|
||||||
|
|
||||||
enum Stack{
|
|
||||||
Header = 0,
|
|
||||||
Version = 1,
|
|
||||||
Length = 2,
|
|
||||||
Command = 3,
|
|
||||||
ACK = 4,
|
|
||||||
Parameter = 5,
|
|
||||||
CheckSum = 7,
|
|
||||||
End = 9
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HandleType _handleType;
|
uint8_t _handleType;
|
||||||
uint8_t _handleCommand;
|
uint8_t _handleCommand;
|
||||||
uint16_t _handleParameter;
|
uint16_t _handleParameter;
|
||||||
bool _isAvailable = false;
|
bool _isAvailable = false;
|
||||||
bool _isSending = false;
|
bool _isSending = false;
|
||||||
|
|
||||||
bool handleMessage(HandleType type, uint16_t parameter = 0);
|
bool handleMessage(uint8_t type, uint16_t parameter = 0);
|
||||||
bool handleError(HandleType type, uint16_t parameter = 0);
|
bool handleError(uint8_t type, uint16_t parameter = 0);
|
||||||
|
|
||||||
uint8_t readCommand();
|
uint8_t readCommand();
|
||||||
|
|
||||||
bool begin(Stream& stream, bool isACK = true);
|
bool begin(Stream& stream, bool isACK = true, bool doReset = true);
|
||||||
|
|
||||||
bool waitAvailable();
|
bool waitAvailable(unsigned long duration = 0);
|
||||||
|
|
||||||
bool available();
|
bool available();
|
||||||
|
|
||||||
HandleType readType();
|
uint8_t readType();
|
||||||
|
|
||||||
uint16_t read();
|
uint16_t read();
|
||||||
|
|
||||||
@@ -185,7 +182,7 @@ class DFRobotDFPlayerMini {
|
|||||||
|
|
||||||
int readVolume();
|
int readVolume();
|
||||||
|
|
||||||
uint8_t readEQ();
|
int readEQ();
|
||||||
|
|
||||||
int readFileCounts(uint8_t device);
|
int readFileCounts(uint8_t device);
|
||||||
|
|
||||||
@@ -194,6 +191,8 @@ class DFRobotDFPlayerMini {
|
|||||||
int readFileCountsInFolder(int folderNumber);
|
int readFileCountsInFolder(int folderNumber);
|
||||||
|
|
||||||
int readFileCounts();
|
int readFileCounts();
|
||||||
|
|
||||||
|
int readFolderCounts();
|
||||||
|
|
||||||
int readCurrentFileNumber();
|
int readCurrentFileNumber();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# DFPlayer - A Mini MP3 Player For Arduino
|
# DFPlayer - A Mini MP3 Player For Arduino
|
||||||
DFPlayer - A Mini MP3 Player For Arduino
|
|
||||||
|
|
||||||
|
|
||||||
|
DFPlayer - A Mini MP3 Player For Arduino
|
||||||
https://www.dfrobot.com/index.php?route=product/product&product_id=1121
|
https://www.dfrobot.com/index.php?route=product/product&product_id=1121
|
||||||
|
|
||||||
This example shows the all the function of library for DFPlayer.
|
This example shows the all the function of library for DFPlayer.
|
||||||
@@ -16,5 +17,4 @@ Notice and Trouble shooting
|
|||||||
|
|
||||||
1.Connection and Diagram can be found here
|
1.Connection and Diagram can be found here
|
||||||
https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram
|
https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram
|
||||||
|
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
|
||||||
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
|
|
||||||
|
|||||||
BIN
doc/FN-M16P+Embedded+MP3+Audio+Module+Datasheet.pdf
Normal file
BIN
doc/FN-M16P+Embedded+MP3+Audio+Module+Datasheet.pdf
Normal file
Binary file not shown.
126
examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino
Normal file
126
examples/AdvancedSettingViaSerial1/AdvancedSettingViaSerial1.ino
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/***************************************************
|
||||||
|
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"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
128
examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino
Normal file
128
examples/AdvancedSettingWithoutACK/AdvancedSettingWithoutACK.ino
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/***************************************************
|
||||||
|
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, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/***************************************************
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/***************************************************
|
/***************************************************
|
||||||
DFPlayer - A Mini MP3 Player For Arduino
|
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.
|
This example shows the all the function of library for DFPlayer.
|
||||||
@@ -115,7 +115,7 @@ void setup()
|
|||||||
Serial.println(myDFPlayer.readEQ()); //read EQ setting
|
Serial.println(myDFPlayer.readEQ()); //read EQ setting
|
||||||
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
|
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
|
||||||
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
|
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()
|
void loop()
|
||||||
@@ -149,6 +149,12 @@ void printDetail(uint8_t type, int value){
|
|||||||
case DFPlayerCardOnline:
|
case DFPlayerCardOnline:
|
||||||
Serial.println(F("Card Online!"));
|
Serial.println(F("Card Online!"));
|
||||||
break;
|
break;
|
||||||
|
case DFPlayerUSBInserted:
|
||||||
|
Serial.println("USB Inserted!");
|
||||||
|
break;
|
||||||
|
case DFPlayerUSBRemoved:
|
||||||
|
Serial.println("USB Removed!");
|
||||||
|
break;
|
||||||
case DFPlayerPlayFinished:
|
case DFPlayerPlayFinished:
|
||||||
Serial.print(F("Number:"));
|
Serial.print(F("Number:"));
|
||||||
Serial.print(value);
|
Serial.print(value);
|
||||||
@@ -185,4 +191,6 @@ void printDetail(uint8_t type, int value){
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/***************************************************
|
/***************************************************
|
||||||
DFPlayer - A Mini MP3 Player For Arduino
|
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 basic function of library for DFPlayer.
|
This example shows the basic function of library for DFPlayer.
|
||||||
@@ -40,7 +40,9 @@ void setup()
|
|||||||
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!"));
|
||||||
while(true);
|
while(true){
|
||||||
|
delay(0); // Code to compatible with ESP8266 watch dog.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println(F("DFPlayer Mini online."));
|
Serial.println(F("DFPlayer Mini online."));
|
||||||
|
|
||||||
@@ -79,6 +81,12 @@ void printDetail(uint8_t type, int value){
|
|||||||
case DFPlayerCardOnline:
|
case DFPlayerCardOnline:
|
||||||
Serial.println(F("Card Online!"));
|
Serial.println(F("Card Online!"));
|
||||||
break;
|
break;
|
||||||
|
case DFPlayerUSBInserted:
|
||||||
|
Serial.println("USB Inserted!");
|
||||||
|
break;
|
||||||
|
case DFPlayerUSBRemoved:
|
||||||
|
Serial.println("USB Removed!");
|
||||||
|
break;
|
||||||
case DFPlayerPlayFinished:
|
case DFPlayerPlayFinished:
|
||||||
Serial.print(F("Number:"));
|
Serial.print(F("Number:"));
|
||||||
Serial.print(value);
|
Serial.print(value);
|
||||||
@@ -115,5 +123,5 @@ void printDetail(uint8_t type, int value){
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
140
examples/ReadValues/ReadValues.ino
Normal file
140
examples/ReadValues/ReadValues.ino
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/***************************************************
|
||||||
|
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 "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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
name=DFRobotDFPlayerMini
|
name=DFRobotDFPlayerMini
|
||||||
version=1.0.0
|
version=1.0.3
|
||||||
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
|
||||||
paragraph=Easy-to-use and reliable library for DFPlayer Mini
|
paragraph=Easy-to-use and reliable library for DFPlayer Mini
|
||||||
category=Sensors
|
category=Device Control
|
||||||
url=https://github.com/DFRobot/DFRobotDFPlayerMini
|
url=https://github.com/DFRobot/DFRobotDFPlayerMini
|
||||||
architectures=*
|
architectures=*
|
||||||
|
|||||||
Reference in New Issue
Block a user