Esp32 - ST7735 - TFT_eSPI with tft_setup.h not working

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:

  1. Copy platform.local.txt to esp32 packages (C:\Users\xxxxx\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\platform.local.txt)
  2. Close Arduino IDE and open it again (to make sure all changes applied)
  3. 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:

  1. Remove platform.local.txt in the esp32 packages folder
  2. 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

Hi @tanmanh0707,

I can't believe that use of this new setup.h feature of TFT_eSPI is so hard to use.
I don't have time to check, but you could mention @bodmer, so he might notice you need help.

If you (or any other reader) have problems with the use of setup configuration of TFT_eSPI,
you might take a look at an alternative, a library I recently came across: Arduino_GFX.
It is available from Library Manager, and uses Adafruit_GFX method names for graphics.
It is derived from Adafruit_GFX, but adds much more fonts support (taken from other libraries). I like the design, the separation of the IO support, solved better than by Adafruit in my opinion.
And the configuration (driver selection) in the application.

GitHub - moononournation/Arduino_GFX: Arduino GFX developing for various color displays and various data bus interfaces

But I still have to try it out, for an evaluation.

Jean-Marc

That isn't the intention of tft_setup.h. In this case it is the same as using user_setup.h. For the next other screen you must change tft_setup.h and that isn't the way Bodmer has implemented it.

I have tested the same issue and don't have it work. Same problems. In most cases I use ESP32 and ILI9486 or ILI9341. Changing user_setup.h isn't required every time.

Is Arduino_GFX compatible with OpenFontRender ?

#define setDrawPixel(F) set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { return F(x, y, c); })
#define setDrawFastHLine(F) set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { return F(x, y, w, c); })
#define setStartWrite(F) set_startWrite([&](void) { return F(); })
#define setEndWrite(F) set_endWrite([&](void) { return F(); })
#define setPrintFunc(F) set_printFunc([&](const char *s) { return F(s); })

Yes, this seems to be the case. It doesn't use nor inherit from Adafruit_GFX.
So you would just need to set the methods of Arduino_GFX instead of Adafruit_GFX, I assume.

But I have no experience yet with Arduino_GFX.

Note that you use an outdated version of the package.
Open preferences, and update the download link for ESP32.
Click Click for a list of unofficial boards... to find the actual download link.

Yes, that's why I posted this question

I intended to use that version since my source code has some Bluetooth logic code need to be updated if I use the latest version. Is it the reason why it doesn't work?
@buckfast_beekeeper which esp32 package version are you using?

The same as you. 1.0.6.

I would not expect. I just wanted to warn, as some users are not aware of the outdated link.
Version 1.0.6 may cause hangs if Serial.begin() is called twice.

Never has that problem.

The ESP32 processor hangs on a second call to Serial.begin(115200) when compiled for ESP32 Dev Module. · Issue #5043 · espressif/arduino-esp32 · GitHub

At the moment I use TFT_eSPI with the OpenFontRender.
screenshot_63358

This clock use only 1 font on an ILI9486 480*320 OLED. That is the first combination what gives smooth text and numbers with only one font. Not load or unload font to get another size.

This is my new night clock that I can read without glasses. :grinning:

Don't work @ESP8266 due the small heap size.

Update.

With platform.local.txt in the ESP map I have compiler problems.

#error "ESPDateTime only support ESP32 or ESP8266 platform!"

Is one of them. While ESP32 board is selected.

I have removed the file. Compiler problems where gone.

I placed tft_setup.h before TFT_eSPI.h and it seems to work.

#include "tft_setup.h"
// display afhankelijke libraries
//#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

If I comment TFT_INVERSION_OFF and uncomment TFT_INVERSION_ON. The screen invert after uploading the program. If I change back the screen is back normal.

#define TFT_INVERSION_OFF
//#define TFT_INVERSION_ON

Yet not tested with other pins for MISO, MOSI, ....

Using the original approach by editing User_Setup.h or User_Setup_Select.h in the library folder works well, and is no big nuisance for users who don't often compile for different displays.
TFT_eSPI is my first choice when I get a new SPI display.

Other approaches for display selection may be preferable for application developers who want to support many displays and provide an easy selection method.

Yes, that's what I'm working with.

1 Like

I have just ordered this 2.8 Inch Smart Display ESP32 for Arduino LVGL WIFI&Bluetooth 240*320 Screen LCD TFT Module With Touch WROOM.
Then I will start using it with Arduino_GFX, to learn more about this library.
Oops: It has ILI9341, I still have no display with ST7735.
See ESP32-2432S028R all in one display, Touch SPI problems - Using Arduino / Displays - Arduino Forum.

I did not find such features in the new version of the library, has it been deleted?

The example was in the example/generic section with as name Sketch_with_tft_setup It seems it is deleted in the github section.

you can see the contents of this file

That example has been deleted in below commit

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.