Fatal error: TFT_eSPI.h: No such file or directory

Simple project. TFT_eSPI + LVGL.
I get the error:

Compiling .pio\build\esp32\lib969\lvgl\drivers\evdev\lv_evdev.c.o
Compiling .pio\build\esp32\lib969\lvgl\drivers\glfw\lv_glfw_window.c.o
.pio/libdeps/esp32/lvgl/src/drivers/display/tft_espi/lv_tft_espi.cpp:11:10: fatal error: TFT_eSPI.h: No such file or directory

******************************************************************
* Looking for TFT_eSPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:TFT_eSPI.h"
* Web  > https://registry.platformio.org/search?q=header:TFT_eSPI.h
*
******************************************************************

 #include <TFT_eSPI.h>
          ^~~~~~~~~~~~
compilation terminated.
Compiling .pio\build\esp32\lib969\lvgl\drivers\glfw\lv_opengles_debug.c.o
Compiling .pio\build\esp32\lib969\lvgl\drivers\glfw\lv_opengles_driver.c.o
*** [.pio\build\esp32\lib969\lvgl\drivers\display\tft_espi\lv_tft_espi.cpp.o] Error 1
=========================================================== [FAILED] Took 230.78 seconds ===========================================================

 *  The terminal process "C:\Users\DanilinSergey\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

platformio.ini

build_flags = 
	-DCORE_DEBUG_LEVEL=5
	-Os
lib_ldf_mode = deep+
lib_deps = 
	bodmer/TFT_eSPI@^2.5.43
	lvgl/lvgl@^9.2.2
	SPI
	SPIFFS
	FS

lv_tft_espi.cpp

/*********************
 *      INCLUDES
 *********************/
#include "lv_tft_espi.h"
#if LV_USE_TFT_ESPI
#include <TFT_eSPI.h>

main.cpp

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

The library is connected. But the error does not disappear.

Change your platformio.ini to

build_flags = 
  -DCORE_DEBUG_LEVEL=5
  -Os
lib_deps = 
  bodmer/TFT_eSPI@^2.5.43
  lvgl/lvgl@^9.2.2

For configuring the TFT_eSPI library, please read TFT_eSPI/docs/PlatformIO/Configuring options.txt at master · Bodmer/TFT_eSPI · GitHub

You might have to switch the includes:

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

Thank you! The problem has been solved.

1 Like