LVGL and WebServer with ESP32-WROM-32 is Crash

I need help, please.

I’m trying to run code with LVGL + WebServer…

The screen appears normally and shows the interface I wrote, but when I open the web page, it restarts the ESP32…

What could be happening?

This error:

This is my code:

extern "C"{
    #include "freertos/FreeRTOS.h"
    #include <freertos/task.h>
    #include "freertos/timers.h"
}

//Bibliotecas
      #include <WiFi.h>        // ESP32 Core WiFi Library    
      #include <ArduinoJson.h>
      #include <SPIFFS.h>
      //#include <AsyncWebServer_WT32_ETH01.h> // Funcionava perfeito nessa biblioteca....Troquei para outra para ver se dá bom com o LVGL
      #include <AsyncTCP.h>
      #include <ESPAsyncWebSrv.h>
      #include <WiFiUdp.h>
      //#define DEBUG_BER
      #include <Arduino_SNMP_Manager_02.h>
      #include <lvgl.h>
      #include <TFT_eSPI.h>
      #include "ui.h"

//Declaração das funções relacionadas ao SNMP no Conceito do Multiprocessamento      


TaskHandle_t Task1Handle, Task2Handle;

//Variaveis usadas no Display
      static const uint16_t screenWidth  = 480;
      static const uint16_t screenHeight = 320;
      uint16_t calData[5] = { 353, 3568, 269, 3491, 7  };     /*touch caldata*/
      TFT_eSPI lcd = TFT_eSPI(); /* TFT entity */
      static lv_disp_draw_buf_t draw_buf;
      static lv_color_t buf1[ screenWidth * screenHeight / 13 ];

// Variables usadas no setup para configurações do usuario
      bool Run;
      String str_Modo;

      String Wifi_SSID;
      String Wifi_Pass;

      uint8_t SNMP_TimeOut;
      uint32_t SNMP_Port;

      String str_Community;

      //const int snmpVersion = 1; // SNMP Version 1 = 0, SNMP Version 2 = 1
      uint8_t snmpVersion; 


//Variaveis de uso interno do Sistema
      String wifiConnected = ""; //Variável para controle do nome da rede conectada
      IPAddress targetIP[5] = { IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0) };
      
      IPAddress last_targetIP[5] = { IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0), IPAddress(0,0,0,0) };
      uint8_t last_pos;

      //unsigned int ifSpeedResponse[5];
      unsigned int inOctetsResponse[5];
      unsigned int outOctetsResponse[5];
      unsigned int lastInOctets[5];
      unsigned int lastOutOctets[5];

      float rateIn[5];
      float rateOut[5];
/*
      int servicesResponse[5];
      char sysName0[30];
      char sysName1[30];
      char sysName2[30];
      char sysName3[30];
      char sysName4[30];
      char *sysNameResponse[] = {sysName0,sysName1,sysName2,sysName3,sysName4};  
*/
      char sysInterfaceName[20]; 
      char *sysInterfaceNameResponse = sysInterfaceName;

//Variaveis da Matriz de IP's (Devices usados) e Interfaces
      const int MAX_DEVICE_COUNT = 5;
      const int MAX_INTERFACE_COUNT = 5;
      
      bool Device[MAX_DEVICE_COUNT];
      String ipArray[MAX_DEVICE_COUNT];
      int ipCount = 0;               
      
      bool xInterface[5];
      int xInterfaceIP[5];


// OIDs
      char *oidInOctetsCount32[] = {NULL, NULL, NULL, NULL, NULL}; // Counter32 ifInOctets.4
      char *oidOutOctetsCount32[] = {NULL, NULL, NULL, NULL, NULL}; // Counter32 ifOutOctets.4
      //char *oidSysName[] = {NULL, NULL, NULL, NULL, NULL};              // OctetString SysName
      char *oidInterfaceName[] = {NULL, NULL, NULL, NULL, NULL};              // OctetString SysName
      char *oidUptime_S = ".1.3.6.1.2.1.1.3.0";
      //char *oidSysName_S = ".1.3.6.1.2.1.1.5.0";   

      //long long unsigned int hcCounter[5];
      
      unsigned int uptime[5];
      unsigned int lastUptime[5];

      unsigned long pollStart = 0;
      unsigned long intervalBetweenPolls = 0;
      uint8_t pollInterval = 1500; // delay in milliseconds
      
// Objects
      DynamicJsonDocument json(1024);
      //DynamicJsonDocument DocNet(1024);
      DynamicJsonDocument oJsonRun(2048);
      JsonArray jsonArrayRun;

      #define FileFS SPIFFS
      #define FORMAT_SPIFFS_IF_FAILED true
      
      FS* filesystem = &SPIFFS;
      const char* conf_Setup = "/conf_Setup.json";
      const char* conf_SetupWifi = "/conf_SetupWifi.json";
      const char* conf_Networks = "/conf_Networks.json";
      const char* conf_ScanDevice = "/conf_ScanDevice.json";
      const char* conf_ScanInterface = "/conf_ScanInterface.json";
      const char* conf_SetupInterface = "/conf_SetupInterface";

      const char* fileWRITE = "WRITE";
      const char* fileAPPEND = "APPEND";

      AsyncWebServer server(80); //Objeto WebServer
      
      WiFiUDP udp;
      SNMPManager snmp = SNMPManager();
      SNMPGet snmpRequest; 

// Blank callback pointer for each OID
      ValueCallback *callbackInOctets[5];
      ValueCallback *callbackOutOctets[5];
      ValueCallback *callbackSysName[5];
      ValueCallback *callbackUptime[5];
      ValueCallback *callbackInterfaceName;


void loop_Display(void *pvParameters) {
  (void)pvParameters;
      for (;;) {
          lv_timer_handler();
          vTaskDelay(10 / portTICK_PERIOD_MS);

      }
}

void loop_SNMP(void *pvParameters) {
  (void)pvParameters;
      for (;;) {
            if (Run && str_Modo == "Station"){
                snmp.loop();
                intervalBetweenPolls = millis() - pollStart;
                if (intervalBetweenPolls >= pollInterval){
                    pollStart += pollInterval; // this prevents drift in the delays
                    f_AllDevices();
                }
            }
            vTaskDelay(10 / portTICK_PERIOD_MS);
      }
}



void setup(){
      Serial.begin(115200);
      SetupFS();
      readConfigFile();
      if (str_Modo == "AP"){
          wifiScanOpenNet(); //Precisa avaliar - O quanto isso impacta 
          setupWifi_AP();
      }
      else if (str_Modo == "Station"){
          setupWifi_Cli();
          setupMainSNMP();
          f_SetupAllDevices();
      }
      setupWebServer();
      setupDisplay();

      xTaskCreatePinnedToCore(loop_Display, "loop_Display", 10000, NULL, 1, &Task1Handle, 1);
      xTaskCreatePinnedToCore(loop_SNMP, "loop_SNMP", 10000, NULL, 1, &Task2Handle, 1);
}

void loop(){

     
}

This is my webpage

And my Display:

image

A conversa de tudo isso é que eu desativo o lv_timer_handler();

Não tenho nenhum erro.

O que pode ser?

Alguém tem ideia de qual caminho devo seguir?

I am not seeing where you have started LVGL anywhere in your code but you are instructing LVGL to update the task handler when it’s not even running.

I like to put it in functions external to Setup() because it is more organized and with a more simplistic logic. Of course I don’t know if this is right or wrong.

In the case of the code I put in the Post above, I call the function: setupDisplay()

Which will trigger this code:


void setupDisplay(){
        pinMode(25, OUTPUT);
        digitalWrite(25, LOW);

        lcd.begin();          
        lcd.setRotation(1); 
        lcd.fillScreen(TFT_BLACK);
        lcd.setTouch(calData);
        delay(100);
        //background light pin
        pinMode(27, OUTPUT);
        digitalWrite(27, HIGH);

        lv_init();
        
        lv_disp_draw_buf_init( &draw_buf, buf1, NULL, screenWidth * screenHeight / 13 );

        static lv_disp_drv_t disp_drv;
        lv_disp_drv_init( &disp_drv );
        //Display driver port of LVGL
        disp_drv.hor_res = screenWidth;
        disp_drv.ver_res = screenHeight;
        disp_drv.flush_cb = my_disp_flush;
        disp_drv.draw_buf = &draw_buf;
        lv_disp_drv_register( &disp_drv );

        static lv_indev_drv_t indev_drv;
        lv_indev_drv_init( &indev_drv );
        indev_drv.type = LV_INDEV_TYPE_POINTER;
        indev_drv.read_cb = my_touchpad_read;
        lv_indev_drv_register( &indev_drv );

        ui_init();        //LVGL UI init

        lv_label_set_text(ui_txtIP, WiFi.localIP().toString().c_str() );

}

the code still isn’t complete, missing the flush function.

Anywho, typical bug hunting when there is no real indicator of where the issue might be stemming from says to comment out everything and add things back in one at a time until it freaks out. then you know where your problem is, or at least you have narrowed it down.

I would comment out all of the stuff for the display and LVGL and leave only the WiFi parts and see if the code will run. If it will then comment out the WiFi and add back in the LVGL and display stuff and see if it runs. If it does then there is some kind of bumping of heads between the 2 that could be hardware related.

Would it be possible for you to send me a sample code for initializing LVGL?

For example with the flush function?

Yes, in my test, that’s exactly what’s happening. When I put LVGL and WEBSERVER together, it crashes and behaves strangely. When I just leave the Web without LVGL, it’s perfect. I don’t know what to do.

This could be a hardware issue. I need to now what pins you are using for the display and what pins for the touchscreen. I also need to know what ESP32 you are using. I will check to see if there are any issues between the WiFi and the pins. If there isn’t then we can dive into the software end of things.


This ESP32:

First of all, I would like to thank you very much for the help you are giving me. I know you’re under no obligation to help me, and yet you’re being so patient and helping me.

I want to thank you very, very much for your community spirit of brotherhood. Thank you, thank you a thousand times!

.
DIS05035H-ESP32-V1.0-20230309.pdf (53.2 KB)

https://www.elecrow.com/wiki/index.php?title=ESP32_Display_3.5''_Intelligent_Touch_Screen_Wi-Fi%26BLE_320*480_HMI_Display

Not a big deal. I will help you get this all sorted out. Just have to figure out where the issue is stemming from is all.

All right, I actually gave up on using freertos in this code. I removed everything and it worked fine.

dumb question here. What do you have the display plugged into for power? If you are using the USB Port on a PC you need to make sure that it is a high output USB port. You will not be able to power the display and the ESP32 with the WiFi running. The ESP32 is going to draw close to 1/2 an amp with the WiFi on and the display when powered on with the backlight lit is going to draw more than 1/2 an amp. You will be right at the line of the maximum power from a PC USB port. I would check you voltage when you are running it and make sure it stays pretty stable when you turn it on. If you see the voltage on the USB port dropping then you know you have hot the limits of what the PC port is going to be able to provide. This can cause goofy things to happen like what you are seeing.

can you zip up all of your source files and attach them to a post please. I need to make sure everything is set up correctly…

1 Like

Wow, you’re absolutely right. Yes, I was only using the PC’s USB port and from time to time the screen restarts and crashes. So the power supply must not be sufficient.

Thanks for the advice, I hadn’t realized that.

I no longer have all the files that were giving me problems. Because I removed FreeRTOs. So the code I have now is modified and no longer giving problems.

I really appreciate the help you offered me in this post. You really are a brother.

I’m trying to learn LVGL and I would be very grateful if you could help me with another issue but I have to open another topic. If you can help me, I’d really appreciate it.

Just hit me up when you have an issue. If I am able to help you out I will. Glad to know the problem is now solved. I just had to look at the hardware setup to be able to figure it out.