Lilygo T-Watch 2021 Arduino code will not compile

What do you want to achieve?

Compile without errors an example Arduino sketch (lvgl_btn.ino) for the Lilygo T-Watch 2021 and upload it on the board, in order to use it as base code to use the UI I created with Squareline Studio.

What have you tried so far?

I have followed multiple times the instruction to setup the file structure. Loaded all the T-Watch libraries from the Lilygo GitHub page ( Xinyuan-LilyGO/T-Watch-2021 (github.com), I created the lv_conf.h file from the lv_conf_template.h, and pasted it next to the lvgl folder, I have configured the TWatch_config.h file. I am still getting a lot of errors (see below). It’s unexpected because this is an example code so it should work properly without much tweaking… Other non lvgl example codes from the same library worked fine.

ONE THING I DONT UNDERSTAND: the code says:
// This project requires LVGL, please uncomment it
but it doesn’t clarify WHAT and WHERE I am supposed to uncomment. I swept all the .c and .h files i could think of and there are is no LVGL code commented out.

I’ve opened an issue on Lilygo GitHub but no answer so far.

As an alternative, it would also help if someone could provide me with another simple code that I could use as basis to upload on the TWatch to start loading my UI files.

Screenshot or video

THIS IS THE CODE

#include <Arduino.h>
#include <TWatch_hal.h>

//“TWatch_config.h” needs to be configured in the library for the first time
// This project requires LVGL, please uncomment it

lv_obj_t *count_label;
uint32_t count = 0;
TWatchClass *twatch = nullptr;

static void event_handler(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);

if (code == LV_EVENT_CLICKED) {
lv_label_set_text_fmt(count_label, “Count:%d”, count++);
} else if (code == LV_EVENT_VALUE_CHANGED) {
LV_LOG_USER(“Toggled”);
}
}

void setup() {
Serial.begin(115200);
twatch = TWatchClass::getWatch();

Serial.println(“lvgl btn Demo (LVGL)”);
twatch->backlight_set_value(100);

twatch->hal_auto_update(true, 0);

lv_obj_t *label;
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);

label = lv_label_create(btn1);
lv_label_set_text(label, “Button”);
lv_obj_center(label);

count_label = lv_label_create(lv_scr_act());
lv_label_set_text(count_label, “Count:0”);
lv_obj_center(count_label);

lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT);

label = lv_label_create(btn2);
lv_label_set_text(label, “Toggle”);
lv_obj_center(label);
}

void loop() {}

THESE ARE THE ERROR MESSAGES

C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:7:1: error: ‘lv_obj_t’ does not name a type; did you mean ‘rmt_obj_t’?
lv_obj_t *count_label;
^~~~~~~~
rmt_obj_t
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: error: variable or field ‘event_handler’ declared void
static void event_handler(lv_event_t *e) {
^~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: error: ‘lv_event_t’ was not declared in this scope
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: note: suggested alternative: ‘spi_event_t’
static void event_handler(lv_event_t *e) {
^~~~~~~~~~
spi_event_t
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:39: error: ‘e’ was not declared in this scope
static void event_handler(lv_event_t *e) {
^
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: error: variable or field ‘event_handler’ declared void
static void event_handler(lv_event_t *e) {
^~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: error: ‘lv_event_t’ was not declared in this scope
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:27: note: suggested alternative: ‘spi_event_t’
static void event_handler(lv_event_t *e) {
^~~~~~~~~~
spi_event_t
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:11:39: error: ‘e’ was not declared in this scope
static void event_handler(lv_event_t *e) {
^
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino: In function ‘void setup()’:
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:30:3: error: ‘lv_obj_t’ was not declared in this scope
lv_obj_t *label;
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:30:3: note: suggested alternative: ‘rmt_obj_t’
lv_obj_t *label;
^~~~~~~~
rmt_obj_t
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:30:13: error: ‘label’ was not declared in this scope
lv_obj_t *label;
^~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:30:13: note: suggested alternative: ‘labs’
lv_obj_t *label;
^~~~~
labs
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:31:13: error: ‘btn1’ was not declared in this scope
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
^~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:31:34: error: ‘lv_scr_act’ was not declared in this scope
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
^~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:31:20: error: ‘lv_btn_create’ was not declared in this scope
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
^~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:31:20: note: suggested alternative: ‘timer_create’
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
^~~~~~~~~~~~~
timer_create
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:32:29: error: ‘event_handler’ was not declared in this scope
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
^~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:32:29: note: suggested alternative: ‘xt_handler’
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
^~~~~~~~~~~~~
xt_handler
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:32:44: error: ‘LV_EVENT_ALL’ was not declared in this scope
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
^~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:32:3: error: ‘lv_obj_add_event_cb’ was not declared in this scope
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
^~~~~~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:33:22: error: ‘LV_ALIGN_CENTER’ was not declared in this scope
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:33:3: error: ‘lv_obj_align’ was not declared in this scope
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
^~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:35:11: error: ‘lv_label_create’ was not declared in this scope
label = lv_label_create(btn1);
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:35:11: note: suggested alternative: ‘timer_create’
label = lv_label_create(btn1);
^~~~~~~~~~~~~~~
timer_create
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:36:3: error: ‘lv_label_set_text’ was not declared in this scope
lv_label_set_text(label, “Button”);
^~~~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:37:3: error: ‘lv_obj_center’ was not declared in this scope
lv_obj_center(label);
^~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:39:3: error: ‘count_label’ was not declared in this scope
count_label = lv_label_create(lv_scr_act());
^~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:43:13: error: ‘btn2’ was not declared in this scope
lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
^~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:43:13: note: suggested alternative: ‘atan2’
lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
^~~~
atan2
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:46:25: error: ‘LV_OBJ_FLAG_CHECKABLE’ was not declared in this scope
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
^~~~~~~~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:46:3: error: ‘lv_obj_add_flag’ was not declared in this scope
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:47:27: error: ‘LV_SIZE_CONTENT’ was not declared in this scope
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn\lvgl_btn.ino:47:3: error: ‘lv_obj_set_height’ was not declared in this scope
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
^~~~~~~~~~~~~~~~~

exit status 1

Compilation error: ‘lv_obj_t’ does not name a type; did you mean ‘rmt_obj_t’?

Others

  • SquareLine Studio version: 1.3.0
  • Operating system: Win 11
  • Target hardware: Lilygo T-Watch 2021

paste isnt only one think. read first ten lines and do it in lv_conf.h

1 Like

@Marian_M, thanks a lot for your answer!

I have looked again at the first ten lines in the lv_conf.h fileto see what I might have missed and the only step I didn’t do is this:

  • define LV_CONF_INCLUDE_SIMPLE
  • add the path as include path
    But I don’t think I needed to do it, because I have pasted the file next to the lvgl folder, and that is needed ONLY if I paste it somewhere else, as described in the lvgl instructions as follows:

“Alternatively, lv_conf.h can be copied to another place but then you should add the LV_CONF_INCLUDE_SIMPLE define to your compiler options (e.g. -DLV_CONF_INCLUDE_SIMPLE for GCC compiler) and set the include path manually (e.g. -I../include/gui ). In this case LVGL will attempt to include lv_conf.h simply with #include "lv_conf.h" .”

Other than that, I did switch the enable from 0 to 1 and I don’t think I need to do anything about the “clang-format off” comment.

Am I missing sometrhing?

If realy you set this , then you place h file to bad folder or other issue…

1 Like

@Marian_M this is my folder tree:


Do you see anything wrong with it?

Go to TWatch_2021_Library folder, find TWatch_config.h file. Line 32, modify #define CONFIG_TWATCH_APP_LVGL 0.

@LeoChris2023 It works now! Thank you so much! Was this explained anywhere and I just missed?
I have tried to compile the other LVGL example code (lvgl_example.ino) and that one compiles too (it produced errors before as well) but at the end of the upload the board gets stuck on “hard resetting via RTS pin”… Any idea what it might be?

OK. After being able to compile the lvgl_btn.ino code (thanks @LeoChris2023 and all for the help!) I tried to upload my ui: I pasted the Squareline Studio UI files (used the export UI files function in SLS) in the lvgl_btn.ino folder, and called #include “ui.h” and ui_init() in my code, commented out unneeded parts and tried to compile, but I get another bunch of errors and the final output is: unknown type name ‘lv_obj_t’.
This is my folder

See partial error log with main errors below. I think I am still doing something wrong with the files position or missing some include directive… Have fixed a couple of syntax errors (include with " not < and missing ; ) but nothing else comes to mind…

In file included from C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.c:6:
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:18:27: error: unknown type name ‘lv_obj_t’
void _ui_bar_set_property(lv_obj_t * target, int id, int val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:24:29: error: unknown type name ‘lv_obj_t’
void _ui_basic_set_property(lv_obj_t * target, int id, int val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:27:32: error: unknown type name ‘lv_obj_t’
void _ui_dropdown_set_property(lv_obj_t * target, int id, int val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:30:29: error: unknown type name ‘lv_obj_t’
void _ui_image_set_property(lv_obj_t * target, int id, uint8_t * val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:30:56: error: unknown type name ‘uint8_t’
void _ui_image_set_property(lv_obj_t * target, int id, uint8_t * val);
^~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:33:29: error: unknown type name ‘lv_obj_t’
void _ui_label_set_property(lv_obj_t * target, int id, const char * val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:37:30: error: unknown type name ‘lv_obj_t’
void _ui_roller_set_property(lv_obj_t * target, int id, int val);
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui_helpers.h:41:30: error: unknown type name ‘lv_obj_t’
void _ui_slider_set_property(lv_obj_t * target, int id, int val);
^~~~~~~~
**** CUT SOME TEXT HERE, IT WENT ON LISTING ALL MY OBJECTS *****

                                             ^~~~~~~~

In file included from C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:6:
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.h:29:8: error: unknown type name ‘lv_obj_t’
extern lv_obj_t * ui_Screen1;
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.h:30:8: error: unknown type name ‘lv_obj_t’
extern lv_obj_t * ui_Arc2;
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.h:31:8: error: unknown type name ‘lv_obj_t’
extern lv_obj_t * ui_Arc1;
^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.h:32:8: error: unknown type name ‘lv_obj_t’
extern lv_obj_t * ui_Arc3;
^~~~~~~~

**** CUT SOME TEXT HERE, AGAIN IT WENT ON LISTING ALL MY OBJECTS *****

^~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:79:6: error: #error “LV_COLOR_DEPTH should be 16bit to match SquareLine Studio’s settings”
#error “LV_COLOR_DEPTH should be 16bit to match SquareLine Studio’s settings”
^~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c: In function ‘ui_init’:
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:93:5: error: unknown type name ‘lv_disp_t’
lv_disp_t * dispp = lv_disp_get_default();
^~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:94:5: error: unknown type name ‘lv_theme_t’
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
^~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:94:71: error: ‘LV_PALETTE_BLUE’ undeclared (first use in this function)
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:94:71: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:94:105: error: ‘LV_PALETTE_RED’ undeclared (first use in this function)
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
^~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:95:48: error: ‘true’ undeclared (first use in this function)
true, LV_FONT_DEFAULT);
^~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:95:54: error: ‘LV_FONT_DEFAULT’ undeclared (first use in this function)
true, LV_FONT_DEFAULT);
^~~~~~~~~~~~~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:98:44: error: ‘NULL’ undeclared (first use in this function)
ui____initial_actions0 = lv_obj_create(NULL);
^~~~
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:98:44: note: ‘NULL’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’?
C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:8:1:
+#include <stddef.h>

C:\Users\angel\Documents\Arduino\libraries\TWatch_2021_Library\examples\LVGL\lvgl_btn_copy\ui.c:98:44:
ui____initial_actions0 = lv_obj_create(NULL);
^~~~

exit status 1

Compilation error: unknown type name ‘lv_obj_t’

I am updating this topic after a while because I thougt I had found a workaround solution but I am probably back at square one.
As per my previous post, I wasn’t able to compile when introducing the SLS UI in the Lilygo provided TWatch 2021 lvgl example file.

After that I was able to load my SLS GUI using the LVGLHelloWorld example taken from the Arduino GFX library, and installing the Kissvegabor LVGL library from the Arduino Library Manager. I did all following Moononournation’s tutorial I found here Design a Fancy GUI for Your Project : 19 Steps (with Pictures) - Instructables

However when I tried to include the TWatch_hal.h file in that example in order to use the vibration motor, I got a bunch of conflicts.

So I figured out I can use the Lilygo LVGL examples and library, where the TWatch_hal.h is already included and I can use all the board HW.

But that puts me back at square one because I am getting all the error messages reported on my previous post, where apparently nobody was able to give me any tips.

So I am trying to ask again… Hoping for better luck
Thanks in advance
Angelo