TroubleshootingArduino

DFPlayer - Serial receiving error (a frame has not been received completely yet)

userHead Delta.Pie 2023-07-04 01:46:56 397 Views1 Replies

Hi, I have been recently working on a project including the DFPlayer Mini, and I am running into some trouble with the following error: Serial receiving error(a frame has not been received completely yet) 

This is coming from the printError() function in the DFPlayerMini_Fast library.

I get a similar error if I use the DFRobotDFPlayerMini library: SerialWrongStack Error

Not sure what is wrong, I have it wired the same as the diagram on the wiki: https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299

 

Both of these errors occur when I try to start playing music by pressing the play/pause button

 

Thanks for any help/suggestions.

 

 

Here is the entirety of my code, it adds code for rotary encoder and LCD:

 

#include <FireTimer.h>

#include <DFPlayerMini_Fast.h>

// include the library code:
#include <LiquidCrystal.h>

// Rotary Encoder Inputs
#define CLK 2
#define DT 3
#define SW 12

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 11, en = 10, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Create the Player object
DFPlayerMini_Fast  player;

//this is so that we can declare the LCD_Update method properly
void LCD_Update(String lineone, String linetwo="");

String currentLCDline1 = "Loading.........";
String currentLCDline2 = "#-#-#-#-#-#-#-#";

//Stores current play/pause state (starts paused)
int playpause = 0;
//number of files in sd card
int FILENUM = 0;
//starts instead of resumes if its our first time
bool firstStart = true;
//stores last button press type
int lastSwitchState =0;
//for long press/short press code
long buttonStartTime = 0;
long longPressTime = 250;

bool wasJustPressed = false;


//rotary encoder
int clkPinLast = LOW;
int clkPinCurrent = LOW;


///methods needed to be used in start=====================================================================

//updates LCD to lineone, with the ability to change line two as well
void LCD_UpDate(String lineone,String linetwo="")
{
 lcd.clear();
 
 lcd.print(lineone);
 currentLCDline1 = lineone;
 if(linetwo != "")
 {
   lcd.setCursor(0,1);
   lcd.print(linetwo);
   lcd.setCursor(0,0);
   currentLCDline2 = linetwo;
 }
 else
 {
   currentLCDline2 = linetwo;
 }
}

//=====================================================================================================

void setup() {
 // Init USB serial port for debugging
 Serial.begin(115200);
 
 Serial.println("Setting up");
 // Set encoder pins as inputs
 pinMode(CLK, INPUT);
 pinMode(DT, INPUT);
 pinMode(SW, INPUT);
 // Init serial port for DFPlayer Mini
 Serial1.begin(9600);
    Innit_LCD();
 //initialize the music player
 Innit_SDPlayer();
}

//main loop===========================================================================================
void loop() 
{
 //check rotary encoder (button and all)
   updateEncoder();
   
//  //Serial.println("Playing");
//  //check dfrobot 
//  if (player.available()) {
//    //update SD player
//    printDetailAndUpdateSong(player.readType(), player.read());
//  }

 player.printError();
 delay(50);
 //update lcd with our strings
 LCD_UpDate(currentLCDline1,currentLCDline2);
 
}


//lcdplay innitilization
void Innit_LCD()
{
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 LCD_UpDate(currentLCDline1,currentLCDline2);
 delay(1000);
}

//sd card player functions
//==================================================================================================
void Innit_SDPlayer()
{
 // Start communication with DFPlayer Mini
 if (player.begin(Serial1, true))
 {
   Serial.println("OK");
   //set timeout for communication
   player.setTimeout(2000);
   
   LCD_UpDate("SD Innitalized");
   FILENUM = player.numSdTracks();
   // Set volume range (0 to 30). some day maybe have a long press for the SW allow this volume to be changed...
   player.volume(20);
   
 } else {
   Serial.println("Connecting to DFPlayer Mini failed!");
   //display on LCD
   LCD_UpDate("SD Player Failed");
 }
}


//play or pause player
void playPauseSD()
{
 if(playpause == 0)
 {
   if(firstStart){
     player.startRepeatPlay();
     firstStart = false;
     }
   playpause = 1;
   player.resume();
 }
 else
 {
   playpause = 0;
   player.pause();
 }
}

 

//=================================Rotary Encoder methods========================================================
void updateEncoder(){
int switchState = digitalRead(SW);

//button code
if (switchState == HIGH&& switchState != lastSwitchState) {
 wasJustPressed = true;
 //was pressed, lets start counting how long it is held down.
 buttonStartTime = millis(); //this is okay because this wont run unti, there is a low and then high again (another button press)
}
else if(switchState == LOW)
{
 long endtime = millis();
 //button was either just released or never pressed, so lets check to see which it is
 if(wasJustPressed)
 {
   //look at how long it was held down, if its a short press play/pause the music (stop - start = time elapsed0
   if((endtime-buttonStartTime) < longPressTime)
   {
      //short press code
           //play or pause
           playPauseSD();
           delay(30);
           if(playpause == 0){
                 Serial.println("Paused");
                 currentLCDline1 = ".....Paused.....";
                 currentLCDline2 = "";
     }else if(playpause == 1){
         Serial.println("Playing");
         currentLCDline1 = "Playing from SD";
         currentLCDline2 = ("Num: "+String(player.currentSdTrack())+"/"+FILENUM);
       }
       
   }
   else
   {
     //long press code
     Serial.println("Pressed for over longPressTime milliseconds");
   }
   wasJustPressed=false;
 }
}
lastSwitchState = switchState;


//make sure that we are not paused
 if(playpause == 1){
 clkPinCurrent = digitalRead(CLK);

 if ((clkPinLast == LOW) && (clkPinCurrent == HIGH)) {
   if (digitalRead(DT) == HIGH) {
     //change song forward
     Serial.println("Next...");
     player.playNext();
     delay(30);
     //display on lCD
     currentLCDline1 = "Playing from SD";
     currentLCDline2 = ("Num: "+String(player.currentSdTrack())+"/"+FILENUM);
   }
   else {
     //change song backward
     Serial.println("Previous..");
     player.playPrevious();
     delay(30);
     //display on lCD
     currentLCDline1 = "Playing from SD";
     currentLCDline2 = ("Num: "+String(player.currentSdTrack())+"/"+FILENUM);
   }
 }

 clkPinLast = clkPinCurrent;
   }
 }

 

 

2023-07-04 16:06:34

I think you didnot use the official library provide by the DFRobot.

DFRobot official libaray is on this Github:

https://github.com/DFRobot/DFRobotDFPlayerMini

 

And this library didnot have the printError() function.

 

 

You could refer to this wiki for the detail usage:

https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299#target_6

userHeadPic Yeez_B