How to display sensor data on LCD more efficeintly?


I am running a code on ESP IDE for WT32-SC01 Plus Touch LCD which has a ESP32 S3 MCU.
I am displaying 60 float numbers on a page that is under menu section of my UI. The way I hav implemented it works but it seems super inefficient and I can see my LCD is struggling to update the numbers (CPU usage goes to 98%). How ever, I can not find any other way to do it. Can anyone suggest a better way?

Here is the simplified code:

The code block(s) should be formatted like:

void Rate_0(void *pvParameter)
	           TickType_t xLastWakeTime0;
		    const TickType_t xFrequency = 1 / portTICK_PERIOD_MS; // 1000 Hz
		    xLastWakeTime0 = xTaskGetTickCount();

		    char str[25];

	 while (1) {


	                                      sprintf(str, "Status: %.2f", *(IncomingData485 +0)); 
	       		                      lv_label_set_text(ui_Status, str);
	       		                      sprintf(str, "ArmPos1: %.2f", *(IncomingData485 +1)); 
	       		                      lv_label_set_text(ui_ArmPos1, str);
	       		                      sprintf(str, "ArmPos2: %.2f", *(IncomingData485 +2)); 
	       		                      lv_label_set_text(ui_ArmPos2, str);
	       		                      sprintf(str, "ArmPos58: %.2f", *(IncomingData485 +58)); 
	       		                      lv_label_set_text(ui_ArmPos58, str);
	       		                      sprintf(str, "ArmPos59: %.2f", *(IncomingData485 +59)); 
	       		                      lv_label_set_text(ui_ArmPos59, str);

	    	vTaskDelayUntil(&xLastWakeTime0, xFrequency);

extern "C" void app_main(void)
	  /* Initialize model */

	  xTaskCreate(Rate_0, "Rate_0", 10240 , NULL, configMAX_PRIORITIES-1,NULL);


As you can, these numbers are getting updated 1000 times per second in my loop. However, I do not need them to be updated all the time. I only want them updated when I go to that specific page in my menu UI. when I actually try to see them.

  • How can I make them run only when that page is showing?
  • Is it even an efficient way to put the number in a string then use “lv_label_set_text” to update it on screen? is there any other way?

PS. The code freaks out if I take the “lv_label_set_text” functions out of “lv_timer_handler” task and put it in another task with a different rate or even if I put them all in an “if” condition that makes it run less frequent. Not sure why that happens. By freaking out I mean it interrupts other features in my code and they wont work properly.

How is your 485 speed? Is realy every 1ms new data ? Is all data changed ?
Font redered size?
Only optimize way is update only real new changed values.

1 Like

thanks so much for your response.
My 485 data is getting updated only in 10H. and yes all data is changing. (but if I move the “lv_label_set_text” into a 10Hz loop, it makes my 485 communication freak out every now and then and eventually screen goes on and off)
Font size is 14. (does this matter on the efficiency?)
can you please elaborate on the optimization. How do you do it practically?
My main question is:
Is this really the right way to display the data? Should they be in the main loop or they should be in the other generated files by squareline that I am not aware of?


No your code isnt right way for use lvgl. You dont show where and how you receive data, but simply all on display changes is event based. Only animations is exception and is time based and handled for you …
Create 1000Hz loop is waste of … and 10Hz is slow because lvconf file define minimum speed. Normal way is use code as in examples.
In 485 code after receive full pack set bool to true and in loop if bool update …
And updates only changed values if float != floatnew…

The problem is when I move the “lv_label_set_text” into a 10Hz loop or in if condition brackets, it makes LCD freak out every now and then and eventually screen goes on and off.
It seems like lvgl does not like it when you run “lv_label_set_text” commands at a different speed than lv_timer_handler().