Hello,
I am working with ESP32-S (AI Thinker NodeMCU 32) and a display LCD TFT 1.44-inch 128x128 - ST7735. My arduino IDE version 1.8.18 and esp32 package version 1.0.6
My project at first used Adafruit_ST7735 library and it's working well except flickering effect. So I changed to use TFT_eSPI for more efficient. It's working well too (examples and my projects are working well) with Setup47_ST7735.h
Then I read the instruction and realized that this library allows a setup file to be included by the sketch for Esp32 with tft_setup.h file (no need to modify user setup file in the library folder)
For ESP32 ONLY, the TFT configuration (user setup) can now be included inside an Arduino IDE sketch providing the instructions in the example Generic->Sketch_with_tft_setup are followed. See ReadMe tab in that sketch for the instructions. If the setup is not in the sketch then the library settings will be used. This means that "per project" configurations are possible without modifying the library setup files. Please note that ALL the other examples in the library will use the library settings unless they are adapted and the "tft_setup.h" header file included
I followed the instructions. Basically there are few steps:
- Copy platform.local.txt to esp32 packages (C:\Users\xxxxx\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\platform.local.txt)
- Close Arduino IDE and open it again (to make sure all changes applied)
- Create a file with filename exact the same as "tft_setup.h" in the sketch and put all the tft library setup information
Below is my tft_setup.h
// Config for two ST7735 128 x 128 displays for Animated_Eyes example
#define ST7735_DRIVER // Configure all registers
#define TFT_WIDTH 128
#define TFT_HEIGHT 128
#define ST7735_GREENTAB3
#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
// Generic ESP32 setup
#define TFT_MISO -1
#define TFT_MOSI 12
#define TFT_SCLK 33
#define TFT_CS 18 // Not defined here, chip select is managed by sketch
#define TFT_DC 22
#define TFT_RST 21 // Connect reset to ensure display initialises
#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_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#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 27000000
//#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
// #define SUPPORT_TRANSACTIONS
This setup file is exact the same as Setup47_ST7735.h which is working well before (i.e all pins configuration are correct). To make it clear and avoid conflicts, I disabled all #include header files in User_Setup_Select.h
But after compile and upload the sketch, my LCD goes WHITE screen only, no display at all. The main sketch is very simple
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI myGLCD = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
#define TFT_W 128
#define TFT_H 128
void setup()
{
randomSeed(analogRead(A0));
// Setup the LCD
myGLCD.init();
myGLCD.fillScreen(TFT_BLACK);
myGLCD.fillRect(0, 0, TFT_W - 1, 14, TFT_RED);
myGLCD.setTextColor(TFT_CYAN);
myGLCD.drawString("Sin", 5, 15, 2);
for (int i = 1; i < TFT_W - 2; i++)
{
myGLCD.drawPixel(i, TFT_H / 2 - 1 + (sin(((i * 2.26) * 3.14) / 180) * 48), TFT_CYAN);
}
}
void loop()
{}
Then I read the library source code TFT_eSPI.h and found this block of codes
#if !defined __has_include
#if !defined(DISABLE_ALL_LIBRARY_WARNINGS)
#warning Compiler does not support __has_include, so sketches cannot define the setup
#endif
#else
#if __has_include(<tft_setup.h>)
// Include the sketch setup file
#include <tft_setup.h>
#ifndef USER_SETUP_LOADED
// Prevent loading further setups
#define USER_SETUP_LOADED
#endif
#endif
#endif
Hmmm... it means the tft_setup.h should be placed in the Arduino library folder which is specified by < > And I tried it, put tft_setup.h in the Arduino library folder in ...\Documents\Arduino\libraries\TFT_eSPI\tft_setup.h
Still does not work
One more try, I removed the platform.local.txt in esp32 packages folder and boom.. it's working as expected
So, to make it work, I have to do 2 steps:
- Remove platform.local.txt in the esp32 packages folder
- Put tft_setup.h in the Arduino library folder
I don't know why it works that way and how to make it works as the TFT_eSPI instruction. Please help to advise this issue.
Thank you,
Manh