Git Product home page Git Product logo

dfrobotdfplayermini's Introduction

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

This example shows the all the function of library for DFPlayer.

Created 2016-12-07 By Angelo qiao

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.

dfrobotdfplayermini's People

Contributors

izhanghui avatar jandelgado avatar jimaobian avatar monicaparroyo avatar qsjhyy avatar sylvsgit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dfrobotdfplayermini's Issues

Using with SparkFun ESP32 board just crashes on start

v1.0.5 with all latest drivers. Had to convert SoftwareSerial reference to Serial2. Running on Sparkfun IoT Redboard, tested board with WiFi and SD card demos successfully. DFRobot software crashes Arduino instantly on boot.

Serial monitor output:

ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d19fc: ffffffff 00000000 ffff0700
Core 1 register dump:
PC : 0x400d1a00 PS : 0x00060330 A0 : 0x800d1349 A1 : 0x3ffb1f00
A2 : 0x3ffbec10 A3 : 0x0000000b A4 : 0x3ffbec10 A5 : 0x0000000a
A6 : 0x0000000b A7 : 0x00000008 A8 : 0x800d22e8 A9 : 0x3ffb1ee0
A10 : 0x3ffbec10 A11 : 0x400d1c24 A12 : 0x00000000 A13 : 0x000000c6
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000015 EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000

Backtrace: 0x400d1a00:0x3ffb1f00 0x400d1346:0x3ffb1f40 0x400d0c4d:0x3ffb1f80 0x400d193b:0x3ffb1fb0 0x40088219:0x3ffb1fd0

Rebooting...

Noise is inserted into audio during communication (It's playing?)

I would like to monitor the status every 1 second to see if it is playing.

I have a folder with files of small duration and others with long files, but some folders can not be played, so I can not use the continuous play commands, or play randomly, for the whole card.

I modified the example file, to randomly play some folders, but it works fine only if I use the busy pin.

I noticed that a noise appears in the audio, when the serial port is used, so I had to monitor the busy signal pin.

I've added series resistors for RX and TX, and the noise has decreased a lot, but sometimes the program reports errors such as "Time Out!", "Stack Wrong!",

How to monitor by software without causing a noise similar to the step of a wall clock in the audio?

/***************************************************
  DFPlayer - A Mini MP3 Player For Arduino
  https://www.dfrobot.com/product-1121.html

  This example shows the all the function of library for DFPlayer.

  Created 2016-12-07
  By Angelo qiao

  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"

//#define busyPin 12

SoftwareSerial mySoftwareSerial(5, 4); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

bool isPlaying = true;

int lastValidFolder = 0;
const int maxFolder = 10; // (1~99)
int folderFiles[maxFolder];

void setup()
{
  delay(5000); // help in upload done with esp-link (OTA)
  //  pinMode(busyPin, INPUT); // optional

  randomSeed((analogRead(6) + analogRead(7)) / 2); //

  mySoftwareSerial.begin(9600);
  Serial.begin(9600);

  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  //Use softwareSerial to communicate with mp3.
  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while (true);
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.setTimeOut(2000); //Set serial communication time out 500ms

  //----Set volume----
  myDFPlayer.volume(30); //Set volume value (0~30).
  // myDFPlayer.volumeUp(); //Volume Up
  // myDFPlayer.volumeDown(); //Volume Down

  //----Set different EQ----
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  // myDFPlayer.EQ(DFPLAYER_EQ_POP);
  // myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
  // myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
  // myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
  // myDFPlayer.EQ(DFPLAYER_EQ_BASS);

  //----Set device we use SD as default----
  // myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  // myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
  // myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
  // myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);

  //----Mp3 control----
  // myDFPlayer.sleep(); //sleep
  // myDFPlayer.reset(); //Reset the module
  // myDFPlayer.enableDAC(); //Enable On-chip DAC
  // myDFPlayer.disableDAC(); //Disable On-chip DAC
  // myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15 (0~30)

  //----Mp3 play----
  // myDFPlayer.next(); //Play next mp3
  // delay(1000);
  // myDFPlayer.previous(); //Play previous mp3
  // delay(1000);
  // myDFPlayer.play(1); //Play the first mp3
  // delay(1000);
  // myDFPlayer.loop(1); //Loop the first mp3
  // delay(1000);
  // myDFPlayer.pause(); //pause the mp3
  // delay(1000);
  // myDFPlayer.start(); //start the mp3 from the pause
  // delay(1000);
  // myDFPlayer.playFolder(15, 4); //play specific mp3 in SD:/15/004.mp3; Folder Name(199); File Name(1255)
  // delay(1000);
  // myDFPlayer.enableLoopAll(); //loop all mp3 files.
  // delay(1000);
  // myDFPlayer.disableLoopAll(); //stop loop all mp3 files.
  // delay(1000);
  // myDFPlayer.playMp3Folder(4); //play specific mp3 in SD:/MP3/0004.mp3; File Name(065535)
  // delay(1000);
  // myDFPlayer.advertise(3); //advertise specific mp3 in SD:/ADVERT/0003.mp3; File Name(065535)
  // delay(1000);
  // myDFPlayer.stopAdvertise(); //stop advertise
  // delay(1000);
  // myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(110); File Name(11000)
  // delay(1000);
  // myDFPlayer.loopFolder(5); //loop all mp3 files in folder SD:/05.
  // delay(1000);
  // myDFPlayer.randomAll(); //Random play all the mp3.
  // delay(1000);
  // myDFPlayer.enableLoop(); //enable loop.
  // delay(1000);
  // myDFPlayer.disableLoop(); //disable loop.
  // delay(1000);

  //----Read imformation----
  Serial.print(F("State: "));
  Serial.println(myDFPlayer.readState()); //read mp3 state
  Serial.print(F("Volume (030): "));
  Serial.println(myDFPlayer.readVolume()); //read current volume
  Serial.print(F("Equalizer (Normal/Pop/Rock/Jazz/Classic/Base): "));
  printEqDetail(myDFPlayer.readEQ()); //read EQ setting
  Serial.print(F("File Counts: "));
  Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
  Serial.print(F("Current File Number of micro SD Card: "));
  Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
  for (int i = 1; i <= maxFolder; i++) { // 199
    folderFiles[i] = myDFPlayer.readFileCountsInFolder(i);
    Serial.print(F("File Counts In Folder "));
    Serial.print(i, DEC);
    Serial.print(F(": "));

    if (folderFiles[i] > 0) {
      lastValidFolder = i;
      Serial.print(folderFiles[i]); //read file counts in folder SD:/nn
      Serial.print(F(" [Valid]"));
    } else {
      Serial.print(F("Not found"));
    }

    Serial.println();
  }
}

static unsigned long timer;
static unsigned long timer2;
static unsigned long timer3;
unsigned long newMillis = 0;
bool newDots = true;
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
int typeFb = 0;
int valueFb = 0;
int typeFb2 = 0;
int valueFb2 = 0;

void loop()
{
  newMillis = millis();

  if (myDFPlayer.available()) {
    if (cnt2 > 0) Serial.println();
    typeFb = myDFPlayer.readType();
    valueFb = myDFPlayer.read();
    printDetail(typeFb, valueFb); //Print the detail message from DFPlayer to handle different errors and states.
    if (myDFPlayer.available()) {
      typeFb2 = myDFPlayer.readType();
      valueFb2 = myDFPlayer.read();
      if ((typeFb2 != typeFb) & (valueFb2 != valueFb)) { // Is not repeated?
        printDetail(typeFb2, valueFb2); //Print the detail message from DFPlayer to handle different errors and states.
      }
    }
  } else if (((newMillis - timer3) > 1000) & (!isPlaying)) { // DFplayer busy pin state
    //  } else if (((newMillis - timer3) > 1000) & (digitalRead(busyPin))) { // DFplayer busy pin state
    timer3 = newMillis;
    playNewRandomFile();
  } else { // available = false & isPlaying = true
    if (newMillis - timer > 1000) {
      timer = newMillis;
      if (isPlaying) printDots(); // dot's playback
    } else if (newMillis - timer2 > 2000) { // playback finished
      timer2 = newMillis;
      isPlayingTest();
    }
  }
}

bool isPlayingTest() {
  //if (isPlaying == true) { // very long music? (noise)
  int state = myDFPlayer.readState();
  //    Serial.print("isPlayingTest: ");
  //    Serial.println(state, DEC);
  if ((state == 513) | (state == 529)) {
    isPlaying = true;
  } else if (state == 512) {
    isPlaying = false;
  }
  //}
  return isPlaying;
}

void printDots() {
  if (newDots) {
    newDots = false;
    cnt1 = 0;
    cnt2 = 1;
    cnt3 = 0;
  } else {
    if (cnt1 < 30) {
      cnt1++;
    } else {
      cnt1 = 1;
      Serial.println();
    }
    if (cnt3 < 9) {
      cnt3++;
      if (cnt3 == 5) {
        printTime();
      } else {
        Serial.print(F("."));
      }
    } else {
      cnt3 = 0;
      printTime();
    }
    cnt2++;
  }
}

void printTime() {
  int hours = cnt2 / 3600;
  int minutes = (cnt2 - (hours * 60)) / 60;
  int seconds = cnt2 - (minutes * 60) - (hours * 60);

  if (cnt2 < 60) {
    Serial.print(seconds, DEC);
    Serial.print(F("s"));
  } else if (cnt2 < 3600) {
    Serial.print(minutes, DEC);
    Serial.print(F("m:"));
    Serial.print(seconds, DEC);
    Serial.print(F("s"));
  } else {
    Serial.print(hours, DEC);
    Serial.print(F("h:"));
    Serial.print(minutes, DEC);
    Serial.print(F("m:"));
    Serial.print(seconds, DEC);
    Serial.print(F("s"));
  }
}

void playNewRandomFile() {
  if (lastValidFolder == 0) {
    Serial.println(F("Empty device"));
    return; // file not found
  }

  int folder = random(1, maxFolder);
  while (folderFiles[folder] < 0) { // have valid files?
    folder = random(1, maxFolder); // for playFolder: 99 max
  }

  // int folder = random(1, 15); // for playLargeFolder: 15 max
  int file = random(1, folderFiles[folder]); // for playFolder: 255 max
  // int file = random(1, 3000); // for playLargeFolder: 3000 max
  char buffer[30];
  if (cnt2 > 1) {
    Serial.print(F("Host - File playback time "));
    printTime();
    Serial.println();
  }
  Serial.print(F("Host - Play file "));
  sprintf(buffer, "%d from folder %d", file, folder);
  Serial.println(buffer);
  isPlaying = true;
  newDots = true; // reset dot's position
  //myDFPlayer.playLargeFolder(folder, file); // up to 3000 tracks and 15 folders
  myDFPlayer.playFolder(folder, file); //play specific mp3 in SD:/nn/nnn.mp3; Folder Name(199); File Name(1255)
}

void printEqDetail(int type) {
  switch (type) { // EQ" (0/1/2/3/4/5) Normal/Pop/Rock/Jazz/Classic/Base
    case 1:
      Serial.print(F("Pop"));
      break;
    case 2:
      Serial.print(F("Rock"));
      break;
    case 3:
      Serial.print(F("Jazz"));
      break;
    case 4:
      Serial.print(F("Classic"));
      break;
    case 5:
      Serial.print(F("Base"));
      break;
    default: // 0
      Serial.print(F("Normal"));
      break;
  }
  Serial.print(F("("));
  Serial.print(type, DEC);
  Serial.println(F(")"));
}

void printDetail(uint8_t type, int value) {
  //  if ((type == DFPlayerError) & (value == Advertise)) {
  //    //isPlaying = true;
  //  } else {
  //    //isPlaying = false;
  //    cnt2 = 0;
  //  }

  Serial.print(F("DFPlayer - "));

  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.println(F("Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("Error: "));
      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:
          Serial.print(F("Unknown, "));
          Serial.println(value, DEC);
          break;
      }
      break;
    default:
      Serial.print(F("Unknown type code, "));
      Serial.println(type, DEC);
      break;
  }
}

continuous random play

Arduino Library Reference?

Is there a reference guide to the Arduino library please? I can work out most of the functions from the example code, but a few things are eluding me! Been unable to find anything through search.

Many thanks!

arduino / nodeMCU issues

Hi,

I've two issues and one I was able to overcome using the hints here in the 'issues' page on github.

I. myDFPlayer.volume() ignored
Using nodeMCU 1.0 I wasn't able to set the volume correctly as e.g. myDFPlayer.volume(5) was just ignored. Setting isACK to false solved this issue:

myDFPlayer.begin(mySoftwareSerial, false

II. printDetail() prints always "Time Out!"
While volume can now be set correctly and mp3 will be played correctly, the printDetail() method from GetStarted.ino will always return "Time Out!". No matter if mp3 is playing or not. Is this a bug or a feature? I have no clue what it means.

thanks in advance and best regards

Stefan

Bug in response handling semantics

When acknowledge enabled some modules may send only response and no acknowledge.
For example "MH2024K-24SS". Library behaves badly in this and similar situations.
The problem code is here:

    case 0x4F:
      _isAvailable = true;
// _handleType=TimeOut-1; // placeholder
      break;

Here _handleType will have previous (uninitialized) value, in case the previous value was TimeOut then the timeout will be received. Problem is generated here:

bool DFRobotDFPlayerMini::waitAvailable(){
  _isSending = true;
  while (!available()){
    delay(0);
  }
  return _handleType != TimeOut;
}

By forcing the standard example to run myDFPlayer.readFileCountsInFolder(1); the code here will return TimeOut two times:

  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

Result of myDFPlayer.readFileCountsInFolder(1); will be -1.

Correct answer should be number and one TimeOut value.

Here goes the command denoted as "<" and response from MH2024K-24SS denoted as ">" and response from YX5200-24SS denoted as "="

Query number of files in folder 1 (with acknowledge):
< 0x7E 0xFF 0x06 0x4E 0x01 0x00 0x01 0xFE 0xAB 0xEF
> 0x7E 0xFF 0x06 0x4E 0x00 0x00 0x05 0xFE 0xA8 0xEF
= 0x7E 0xFF 0x06 0x41 0x00 0x00 0x00 0xFE 0xBA 0xEF 0x7E 0xFF 0x06 0x4E 0x00 0x00 0x05 0xFE 0xA8 0xEF

The code inside void DFRobotDFPlayerMini::parseStack() should be reanalyzed and rewritten to avoid usage of uninitialized variables. My _handleType=TimeOut-1; is just a placeholder.

Latest Version is not working (Hanging Arduino) when using multiple SoftwareSerial.

The Arduino will hang when calling startSoundSerial() after I call stopSoundSerial()
_But if you use v1.0.0 it will work without any issues.

SoftwareSerial WifiSerial(DD5, DD6);
SoftwareSerial SoundSerial(A0, A1);

void startSoundSerial() {
if (WifiSerial.isListening()) {
WifiSerial.flush();
WifiSerial.stopListening();
} else {
SoundSerial.listen();
}
}

void stopSoundSerial() {
if (SoundSerial.isListening()) {
SoundSerial.flush();
SoundSerial.stopListening();
} else {
WifiSerial.listen();
}
}

About the LGPL license

Hi,
I was wondering why the library is licensed under the LGPL while it is an SDK/API for a commercial product. I mean If I buy the product from DFRobot, shouldn't I receive the library under less restricted license?

Time Out on Arduino Pro Micro / Is online but Not Play

I'm had use the DF module with Arduino Pro Micro.
For RX and TX, I set the Pins 9 and 10.
Running the example it shows that the module is Online on player.begin
But after timeOut (set to 1500) I't shows Time Out
And not play any song.

Help Me Please.

Serial player?

If the module could also play MP3 streams coming from serial port, it could be also used to build tiny webradio players.

Not looping seamlessly

I wrote your basic code with .loop, and the file plays over and over, but with a small break in between, how can I disable that break? (Using .wav file)

Example code doesnt seem to work on a Seeeduino XIAO?

I needed a small Arduino for a project and I went with the Seeeduino XIAO which is a great little processor - but the same code that works on my other Arduinos does not execute correctly on the Seeeduino (or so it appears). I am new to the Seeeduino offering, so it may be something obvious that I'm missing.

Its acting like it locks up - The code uploads and seems to start, but the triggers arent working to start the first MP3 on the SD - However the same circuit works fine on my nano and UNO. On the Seeeduino, I cant see any serial output in the Arduino monitor and again, no MP3s start.

void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);

Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));

Is this a known issue or any known fix?

Thanks

Low power mode

Hi,

Is there a command of the library to put the DF Player Mini in a low power mode?

I have tried with the function sleep() but the consumption remains the same as in normal operation (around 20 mA).

Thanks in advance.

MP3 ID3

hi,

is there any way we can get the ID3 tags for the current play file.

regards,

Bug with reading DFPlayer feedback (readFileCount, readVolume,...)

I found a problem with parseStack().

E.g. if calling readFileCount() or readVolume() , the DFPlayer response returns 41 as 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;
}

Response parameters _handlerParameter is only read after the 41 command if.

_handleParameter = arrayToUint16(_received + Stack_Parameter);

Shouldn't 41 command codes (at lease in these cases) result in DFPlayerFeedBack?

case 0x3C:
case 0x3E:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
case 0x47:
case 0x48:
case 0x49:
case 0x4B:
case 0x4C:
case 0x4D:
case 0x4E:
case 0x4F:
handleMessage(DFPlayerFeedBack, _handleParameter);
break;
default:
handleError(WrongStack);
break;
}

(We solved it our problem now by a dirty fix, we set the _handleParameter directly after the method starts.)

reading issue with DFmini type AA20HFJ648

With the AA20HFJ648 module, reading from the chip does not work for some functions. The number of files in a folder is output incorrectly.
It is often reported that -1 is returned. This is the case if the number is only requested for one folder and the volume or EQ has been set beforehand, for example.

If you request the same folder several times, the 2 or 3 result is returned correctly.

I have checked the communication on the bus, the result is already sent from the Arduino to the PC before the DFmini has responded.

In the code I found that if you set volume or EQ, the return value is not waited for, if I have understood everything correctly. However, the AA20HFJ648 confirms every command, i.e. if I request the number of files after setting the volume, the confirmation response from volume is in the receive buffer. This data is then interpreted incorrectly and obviously output as -1.

A correction would be to clear the receive buffer before each command is sent to which a response is expected. It would be more elegant to read this confirmation for versions that confirm every command.

HardwareSerial on Mega 2560

Hi, please help me to understand what's going on. When I'm using the SoftwareSerial communication between DFPlayer Mini and Arduino Mega 2560 everething works perfect but when I'm trying to use the HardwareSerials Serial1, Serial2 or Serial3 I'm in the stupid condition

Unable to begin:
1.Please recheck the connection!
2.Please insert the SD card!

My initialization is following

`#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{

Serial.begin(9600);
Serial1.begin(9600);

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);
}
Serial.println(F("DFPlayer Mini online."));

myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms

//----Set volume----
myDFPlayer.volume(10); //Set volume value (0~30).

//----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);

//----Mp3 play----
myDFPlayer.loop(1); //Loop the first mp3

//----Read imformation----
Serial.println(myDFPlayer.readState()); //read mp3 state
Serial.println(myDFPlayer.readVolume()); //read current volume
Serial.println(myDFPlayer.readEQ()); //read EQ setting
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03
}`

Please help me to understand what I'm doing wrong or within your library I can't use the HardwareSerial?

readState()

Serial.println(myDFPlayer.readState());

sometimes while playing returns 513 or stopped 512

but most of the time returns -1 or some other number unless rebooted

using esp8266

It's not working USB.help.

It's not working
myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(110); File Name(11000)
help.
technical translation.
26.08.18 the question is closed. I had mistake.

Exception 28

HI there

I had the previous library running well (ESP8266), but I needed to use folders so want to move to the new library. Fairly simple swap out but getting an exception on setup() as soon as a command issued e.g myDFPlayer.volume(mp3vol);

The whole project code is quite big to post, but all the sample code initialisations have been followed. Anyone else have this running on an ESP?

DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
DFPlayer Mini online.

Exception (28):
epc1=0x4020b28a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

stack>>>

ctx: cont
sp: 3fff32d0 end: 3fff34f0 offset: 01a0
3fff3470: 00000000 3fff0590 3fff0598 4020b305
3fff3480: 00000000 3fff0598 3fff1c50 4020b35b
3fff3490: 00000000 3fff0598 3fff1c50 40207122
3fff34a0: feefeffe feefeffe feefeffe feefeffe
3fff34b0: feefeffe feefeffe feefeffe feefeffe
3fff34c0: feefeffe feefeffe feefeffe 3fff1d70
3fff34d0: 3fffdad0 00000000 3fff1d40 40213a64
3fff34e0: feefeffe feefeffe 3ffe85e0 401017f9
<<<stack<<<

DFPlayer has power, only says 'timeout' in serial monitor when asked to play.

Here is my code:

`#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <Encoder.h>

int relayPin = 7; //Relay Control - Lights
const int buttonPin = 2; // the number of the pushbutton pin
Encoder myEnc(3, 4);
int encoderPos = 0;
const int MIN_POSITION = 0;
const int MAX_POSITION = 30;
boolean encoderALast = LOW; //remembers the previous state of the encoder pin A
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
int playing; //Track playing state
int pause; //is track paused?
int fin; //for interrupting audios
unsigned long pauseTime; //Way to track pause length
unsigned long timeUntilReset = 60000; //how long to wait before reset? (60s)
long currentPosition = 0;
long previousPosition = 0;
boolean printed = false;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 6; // Connects to module's TX
static const uint8_t PIN_MP3_RX = 5; // Connects to module's RX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

// Create the Player object
DFRobotDFPlayerMini myDFPlayer;

void setup() {
pinMode(relayPin, OUTPUT); // Set RelayPin as an output pin
pinMode(buttonPin, INPUT_PULLUP); // Set buttonPin as Input
softwareSerial.begin(9600); //Serial Port for DFPlayer Mini
if (myDFPlayer.begin(softwareSerial)) // Start communication with DFPlayer Mini
{
Serial.println("OK");
}

else {
Serial.println("Connecting to DFPlayer Mini failed!");
}
Serial.begin(9600);
}

void loop() {
int reading = digitalRead(buttonPin); //Read Button State
if (reading != lastButtonState) {
lastDebounceTime = millis(); // reset the debouncing timer
}
volumeControl();

if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
} //Quick check (is track finished?)

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
  buttonState = reading;  //Set Buttonstate to current (i.e. 0 or 1)

  if (buttonState == HIGH) {  //if button pressed, do xyz:

    if (playing == 1) {  //If track is begun (paused or playing), do xyz:
      if (pause == 1) {
        myDFPlayer.advertise(3);  //Play 'Resume'
        delay(1000);
        myDFPlayer.start();  // Resume from pause
        pause = 2;
      }
      if (pause == 0) {
        fin = 1;
        myDFPlayer.stopAdvertise();  //stop advertise to allow 1st track continuation
        myDFPlayer.advertise(2);     //play 'pause'
        delay(1000);
        myDFPlayer.pause();    //pause the mp3
        pauseTime = millis();  //Reset pause timer
        pause = 1;
      }
      if (pause == 2) {
        myDFPlayer.stopAdvertise();  //important so that 'track end' doesnt trigger with end of this track
        pause = 0;
        fin = 0;  //also important, same reason
      }
    }
    if (playing == 0) {              //If track not playing, begin playback
      myDFPlayer.playMp3Folder(1);   // Play the "0001.mp3" in the "mp3" folder on the SD card
      digitalWrite(relayPin, HIGH);  //Turn Lights on
      myDFPlayer.volume(15);     // Set volume to maximum (0 to 30).
      playing = 1;
    }
  }
}

}
// save the reading. Next time through the loop, it'll be the lastButtonState:
lastButtonState = reading;

if ((pause == 1) && ((millis() - pauseTime) > timeUntilReset)) { //if its paused, check if pausetime has elapsed resetTime
playing = 0;
pause = 0;
myDFPlayer.pause(); //pause the mp3
digitalWrite(relayPin, LOW); //Turn Lights off
}
}

void volumeControl() {
long currentPosition = myEnc.read() / 4;
// If it goes beyond 30, set it back to 30
if (currentPosition > MAX_POSITION) {
currentPosition = MAX_POSITION;
myEnc.write(currentPosition * 4); // Update the encoder position
}

// If it goes below 0, set it back to 0
if (currentPosition < MIN_POSITION) {
currentPosition = MIN_POSITION;
myEnc.write(currentPosition * 4); // Update the encoder position
}
// Check if the position has changed
if (currentPosition != previousPosition) {
// Print the clamped position
Serial.println(currentPosition);
//Change Volume
myDFPlayer.volume(currentPosition);

// Update the previous position
previousPosition = currentPosition;
printed = true;

} else {
// If it hasn't changed, reset the printed flag
printed = false;
}
}
void printDetail(uint8_t type, int value) { //Controls various things depending on mp3 state
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!"));
if (fin != 1) {
playing = 0;
digitalWrite(relayPin, LOW); //Turn Lights off
myDFPlayer.pause(); //pause the mp3
}
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;
}
}
`

The board is getting 5V and is wired up as 5V to 5V, GND pins to GND, D5 to a 1k ohm resistor to RX, D6 to TX

Particle Xenon VS 0x3F command

Hello guys !

Sorry if i'm not on the right place, I'm using the DFPlayer with raw commands on a Particle's Xenon board.
Basically i'm doing what's explained here :
https://community.particle.io/t/a-great-very-cheap-mp3-sound-module-without-need-for-a-library/20111

But i have issues with the 0x3F command at the start of the program.
As explained here i don't get the bytes result of the init until i unplug/replug the DFPlayer power.
Only then i get the bytes from Serial1.

I was wondering if you may have any idea why ?

Also, if i just skip this init/check step, it seems to work fine without having to unplug/replug the power.
Do you think it's safe..?

Sorry that it's not the right place for such question as it's not related to the lib, but i couldn't find any place with low-level experts of this board..

I wish you a good day !

Durss

Esp8266

I'm going crazy..

I can't not communicate with the DFPlayer.

If I run it in manual mode I can player a track.. So files system is OK..

I've got a 1k resistor on the tx...

I've tried a wemos d1 Pro and esp8266 all I get is
1.failed to connect
2. Can't read sd card.

Anybody got any ideas?

Cannot connect DFPlayer to Arduino Nano 33 IoT

Hello,
I am trying to connect DFPlayer to Arduino Nano 33 IoT.
I believe I cannot use SoftwareSerial there, but can use HardwareSerial Serial1, connection TX-RX and RX-TX. I also use external power supply for 5V, but it seems to be irrelevant. Player cannot be found with or without it (when Arduino is just connected to PC by USB).

The wiring
ArduinoNano_dfplayer

The code


// Create the DFPlayer Mini object.
DFRobotDFPlayerMini myDFPlayer;


void setup()
{
  Serial.begin(115200);

  // Initiate DFPlayer Mini on the second serial port on RX0 and TX1 pins.
  Serial1.begin(1200); // tried 9600 as well
  while(!myDFPlayer.begin(Serial1))  { Serial.println("Not Connected!"); }

  Serial.println("DFPlayer Connected!!!");
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
  //----Set volume----
  myDFPlayer.volume(30);  //Set volume value (0~30).
  // Set EQ
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  // Set the SD Card as default source.
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
}


void loop()
{
  myDFPlayer.play(1);
  delay(1000);
  myDFPlayer.play(2);
  delay(1000);

}

All I see in Serial Monitor is “Not Connected” messages.

Is there something wrong with my wiring? With the code? Any suggestions are appreciated.
TIA

stuck on play

I don't know why but with the new version 1.0.6 my code gets stuck on play. I use an ESP32. I tried switching between Serial2 and SoftwareSerial - no difference.
#51 (comment)

3C _handleCommand should lead to "DFPlayerPlayFinished" case, not "DFPlayerFeedBack"

The "3C" handleCommand means that a USB track is done playing (like "3D" for the SD Card); therefore this handle command should trigger a "DFPlayerPlayFinished" message, not a "DFPlayerFeedBack" message, otherwise we are not able to be sure that a USB track is done playing.

In other words, please move line 194 to line 161.

Thoughts ?

readFolderCounts returns 1 more than the number of folders

I'm trying to understand why readFolderCounts returns 1 more than the number of folders on my card. I have 3 folders on the card, named 01, 02, and 03. A call to readFolderCounts consistently returns 4. There are no hidden folders on the card from what I can see.

Dfplayer won't start when volume is changed in Void

I am building a Wake Up Light alarm clock. During the alarm the DFplayer should start at a low volume after which the volume should slightly increase.
Strangely whenever I try to change the volume in the function of the alarm, there is no sound coming out of the player.
Any idea how I can fix this?
The alarm function code:

void playAlarm()
{
myDFPlayer.volume(2); // Whenever this line is removed it does work
myDFPlayer.play(1);
brightness = 30;
analogWrite(led, brightness);
delay(5000);
myDFPlayer.volume(6);
brightness = 60;
analogWrite(led, brightness);
delay(5000);
myDFPlayer.volume(8);
brightness = 90;
analogWrite(led, brightness);
delay(5000);
myDFPlayer.volume(10);
brightness = 120;
analogWrite(led, brightness);
delay(5000);
myDFPlayer.volume(15);
brightness = 5;
analogWrite(led, brightness);
}

Arduino Stuck after trying to stop DFPlayer

Hello, since the new library version 1.0.6 , arduino stuck into an infinite loop when we play a music and we try to stop it.

The issue can be reproduced if the ack mode is set to true, then you play a music, and then you stop it with the DFPlayer function

The issue come from a change on the sendStack and available function.

it seams when you sendStack Stop (command 0x16) DFplayer do not reply or there is no catch in switch case in the available() function and _isSending is never set to false as the handleError is not called anymore, and you are stuck in the while loop in the sendStack function.

void DFRobotDFPlayerMini::sendStack(){ if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition **while (_isSending) { delay(0); waitAvailable(); }** }

the romoval of the following code in DFRobotDFPlayerMini::available(){ function is responsible of the DFplayer stuck :
if (_isSending && (millis()-_timeOutTimer>=_timeOutDuration)) { return handleError(TimeOut); }

This need to checked back and be fixed as the dfplayer is no more really usable.

API ??

I want to read the API Code Docu. can some one share it ?

ESP8266 (12e) support?

How can I use this library with ESP8266 (12e)?
The esp8266 module reboots.
I have a problem with the code examples FullFunction.ino

...libraries\DFRobotDFPlayerMini-1.0.0/DFRobotDFPlayerMini.cpp line 79
...esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56
...esp8266\hardware\esp8266\2.3.0\cores\esp8266/cont.S line 109

ps. With Arduino UNO and Pro Micro all goes well.
thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.