Lib Lilygo T-Display S3 Touch

I’m testing a new Lilygo T-Display S3 Touch. Unfortunately, the library does not load properly.

Can anyone help me?

Processing lilygo-t-display-s3 (platform: espressif32; board: lilygo-t-display-s3; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lilygo-t-display-s3.html
PLATFORM: Espressif 32 (6.5.0) > LilyGo T-Display-S3
HARDWARE: ESP32S3 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit MPR121 @ 1.0.2+sha.f05257c
|-- Wire @ 2.0.0
Building in release mode
Compiling .pio\build\lilygo-t-display-s3\src\main.cpp.o
Building .pio\build\lilygo-t-display-s3\bootloader.bin
Generating partitions .pio\build\lilygo-t-display-s3\partitions.bin
Compiling .pio\build\lilygo-t-display-s3\lib131\Wire\Wire.cpp.o
esptool.py v4.5.1
Creating esp32s3 image...
Merged 1 ELF section
Successfully created esp32s3 image.
Compiling .pio\build\lilygo-t-display-s3\lib62f\Adafruit MPR121\Adafruit_MPR121.cpp.o
Compiling .pio\build\lilygo-t-display-s3\FrameworkArduino\Esp.cpp.o
src/main.cpp:27: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" /* Please use the TFT library provided in the library. */
          ^~~~~~~~~~~~
compilation terminated.
*** [.pio\build\lilygo-t-display-s3\src\main.cpp.o] Error 1
.pio/libdeps/lilygo-t-display-s3/Adafruit MPR121/Adafruit_MPR121.cpp: In member function 'boolean Adafruit_MPR121::begin(uint8_t, TwoWire*)':
.pio/libdeps/lilygo-t-display-s3/Adafruit MPR121/Adafruit_MPR121.cpp:69:25: warning: 'void Adafruit_MPR121::setThreshholds(uint8_t, uint8_t)' is deprecated [-Wdeprecated-declarations]
     setThreshholds(12, 6);
                         ^
In file included from .pio/libdeps/lilygo-t-display-s3/Adafruit MPR121/Adafruit_MPR121.cpp:29:
.pio/libdeps/lilygo-t-display-s3/Adafruit MPR121/Adafruit_MPR121.h:96:8: note: declared here
   void setThreshholds(uint8_t touch, uint8_t release)
        ^~~~~~~~~~~~~~
=========================================================== [FAILED] Took 15.08 seconds ===========================================================

platform.ini

[env:lilygo-t-display-s3]
platform = espressif32
board = lilygo-t-display-s3
framework = arduino

; change microcontroller
board_build.mcu = esp32s3

; change MCU frequency
board_build.f_cpu = 240000000L

lib_deps =
    https://github.com/Xinyuan-LilyGO/T-Display-S3.git

Test-Code:

#include "Arduino.h"
// 170 x 320
#define TOUCH_MODULES_CST_SELF
#include "Arduino.h"
#include "TFT_eSPI.h" /* Please use the TFT library provided in the library. */
#include "TouchLib.h"
#include "Wire.h"
#include "pin_config.h"

TouchLib touch(Wire, PIN_IIC_SDA, PIN_IIC_SCL, CTS820_SLAVE_ADDRESS, PIN_TOUCH_RES);

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);

int deb=0;
bool switch1=true;
bool switch2=false;

void setup() {
  pinMode(PIN_POWER_ON, OUTPUT);
  digitalWrite(PIN_POWER_ON, HIGH);
  pinMode(PIN_TOUCH_RES, OUTPUT);
  digitalWrite(PIN_TOUCH_RES, LOW);
  delay(500);
  digitalWrite(PIN_TOUCH_RES, HIGH);
  tft.begin();
  sprite.createSprite(170,320);
  sprite.setTextColor(TFT_WHITE,TFT_BLACK);
  Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL);
  draw(-1,-1);
}


void draw(int x, int y)
{  
  sprite.fillSprite(TFT_BLACK);
 
      if(y<160)
      switch1=!switch1;
      else
      switch2=!switch2;

    sprite.drawString("SWITCH1= "+String(switch1),20,30,4);
    sprite.drawRect(18,58,134,54,TFT_GREEN);
    sprite.fillRect(20+(switch1*80),60,50,50,TFT_GREEN);
    
    sprite.drawString("SWITCH2= "+String(switch2),20,190,4);
    sprite.drawRect(18,218,134,54,TFT_YELLOW);
    sprite.fillRect(20+(switch2*80),220,50,50,TFT_YELLOW);

  sprite.pushSprite(0,0); 
}

void loop() {
  
  if (touch.read()) {
    if(deb==0){
    deb=1;
      TP_Point t = touch.getPoint(0);
      if(t.x<170)
      draw(t.x,t.y);
    } }else {
    deb=0;}
}

That’s not a library at all but a project with examples.
How it can be used with PlatformIO is described in section 3 of the repository readme: GitHub - Xinyuan-LilyGO/T-Display-S3

Ok, thanks! How do I get the right libraries loaded?

The required libraries are all already located in the “lib” folder.
Simply follow the steps in section 3.

Use steps 6 and following to select the desired example.

Unfortunately I didn’t understand the instructions. But it works now: I copied all lib files to the project folder one by one. Thank you!

Next problem: If I also load the library Mhz19.h via the platformio.ini, the TFT_eSPI is no longer recognized. I’m at a loss. Can someone give me a hint?

It looks like you’re not alone.
See Library incompatible with I2C LCD? · Issue #42 · WifWaf/MH-Z19 · GitHub

However, this is a bug of this library and not PlatformIO.
Please open an issue to the library repository: Issues · WifWaf/MH-Z19 · GitHub

The problem is different for me: I have a T-display without touch with TFT_eSPI and MHZ19 that works well.

Now I have the new T-Display S3 with touch. I couldn’t load the TFT_ESPI via .ini. I therefore loaded all the necessary files into my project folder. Since then the display and touch have worked well. In the .ini the lib_deps is empty.

Now I wanted to load the MHZ19 via the .ini. Since then, when compiling it shows that it can no longer find the TFT_ESPI, even though I haven’t changed anything about it.

If I load the MHZ19 directly into the project folder, the TFT_ESPI works but the MHZ19 does not.

I cant imagine why this would happen.
Please, kindly share your platformio.ini and the smallest main.cpp to reproduce the error.

This works: Files from TFT_eSPI and TouchLib in the project folder.

#define TOUCH_MODULES_CST_SELF
#include "Arduino.h"
#include "TFT_eSPI.h" /* Please use the TFT library provided in the library. */
#include "TouchLib.h"
#include "Wire.h"
#include "pin_config.h"

TouchLib touch(Wire, PIN_IIC_SDA, PIN_IIC_SCL, CTS820_SLAVE_ADDRESS, PIN_TOUCH_RES);

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);

int deb=0;
bool switch1=true;
bool switch2=false;


void draw(int x, int y);



void setup() {
  pinMode(PIN_POWER_ON, OUTPUT);
  digitalWrite(PIN_POWER_ON, HIGH);
  pinMode(PIN_TOUCH_RES, OUTPUT);
  digitalWrite(PIN_TOUCH_RES, LOW);
  delay(500);
  digitalWrite(PIN_TOUCH_RES, HIGH);
  tft.begin();
  sprite.createSprite(170,320);
  sprite.setTextColor(TFT_WHITE,TFT_BLACK);
  Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL);
  draw(-1,-1);
}







void draw(int x, int y)
{  
  sprite.fillSprite(TFT_BLACK);
 
      if(y<160)
      switch1=!switch1;
      else
      switch2=!switch2;

    sprite.drawString("SWITCH1= "+String(switch1),20,30,4);
    sprite.drawRect(18,58,134,54,TFT_GREEN);
    sprite.fillRect(20+(switch1*80),60,50,50,TFT_GREEN);
    
    sprite.drawString("SWITCH2= "+String(switch2),20,190,4);
    sprite.drawRect(18,218,134,54,TFT_YELLOW);
    sprite.fillRect(20+(switch2*80),220,50,50,TFT_YELLOW);

  sprite.pushSprite(0,0); 
}






void loop() {
  
  if (touch.read()) {
    if(deb==0){
    deb=1;
      TP_Point t = touch.getPoint(0);
      if(t.x<170)
      draw(t.x,t.y);
    } }else {
    deb=0;}
}

.ini

[env:lilygo-t-display-s3]
platform = espressif32
board = lilygo-t-display-s3
framework = arduino

; change microcontroller
board_build.mcu = esp32s3

; change MCU frequency
board_build.f_cpu = 240000000L

lib_deps =
    

That doesn’t work: (Files from TFT_eSPI and TouchLib in the project folder.)

// TTGO T-Display S3 Touch

#define TOUCH_MODULES_CST_SELF
#include "Arduino.h"
#include "TFT_eSPI.h" /* Please use the TFT library provided in the library. */
#include "TouchLib.h"
#include "Wire.h"
#include "pin_config.h"


#include "MHZ19.h"

HardwareSerial mySerial(2); 
MHZ19 myMHZ19;


TouchLib touch(Wire, PIN_IIC_SDA, PIN_IIC_SCL, CTS820_SLAVE_ADDRESS, PIN_TOUCH_RES);

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite sprite = TFT_eSprite(&tft);

int deb=0;
bool switch1=true;
bool switch2=false;


void draw(int x, int y);



void setup() {
  pinMode(PIN_POWER_ON, OUTPUT);
  digitalWrite(PIN_POWER_ON, HIGH);
  pinMode(PIN_TOUCH_RES, OUTPUT);
  digitalWrite(PIN_TOUCH_RES, LOW);
  delay(500);
  digitalWrite(PIN_TOUCH_RES, HIGH);
  tft.begin();
  sprite.createSprite(170,320);
  sprite.setTextColor(TFT_WHITE,TFT_BLACK);
  Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL);
  draw(-1,-1);

  mySerial.begin(9600);                                // Uno example: Begin Stream with MHZ19 baudrate
  myMHZ19.begin(Serial1);                                 // *Imporant, Pass your Stream reference

}







void draw(int x, int y)
{  
  sprite.fillSprite(TFT_BLACK);
 
      if(y<160)
      switch1=!switch1;
      else
      switch2=!switch2;

    sprite.drawString("SWITCH1= "+String(switch1),20,30,4);
    sprite.drawRect(18,58,134,54,TFT_GREEN);
    sprite.fillRect(20+(switch1*80),60,50,50,TFT_GREEN);
    
    sprite.drawString("SWITCH2= "+String(switch2),20,190,4);
    sprite.drawRect(18,218,134,54,TFT_YELLOW);
    sprite.fillRect(20+(switch2*80),220,50,50,TFT_YELLOW);

  sprite.pushSprite(0,0); 
}






void loop() {
  
  if (touch.read()) {
    if(deb==0){
    deb=1;
      TP_Point t = touch.getPoint(0);
      if(t.x<170)
      draw(t.x,t.y);
    } }else {
    deb=0;}
}
[env:lilygo-t-display-s3]
platform = espressif32
board = lilygo-t-display-s3
framework = arduino

; change microcontroller
board_build.mcu = esp32s3

; change MCU frequency
board_build.f_cpu = 240000000L

lib_deps =
    wifwaf/MH-Z19 @ ^1.5.4
Processing lilygo-t-display-s3 (platform: espressif32; board: lilygo-t-display-s3; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------Removing unused dependencies...
Library Manager: Removing TFT_eSPI @ 2.5.43
Library Manager: TFT_eSPI@2.5.43 has been removed!
Library Manager: Removing MH-Z19 @ 1.5.4+sha.95fe425
Library Manager: MH-Z19@1.5.4+sha.95fe425 has been removed!
Library Manager: Installing wifwaf/MH-Z19 @ ^1.5.4
Unpacking  [####################################]  100%
Library Manager: MH-Z19@1.5.4 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lilygo-t-display-s3.html
PLATFORM: Espressif 32 (6.5.0) > LilyGo T-Display-S3
HARDWARE: ESP32S3 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20014.231204 (2.0.14) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- MH-Z19 @ 1.5.4
|-- Wire @ 2.0.0
Building in release mode
Compiling .pio\build\lilygo-t-display-s3\src\main.cpp.o
Building .pio\build\lilygo-t-display-s3\bootloader.bin
Generating partitions .pio\build\lilygo-t-display-s3\partitions.bin
Compiling .pio\build\lilygo-t-display-s3\lib037\MH-Z19\MHZ19.cpp.o
esptool.py v4.5.1
Creating esp32s3 image...
Merged 1 ELF section
Successfully created esp32s3 image.
Compiling .pio\build\lilygo-t-display-s3\lib131\Wire\Wire.cpp.o
Compiling .pio\build\lilygo-t-display-s3\FrameworkArduino\Esp.cpp.o
src/main.cpp:5: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" /* Please use the TFT library provided in the library. */
          ^~~~~~~~~~~~
compilation terminated.
*** [.pio\build\lilygo-t-display-s3\src\main.cpp.o] Error 1
=========================================================== [FAILED] Took 23.40 seconds ===========================================================

It works now: I don’t know exactly why, but I must have made a mistake copying the TFT-eSPI in the project folder. Thank you for your support!

I personally do not copy any libraries manually into my project directory (unless absolutely necessary).

I include the TFT_eSPI library via lib_deps and configure it via the build_flags.
This is also what Bodmer recommends for PlatformIO projects: “PlatformIO users can define these settings on a per project basis within a platformio.ini file, see Docs folder in library.”