Code works in Arduino IDE, too many errors in PlatformIO

I have a simple “Hello World” code, which displays some text in the Screen.
This code works on the Arduino IDE, but I get 15 errors from the VSCode compiler.
I’ve already put the libraries in /lib/, took it out. Change Platformio.ini, and several other ways, but can’t get it to compile.

#include <lvgl.h>
#include <TFT_eSPI.h>
#include "lv_conf.h"

/*Change to your screen resolution*/
static const uint16_t screenWidth  = 240;
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_drv, 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_drv );
}


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( 0 ); /* Landscape orientation, flipped */

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

    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 );

  
    /* Create simple label */
    lv_obj_t *label = lv_label_create( lv_scr_act() );
    lv_label_set_text( label, "Hello World");
    lv_label_set_recolor(label,true);
    lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );
 
    //lv_demo_widgets();               
    // lv_demo_benchmark();          
    // lv_demo_keypad_encoder();     
    // lv_demo_music();              
    // lv_demo_printer();
    // lv_demo_stress();
    
    Serial.println( "Setup done" );
}

void loop()
{
    lv_timer_handler(); /* let the GUI do its work */
    delay( 5 );
}

Seems the compiler can’t find any of the libraries, but I can click with the right mouse button in any of the Includes, and navigate to the definition.
I’ve already tried even hardcoding the libraries (removing it from platformio.ini file, adding the libraries to /lib/ and changing the C/C++ configuration to add my entire workspace to the library path).

Nothing works :sob:

You may be mismatching versions. What does the library.properties say in your C:\Users\<user>\Documents\Arduino\libraries\lvlg? (or, the verbose Arduino IDE build output).

1 Like

Thank you for your answer! The versions are:

lvgl@8.3.8
TFT_eSPI@2.5.34

I’ve deleted the newest libraries, and I’m using the same versions as the ArduinoIDE now, the compile errors are gone, but in Terminal I get this now:

In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_obj.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_event.c:9:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../hal/../draw/lv_draw.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../hal/lv_hal_disp.h:21,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../hal/lv_hal.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_disp.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_disp.c:9:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../hal/../draw/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_group.h:17,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_group.c:11:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_obj.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_indev.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_indev.c:9:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_obj.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_indev.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_indev_scroll.c:9:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_obj.c.o
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_group.c.o] Error 1
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_disp.c.o] Error 1
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_event.c.o] Error 1
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_indev_scroll.c.o] Error 1
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_indev.c.o] Error 1
In file included from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_obj.h:16,
                 from .pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/lv_obj.c:9:
.pio/libdeps/esp32-s3-devkitm-1/lvgl/src/core/../lv_conf_internal.h:41:18: fatal error: ../../lv_conf.h: No such file or directory
         #include "../../lv_conf.h"                /*Else assume lv_conf.h is next to the lvgl folder*/
                  ^~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio/build/esp32-s3-devkitm-1/lib4b7/lvgl/core/lv_obj.c.o] Error 1

Well, it does need a macro set so it can grab the lv_conf.h file. Did you original project have one?

Post your platformoi.ini. For example, you could do

builld_flags = 
  ; add folder where lv_conf.h is to the global include directories (assume "src/")
  -Isrc
  ; Tell lvgl to just include lvgl.h, it'll be there
  -DLV_CONF_INCLUDE_SIMPLE

I’ve done something else.
I’ve copied the lv_conf.h to the LVGL folder. That seems to solve the compiling problem, but now the only thing left, is that the board is display, is not showing anything :frowning:

Did you setup the right TFT_eSPI configuration options in your platformio.ini so that the same display controller type etc. is used? It won’t be able to just autodetect your screen type and pins etc. See their documentation.

https://github.com/Bodmer/TFT_eSPI/blob/master/docs/PlatformIO/Configuring%20options.txt

https://github.com/Bodmer/TFT_eSPI/tree/master/User_Setups

https://github.com/Bodmer/TFT_eSPI/blob/master/User_Setup_Select.h#L29-L158

Everything in the .pio directory is temporary content and will be deleted when you do a deep project clean. Don’t do that, put the config in the e.g. src folder and do as I’ve shown above.

Thank you so much for your Help! I finally feel like I’m getting somewhere.
The initial project came with two TFT_eSPI_Setups:

Setup207_GC9A01.h
Setup208_ST7789.h

I’m pretty sure GC9A01 is the right one.

I’ve added them to /lib/ folder, and included them to main.cpp:

#include "Setup207_GC9A01.h"
//#include "Setup208_ST7789.h"

I’ve tried both of them (commenting as well), but nothing is shown still. So I took them off, and edited both the TFT_eSPI User_Setups in my /.pio/libdeps/esp32-s3-devkitm-1/TFT_eSPI Folder to:
#define GC9A01_DRIVER
#include <User_Setups/Setup46_GC9A01_ESP32.h>

Based on the original TFT_eSPI configurations though, I don’t think either of them are the right ones:

This is the TFT_Setup file with the correct Pins:

#define USER_SETUP_ID 207
#define USER_SETUP_INFO "ESP32-S3-Touch-LCD-1.28"

#ifdef ILI9341_DRIVER
#undef ILI9341_DRIVER
#endif

#define GC9A01_DRIVER

// For ESP32 Dev board (only tested with GC9A01 display)
// The hardware SPI can be mapped to any pins

#define TFT_WIDTH  240
#define TFT_HEIGHT 240

#define TFT_MISO -1
#define TFT_MOSI 11
#define TFT_SCLK 10
#define TFT_CS   9  // Chip select control pin
#define TFT_DC   8  // Data Command control pin
#define TFT_RST  12
#define TFT_BL	40
#define TFT_BACKLIGHT_ON HIGH

#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

#define SMOOTH_FONT

#define SPI_FREQUENCY  80000000

This is my old platformio.ini file:

[env:esp32-s3-devkitm-1]
platform = espressif32
board = esp32-s3-devkitm-1
framework = arduino
monitor_speed = 115200
lib_deps = 
	lvgl/lvgl@8.3.8
	bodmer/TFT_eSPI@2.5.34

build_flags = 
  ; add folder where lv_conf.h is to the global include directories (assume "src/")
  -Isrc
  ; Tell lvgl to just include lvgl.h, it'll be there
  -DLV_CONF_INCLUDE_SIMPLE

I’ve then tried changing the platformio.ini file to reflect the Pins:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32-s3-devkitm-1]
platform = espressif32
board = esp32-s3-devkitm-1
framework = arduino
monitor_speed = 115200
lib_deps = 
	lvgl/lvgl@8.3.8
	bodmer/TFT_eSPI@2.5.34

build_flags = 
  ; add folder where lv_conf.h is to the global include directories (assume "src/")
  -Isrc
  ; Tell lvgl to just include lvgl.h, it'll be there
  -DLV_CONF_INCLUDE_SIMPLE
  -ILI9341_DRIVER=1
  -DTFT_WIDTH=240
  -DTFT_HEIGHT=280
  -DTFT_MISO=-1
  -DTFT_MOSI=11
  -DTFT_SCLK=10
  -DTFT_CS=9
  -DTFT_DC=8
  -DTFT_RST=12
  -DTFT_BL=40
  ;-DTOUCH_CS=22
  -DLOAD_GLCD=1
  -DLOAD_FONT2=1
  -DLOAD_FONT4=1
  -DLOAD_FONT6=1
  -DLOAD_FONT7=1
  -DLOAD_FONT8=1
  -DLOAD_GFXFF=1
  -DSMOOTH_FONT=1
  -DSPI_FREQUENCY=80000000

Notice here I’m using ILI9341_DRIVER=1
Using GC9A01_DRIVER=1 returns an error (unrecognized command line option ‘-GC9A01_DRIVER=1’)

Mh no that flag is wrong, -I is for “add an include directory”, -D is for “add a define”.

All the define flags should be in the form

   -D<name of macro>=<value of macro>
   ; or 
   -D <name of macro>=<value of macro>

e.g.

   -DILI9341_DRIVER=1
   ; or
   -D ILI9341_DRIVER=1

means the same thing. But not -ILI9341_DRIVER=1.

See documentation.

1 Like

Plus, if you give all display options in the build_flags, TFT_eSPI requires you to have the

macro activated, otherwise you will again get some defaults.

-D GC9A01_DRIVER=1 is recognized.

But what made it work was actually changing User_Setup_Select to include:
#include <User_Setups/Setup207_GC9A01.h>

Though both the Setup207_GC9A01.h file, and this line are not in the original library. So as long as I do a Full Clean, it stops working (changes are deleted)
Is there anyway I can make these changes permanent?

Don’t try and make the file changes permant. Work on getting the config options in the platformio.ini right. They will configure the unmodified library files just fine.

If you want to replicate Setup46_GC9A01_ESP32.h, you should have

build_flags = 
  ; add folder where lv_conf.h is to the global include directories (assume "src/")
  -Isrc
  ; Tell lvgl to just include lvgl.h, it'll be there
  -DLV_CONF_INCLUDE_SIMPLE
  ; TFT_eSPI configuration
  -DUSER_SETUP_LOADED=1
  -D GC9A01_DRIVER
  -D TFT_WIDTH=240
  -D TFT_HEIGHT=240
  -D TFT_MISO=-1
  -D TFT_MOSI=11
  -D TFT_SCLK=10
  -D TFT_CS=9
  -D TFT_DC=8
  -D TFT_RST=12
  -D TFT_BL=40
  -D TFT_BACKLIGHT_ON=HIGH
  -D LOAD_GLCD
  -D LOAD_FONT2
  -D LOAD_FONT4
  -D LOAD_FONT6
  -D LOAD_FONT7
  -D LOAD_FONT8
  -D LOAD_GFXFF
  -D SMOOTH_FONT
  -D SPI_FREQUENCY=80000000

You might also need to delete your .pio folder to get a clean download of the libraries again. (After backing them up for reference :wink: )

I’m questioning those pins a bit because the source here has different pins but the same “ESP32-S3-Round-SPI-TFT-with-Touch-1.28” name.

https://github.com/Makerfabs/ESP32-S3-Round-SPI-TFT-with-Touch-1.28/blob/main/example/tft_espi_demo/User_Setup.h#L217-L222

If I add -DUSER_SETUP_LOADED=1 , it stops working.

The only way it works is:

  • adding the file Setup207_GC9A01.h to User_Setups/
  • changing User_Setup_Select.h to include it
  • changing User_Setup.h to define GC9A01_DRIVER

I’m using the custom Setup with these pins, cause the board with Touch has different pins im comparison with the board without touch :slight_smile:

Since with a Full Clean, the changes on User_Setup_Select.h and User_Setup.h are reverted, how to keep them like ‘hard-coded’?

It should 100% work with -DUSER_SETUP_LOADED=1 defined and all following -D options being exactly those from the Setup207_GC9A01.h file… That’s how I read User_Setup_Select.h.

Well if you want to at least save the changes, once you’re done modifying .pio/libdeps/<env>/TFT_eSPI, you can move that folder to lib/ folder of the project and then delete the TFT_eSPI line from the lib_deps expression. The library in lib/ should be automatically picked up.

1 Like