When i using lvgl, my dfplayer not working properly

when i using xTaskCreate in my setup, and using dplayer, mydfplayer not working properly, anyone can help me?

What do you mean by not working properly. We need to know more detail to help.

My first guess is the stack size of LVGL is too small in xTaskCreate.

1 Like

when i am making, User interface dynamic, example for wifi status connectWIFI() this function to connect wifi and update icon of wifi status, but when i using this function, the dfplayer does not finish the mp3, but when I comment connectWIFI() the mp3 sound is working until it finish,
when i disable xTaskCreate on connectWIFI it working, and i need to press reset button and gui showing, when i using, Serial2
this little of my code, I am using esp32 and ILI19132


void setup {
Serial.begin(9600);
Serial2.begin(9600);
delay(100);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));


if (!mp3.begin(Serial2)) { //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."));

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

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

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

mp3.outputDevice(DFPLAYER_DEVICE_SD);



xTaskCreate(guiTask,
    "gui",
    4096 * 2,
    NULL,
    2,
    NULL);
networkScanner();
connectWIFI();

}

void loop() {

        static unsigned long timer = millis();

        if (millis() - timer > 3000) {
            timer = millis();
            Serial.println("loop");
            mp3.next(); //Play next mp3 every 3 second.
        }

}

 void connectWIFI() {
            Serial.println("Coba menghubungkan dengan wifi");
            if (ssidName == NULL || ssidName.length() < 1 || password == NULL || password.length() < 1) {
                return;
                Serial.println("Password dan ssid kosong");
                Serial.println(ssidName);
                Serial.println(password);

            }
            Serial.println(ssidName);
            Serial.println(password);
            vTaskDelete(ntScanTaskHandler);
            vTaskDelay(500);
            xTaskCreate(beginWIFITask,
                "BeginWIFITask",
                2048,
                NULL,
                0, &
                ntConnectTaskHandler);
 }

I suggest commenting out the whole content of guiTask and enable it in small steps to see what line causes the issue.

I found the , xTaskCreate(beginWIFITask, is the problem when I uncomment this function it working normally,
i also delete comment all function inside `void beginWIFITask(void *pvParameters) but still same the player not finish the mp3,
but I don’t know how to do next


void connectWIFI(){
  Serial.println("Coba menghubungkan dengan wifi");
  if(ssidName == NULL || ssidName.length() <1 || password == NULL || password.length() <1){
    return;
     Serial.println("Password dan ssid kosong");
      Serial.println(ssidName);
       Serial.println(password);
      
  }
  Serial.println(ssidName);
  Serial.println(password);
  vTaskDelete(ntScanTaskHandler);
  vTaskDelay(500);
  xTaskCreate(beginWIFITask,
                "BeginWIFITask",
                2048,
                NULL,
                0,
                &ntConnectTaskHandler);                
}




void beginWIFITask(void *pvParameters) {

  updateBottomStatus(LV_COLOR_TEAL,"Connecting WIFI: " + ssidName);
 isConnected = true;
     setConnectIcon(true);
  unsigned long startingTime = millis();

  WiFi.begin(ssidName.c_str(), password.c_str());
  while (WiFi.status() != WL_CONNECTED && (millis() - startingTime) < timeout)
  {
    vTaskDelay(250);
  }

   if(WiFi.status() != WL_CONNECTED) {
    updateBottomStatus(LV_COLOR_RED, "Please check your wifi password and try again.");
    isConnected = false;
    setConnectIcon(false);
    vTaskDelay(2500);
    networkScanner();
    vTaskDelete(NULL);
  
  }else{
     isConnected = true;
     setConnectIcon(true);
  }
  
  updateBottomStatus(LV_COLOR_GREEN, "WIFI is Connected! Local IP: " +  WiFi.localIP().toString());
    networkScanner();
    vTaskDelete(NULL);
}

If the issue is unrelated to LVGL you should post the issue into the forum of the problematic part.

i think it related to LVGL, because

 xTaskCreate(beginWIFITask,
                "BeginWIFITask",
                2048,
                NULL,
                0,
                &ntConnectTaskHandler);

is to update icon of status connection


void beginWIFITask(void *pvParameters) {

  updateBottomStatus(LV_COLOR_TEAL,"Connecting WIFI: " + ssidName);
 
  unsigned long startingTime = millis();

  WiFi.begin(ssidName.c_str(), password.c_str());
  while (WiFi.status() != WL_CONNECTED && (millis() - startingTime) < timeout)
  {
    vTaskDelay(250);
  }

   if(WiFi.status() != WL_CONNECTED) {
    updateBottomStatus(LV_COLOR_RED, "Please check your wifi password and try again.");
    isConnected = false;
    setConnectIcon(false);
    vTaskDelay(2500);
    networkScanner();
    vTaskDelete(NULL);
  
  }else{
     isConnected = true;
     setConnectIcon(true);
  }
  
  updateBottomStatus(LV_COLOR_GREEN, "WIFI is Connected! Local IP: " +  WiFi.localIP().toString());
    networkScanner();
    vTaskDelete(NULL);
}

void updateConnection(bool isOn){
  if(isConnected != isOn){
    isConnected = isOn;
    setConnectIcon(isOn);
  }
}

void setConnectIcon(bool isOn){
   vTaskDelay(500);
  LV_IMG_DECLARE(reload_icon);
   LV_IMG_DECLARE(rfid_icon);
    LV_IMG_DECLARE(wifi_off_icon);
   
    lv_obj_clean(cont);

     lv_obj_t * imgbtn1 = lv_imgbtn_create(cont, NULL);
     lv_imgbtn_set_src(imgbtn1, LV_BTN_STATE_RELEASED, isOn ? &rfid_icon : &wifi_off_icon);
     lv_imgbtn_set_src(imgbtn1,LV_BTN_STATE_PRESSED, &reload_icon);
//     lv_imgbtn_set_checkable(imgbtn1, true);
     lv_obj_set_click(imgbtn1, true);
      lv_obj_set_event_cb(imgbtn1, connect_wifi_handler);
     lv_obj_align(imgbtn1, NULL, LV_ALIGN_CENTER, 0, 0);
}

We need an error message or log to see what could be the issue.

I suggest enabling all ASSERTs and logging with TRACE level in lv_conf.h.

1 Like

i wass, enabeling all Asserts, but nothing to show in Serial Monitor
this my lv_conf.h

You should

 # define LV_LOG_LEVEL LV_LOG_LEVEL_TRACE
 # define LV_LOG_PRINTF 1

Or if printf is not redirected to the serial port register a custom print function.