Trouble with updating the GUI's texts and graphs on STM32F769-DISCO

Description

I am trying to get the text on my GUI to update. Every time there’s a new value updated via UART, the text should automatically update itself. For example, if text A has a new value, text A is updated while the other tabs are kept the same.

What MCU/Processor/Board and compiler are you using?

STM32F769-DISCO

What LVGL version are you using?

v8.0

What do you want to achieve?

To update the text in my GUI.

What have you tried so far?

Every time there’s a new value for a variable sent via UART, it’s ‘rewritten’ but there’s no change in the GUI. Shouldn’t lv_task_handler() automatically update the GUI or do I have to call something like lv_chart_refresh to refresh a particular part of the GUI? Also, I’ve removed HAL_Delay(5) as it causes problems with other functions. I’m not sure if it affects it or not.

Thank you for your help!

What code are you using?

Hi, thank you for your reply. I am using my own code, but it’s based on the STM32F769-DISCO demo. As my code is way too long, I’ve made a short demo of what I’m trying to do below. Essentially, the variables ‘Val’ is an external variable that updates when there’s data in the UART. The GUI should then update the text according to what the UART has received.

Main code:


int main(void) {
	CPU_CACHE_Enable();
	HAL_Init();  //Initialise HAL
	SystemClock_Config();
	PeriphCommonClock_Config();
	MX_GPIO_Init();
	lv_init();  //Initialise LVGL
	tft_init();  //Initialise TFT driver
	touchpad_init();  //Initialise touchpad driver
	COM();  //start UART
	test();
	while(1) {
		RX();  //Receive data from UART
		lv_task_handler();  
	}
}

GUI code:

#include <stdio.h>
#include <string.h>
#include "GUI.h"  
#include "../lvgl/lvgl.h" //Include lvgl library

extern char Val[50];
void test(void)
{
	 lv_obj_t * test = lv_obj_create(lv_scr_act());
	 lv_obj_set_size(test,800,220);  //Set size
	 lv_obj_t * label= lv_label_create(test);
	 lv_obj_set_pos(label, 50, 70);
	 lv_label_set_text(label, Val);
}

When the variable “Val” is updated you need to call:

lv_label_set_text(label, Val);

Once the value is set in the label the variable isnt used again. IE the variables can be created and used within a function like this:

	char buffer[64];
	snprintf(buffer, sizeof buffer, "%0.2f°c", (double)_temp);

    lv_table_set_cell_value(sensorTable, arraypos, 1, buffer);
1 Like

you need make lv_obj_t * label as global variable and do lv_label_set_text(label, Val); every time on val changed,

lv_obj_t * label

void test(void)
{
	 lv_obj_t * test = lv_obj_create(lv_scr_act());
	 lv_obj_set_size(test,800,220);  //Set size
	 label= lv_label_create(test);
	 lv_obj_set_pos(label, 50, 70);
}

void RX()
{
	...
	lv_label_set_text(label, Val);
	...
}
1 Like

As others have mentioned, with lv_label_set_text, the label keeps its own copy of the text, so you would need to call that function each time you update Val.

Alternatively, you can use lv_label_set_text_static(label, Val), which expects you to maintain the text buffer yourself (as you’re doing), and then you can just call lv_label_set_text_static(label, NULL) to instruct the label to refresh its text. This avoids the label needing to reallocate its own buffer each time.

1 Like

I see. Thank you very much for your help. How about if I want to refresh the entire screen or tab? For example, if I want to refresh tab(lv_obj_t * parent), how what would I input as the parent?

I see. Thank you very much for your help. How about if I want to refresh the entire screen or tab? For example, if I want to refresh tab(lv_obj_t * parent), how what would I input as the parent?

I see. Thank you very much for your help!

What do you mean by refresh?

If you are referring to changing the displayed value, you would need to update the individual widgets’ values (e.g. if you had 3 labels, you’d need to call lv_label_set_text on each).

If you are referring to the widget being redrawn on the screen, LVGL takes care of that for you.

I realised I wasn’t very clear with my question. Essentially, I wanted to update the values of the texts in a particular tab. But I had problems calling the function of tab(lv_obj_t * parent) as it requires an lv_obj_t object called parent which is not declared in the UART file as parent isn’t an extern variable. I managed to solve this by declaring the parent as an extern so I could refresh/update the tab and everything in the tab whenever a value needs to be updated.

Thank you for your help though!