Esp32 falling in boot loop

Hi,

I want to make a simple car engine coolant temperature gauge. I’m utilizing Elmdunio library . It uses elm327 to communicate with car canbus system and transfers data to esp32 via bluetooth.
I have tested it and I get correct values and communication is ok.
Now the issues.

I’ve designed the UI - and that part works perfectly on my ESP32 and TFT lcd display.

  • Now the issue is when I join the Elmduino library into my UI.
  • I get stuck in boot loop
    -I get screen corruption.

This is the UI code ( works without no issues)

#include <lvgl.h>
#include <TFT_eSPI.h>
#include <ui.h>



extern lv_obj_t *ui_Arc2;
extern lv_obj_t *ui_Temp;


/*Don't forget to set Sketchbook location in File/Preferencesto the path of your UI project (the parent foder of this INO file)*/



/*Change to your screen resolution*/
static const uint16_t screenWidth  = 320;
static const uint16_t screenHeight = 240;

static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * screenHeight / 10 ];

TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */

#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(const char * buf)
{
    Serial.printf(buf);
    Serial.flush();
}
#endif

/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
    uint32_t w = ( area->x2 - area->x1 + 1 );
    uint32_t h = ( area->y2 - area->y1 + 1 );

    tft.startWrite();
    tft.setAddrWindow( area->x1, area->y1, w, h );
    tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
    tft.endWrite();

    lv_disp_flush_ready( disp );
}




void setup()
{
  
    Serial.begin( 115200 ); /* prepare for possible serial debug */

  

    String LVGL_Arduino = "Hello Arduino! ";
    LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();

    Serial.println( LVGL_Arduino );
    Serial.println( "I am LVGL_Arduino" );

    lv_init();

#if LV_USE_LOG != 0
    lv_log_register_print_cb( my_print ); /* register print function for debugging */
#endif

    tft.begin();          /* TFT init */
    tft.setRotation( 3 ); /* Landscape orientation, flipped */

    lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 10 );

    /*Initialize the display*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init( &disp_drv );
    /*Change the following line to your display resolution*/
    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 );

    /*Initialize the (dummy) input device driver*/
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init( &indev_drv );
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_register( &indev_drv );


    ui_init();

    Serial.println( "Setup done" );
}

void loop()
{
   
    // Let the LVGL GUI do its work
    lv_timer_handler(); 
    delay(5); // Small delay for stability
}

This is the Elmduino code that i need to merge into my UI.

#include "BluetoothSerial.h"
#include "ELMduino.h"


BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial


ELM327 myELM327;


uint32_t rpm = 0;


void setup()
{
#if LED_BUILTIN
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
#endif

  DEBUG_PORT.begin(115200);
  //SerialBT.setPin("1234");
  ELM_PORT.begin("ArduHUD", true);
  
  if (!ELM_PORT.connect("OBDII"))
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    while(1);
  }

  if (!myELM327.begin(ELM_PORT, true, 2000))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }

  Serial.println("Connected to ELM327");
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
    myELM327.printError();
}

-Note My goal it’s to pull engineCoolantTemperature so the code looks like this.

#include <lvgl.h>
#include <TFT_eSPI.h>
#include <ui.h>
#include "BluetoothSerial.h"
#include "ELMduino.h"

BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial

ELM327 myELM327;
uint32_t rpm = 0;

extern lv_obj_t *ui_Arc2;
extern lv_obj_t *ui_Temp;

/* Screen resolution */
static const uint16_t screenWidth  = 320;
static const uint16_t screenHeight = 240;

/* Display buffer */
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * screenHeight / 10 ];
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */

#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(const char * buf)
{
    Serial.printf(buf);
    Serial.flush();
}
#endif

/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
    uint32_t w = ( area->x2 - area->x1 + 1 );
    uint32_t h = ( area->y2 - area->y1 + 1 );

    tft.startWrite();
    tft.setAddrWindow( area->x1, area->y1, w, h );
    tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
    tft.endWrite();

    lv_disp_flush_ready( disp );
}

void setup()
{
    Serial.begin(115200); /* Serial initialization */

    String LVGL_Arduino = "Hello Arduino! ";
    LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
    Serial.println(LVGL_Arduino);
    Serial.println("I am LVGL_Arduino");

    lv_init();

    tft.begin();          /* TFT init */
    tft.setRotation(3);   /* Landscape orientation, flipped */

    lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * screenHeight / 10 );

    /* Initialize the display */
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    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);

    /* Initialize the (dummy) input device driver */
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_register(&indev_drv);

    ui_init(); /* Initialize UI */

    SerialBT.begin("ArduHUD", true); /* Bluetooth initialization */
  
    if (!SerialBT.connect("OBDII"))
    {
        Serial.println("Couldn't connect to OBD scanner - Phase 1");
        while(1);
    }

    if (!myELM327.begin(ELM_PORT, true, 2000))
    {
        Serial.println("Couldn't connect to OBD scanner - Phase 2");
        while (1);
    }

    Serial.println("Connected to ELM327");

    Serial.println("Setup done");
}

void loop()
{
   float coolantTemp = myELM327.engineCoolantTemp(); // Read Oil Temperature

    if (myELM327.nb_rx_state == ELM_SUCCESS) {
        // Round the coolant temperature to the nearest whole number
        int roundedCoolantTemp = round(coolantTemp);

        // Update the UI elements with the rounded coolant temperature
        lv_arc_set_value(ui_Arc2, roundedCoolantTemp); // Update the arc
        lv_label_set_text_fmt(ui_Temp, "%d°C", roundedCoolantTemp); // Update the temperature label
    } else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
        
    }
    lv_timer_handler(); // Let the LVGL GUI do its work
    delay(5); // Small delay for stability
}

I’ve tried many thing but everything leads to boot loop, or corrupted screen.
ui.zip (42.1 KB)

Does someone know why I get into the boot loop. I tried many thing but same issue I posted the issue on SquareLine studio forum topic ( Esp32 rebooting - debugging - #9 by Amer7 - How to - Forum - SquareLine Studio) But maybe here i get a better reach?

Just to add The code works great, and display works … Until I power off the ESP32, when I power it ON i get corrupted screen.
After If i compile and upload the same sketch- Still Corrupted screen image.

With the last code I posted I don’t get into a boot loop but image on the screen is disrupted/

rst:0x1 (POWERON_RESET),boot:0x17 (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:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
Hello Arduino! V8.3.7
I am LVGL_Arduino

I’ve tried enabling debbuging in the config but i dont get more information than up top. Does anyone know whats the issue now?

I can confirm that the tft_espi display drivers and ELMduino library worked without an issue- and displayed data on the LCD before implementing the LVGL ui.

I’ve hit a brake thru. Eureka!
I’ve been reading a bit of documentation and something came across that loops should be put in lv_timer_handler();

So when i put my ELMDUINO if loop that is in the setup() in lv_timer_handler();
the display comes back to life, and no more boot loop!