Trouble using TFT_eSPI with ESP32 on PIO

Hi all,
I am trying to use a 240x240 ST7789 TFT display with an ESP32, and I am stuck, it simply wont work. I have tried the adafruit GFX library, it compiled but nothing was showing on the screen. Then I have seen most tutorials (like this one) were using the TFT_eSPI pibrary. So I did as they advised and setup macros as build flags in my platformio.ini file. I get a whole lot of errors from std not being a template. Maybe its just missing an include for std vectors shared ptrs etc?

here ir a snippet of my errors :

Compiling .pio\build\esp-wrover-kit\libaf7\StandardCplusplus_ID572\eh_globals.cpp.o
In file included from src\main.cpp:1:0:
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\cores\esp32/Arduino.h:158:12: error: 'std::isinf' has not been declared
 using std::isinf;
            ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\cores\esp32/Arduino.h:159:12: error: 'std::isnan' has not been declared
 using std::isnan;
            ^
In file included from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream:28:0,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/istream:24,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/complex:20,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572\complex.cpp:19:
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream_helpers: In static member function 'static void std::__ostream_printout<traits, char, float>::printout(std::basic_ostream<char, traits>&, float)':
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream_helpers:250:109: error: there are no arguments to 'dtostrf' that depend on a template parameter, so a 
declaration of 'dtostrf' must be available [-fpermissive]
    length = strlen(dtostrf(f, static_cast<int>(stream.width()), static_cast<int>(stream.precision()), buffer));
                                                                                                             ^
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream_helpers:250:109: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of 
an undeclared name is deprecated)
In file included from .pio\libdeps\esp-wrover-kit\TFT_eSPI/Processors/TFT_eSPI_ESP32.h:78:0,
                 from .pio\libdeps\esp-wrover-kit\TFT_eSPI/TFT_eSPI.h:65,
                 from src\main.cpp:5:
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:37:14: error: 'shared_ptr' in namespace 'std' does not name a template type   
 typedef std::shared_ptr<FileImpl> FileImplPtr;
              ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:39:14: error: 'shared_ptr' in namespace 'std' does not name a template type   
 typedef std::shared_ptr<FSImpl> FSImplPtr;
              ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:50:22: error: expected ')' before 'p'
     File(FileImplPtr p = FileImplPtr()) : _p(p) {
                      ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:83:5: error: 'FileImplPtr' does not name a type
     FileImplPtr _p;
     ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:89:18: error: expected ')' before 'impl'
     FS(FSImplPtr impl) : _impl(impl) { }
                  ^
C:\Users\jcbsk\.platformio\packages\framework-arduinoespressif32\libraries\FS\src/FS.h:111:5: error: 'FSImplPtr' does not name a type
     FSImplPtr _impl;
     ^
In file included from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/istream:24:0,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/complex:20,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572\complex.cpp:19:
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream: At global scope:
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/ostream:318:50: error: default argument for template parameter for class enclosing 'class std::basic_ostream<charT, traits>::sentry'
   class _UCXXEXPORT basic_ostream<charT,traits>::sentry
                                                  ^
In file included from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/complex:20:0,
                 from C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572\complex.cpp:19:
C:\Users\jcbsk\.platformio\lib\StandardCplusplus_ID572/istream:343:107: error: default argument for template parameter for class enclosing 'class std::basic_istream<charT, traits>::sentry'
  template <class charT,class traits = char_traits<charT> > class _UCXXEXPORT basic_istream<charT,traits>::sentry {
                                                                                                           ^
*** [.pio\build\esp-wrover-kit\libaf7\StandardCplusplus_ID572\complex.cpp.o] Error 1
*** [.pio\build\esp-wrover-kit\src\main.cpp.o] Error 1
==================================================================== [FAILED] Took 5.01 seconds ====================================================================

I did not even start to try writing to the screen, I just want the library to compile first
Here is my .ini and main.cpp files

[env:esp-wrover-kit]

platform = espressif32

board = esp-wrover-kit

framework = arduino

build_flags =

-DUSER_SETUP_LOADED=1

-DST7735_DRIVER=1

-DTFT_WIDTH=240

-DTFT_HEIGHT=240

-DST7735_BLACKTAB=1

-DTFT_RST=PIN_D4

-DTFT_CS=PIN_D8

-DTFT_DC=PIN_D3

-DLOAD_GLCD=1

-DLOAD_FONT2=1

-DLOAD_FONT4=1

-DLOAD_FONT6=1

-DLOAD_FONT7=1

-DLOAD_FONT8=1

-DLOAD_FONT8N=1

-DLOAD_GFXFF=1

-DSMOOTH_FONT=1

-DSPI_FREQUENCY=27000000

; lib_deps = 

;   adafruit/Adafruit BusIO@^1.5.0

;   adafruit/Adafruit SSD1306@^2.4.0

;   adafruit/Adafruit ST7735 and ST7789 Library@^1.6.0

    bodmer/TFT_eSPI@^2.3.66

Main file

#include <Arduino.h>
#include <Wire.h>
#include <TFT_eSPI.h>

void setup()
{
}

void loop()
{
}

This global library is interfering, remove it.

1 Like

Thanks!! it works!. Now I get this problem when trying to upload:

Indexing .pio\build\esp-wrover-kit\libFrameworkArduino.a
*** [.pio\build\esp-wrover-kit\firmware.elf] Implicit dependency `C:\Users\jcbsk\.platformio\platforms\espressif32\builder\DUSER_SETUP_LOADED=1' not found, needed by target `.pio\build\esp-wrover-kit\firmware.elf'.
==================================================================== [FAILED] Took 24.88 seconds ====================================================================The terminal process "C:\Users\jcbsk\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'" terminated with exit code: 1.

but it is specified in the .ini file, so I do not know what is missing!!

[env:esp-wrover-kit]

platform = espressif32

board = esp-wrover-kit

framework = arduino

build_flags =

    DUSER_SETUP_LOADED = 1

    DST7735_DRIVER=1

    DTFT_WIDTH=240

    DTFT_HEIGHT=240

    DST7735_BLACKTAB=1

    DTFT_RST=PIN_D2

    DTFT_CS=PIN_D8

    DTFT_DC=PIN_D4

    DTFT_MOSI=23

    DTFT_SCLK=18

    DLOAD_GLCD=1

    DLOAD_FONT2=1

    DLOAD_FONT4=1

    DLOAD_FONT6=1

    DLOAD_FONT7=1

    DLOAD_FONT8=1

    DLOAD_FONT8N=1

    DLOAD_GFXFF=1

    DSMOOTH_FONT=1

    DSPI_FREQUENCY=27000000

; lib_deps = 

;   adafruit/Adafruit BusIO@^1.5.0

;   adafruit/Adafruit SSD1306@^2.4.0

;   adafruit/Adafruit ST7735 and ST7789 Library@^1.6.0

    bodmer/TFT_eSPI@^2.3.66

You’re missing all the - in fron fron of each option. Also there should be no space between the name and the value and the = sign.

build_flags =
    -DUSER_SETUP_LOADED=1
    -DST7735_DRIVER=1
    ...

Also the last line seems active but not the lib_deps line, so either the first should be commented in or the last one commented out, too.

You’re missing all the - in fron fron of each option. Also there should be no space between the name and the value and the = sign.

Ho, I thought it was a pasting error, so I removed them, because when I put them, without spaces between =, I get these errors

> Executing task: C:\Users\jcbsk\.platformio\penv\Scripts\platformio.exe run <

Warning! Ignore unknown configuration option `-dtft_width` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dtft_height` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dst7735_blacktab` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dtft_rst` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dtft_cs` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dtft_dc` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_glcd` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font2` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font4` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font6` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font7` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font8` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_font8n` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dload_gfxff` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dsmooth_font` in section [env:esp-wrover-kit]
Warning! Ignore unknown configuration option `-dspi_frequency` in section [env:esp-wrover-kit]

Also the last line seems active but not the lib_deps line, so either the first should be commented in or the last one commented out, too.

My mistake! It doesn’t solve the issue though :frowning:

You’re missing the indentation now it seems. There must be at least two spaces before each flag. In VSCode, you can also select all the lines and press ‘Tab’ once to shift them to the right.

1 Like

Thanks a lot, I could have been more proactive and checked the syntax better… I didnt understand how the arguments worked. Now it uploads!

I have tried for over an hour with different .ini pin settings, and TFT_eSPI examples, but nothing prints on the screen…

I am using a SPI (even though its printed SCL and SDA, its SCK and MOSI) ST7789 with the SS pin unavailable, so 7 pins are accessible in total. I know it works because I have been using it with arduinos and adafruit gfx, (library which I havent been able to print anything on the screen either with the ESP32…)

I am attaching a photo, in case, but I am basically using the connections described here Interfacing Arduino with ST7789 TFT Display - Graphics Test Example but with the SPI on my esp32.

I am using the wroover, specifically this one from digikey
https://www.digikey.ca/en/products/detail/espressif-systems/ESP32-DEVKITC-VE/12091812

If anyone has an idea what is going on, please let me know!
Thanks again a lot Max

Have you tried putting just 2, 8 and 4 here so that it goes to GPIO 2, 8, 4? The PIN definitions are for ESP8266 boards.

Thus if you do PIN_D2 you actually get GPIO4, which is not the way it’s connected.

Also this is then wrong and must be (GPIO) 13 and 14, no?

This is my latest .ini… I reckon I have checked the pins like a million times, I cant tell what is missing. Is there anything else I am supposed to do before the library works on platformIO??

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = arduino
build_flags =
    -DTFT_MOSI=13
    -DTFT_SCLK=14
    -DUSER_SETUP_LOADED=1
    -DST7735_DRIVER=1
    -DTFT_WIDTH=240
    -DTFT_HEIGHT=240
    -DST7735_GREENTAB2=1
    -DTFT_RST=2
    -DTFT_CS=0
    -DTFT_DC=4
    -DLOAD_GLCD=1
    -DLOAD_FONT2=1
    -DLOAD_FONT4=1
    -DLOAD_FONT6=1
    -DLOAD_FONT7=1
    -DLOAD_FONT8=1
    -DLOAD_FONT8N=1
    -DLOAD_GFXFF=1
    -DSMOOTH_FONT=1
    -DSPI_FREQUENCY=27000000
lib_deps = 
;   adafruit/Adafruit BusIO@^1.5.0
;   adafruit/Adafruit SSD1306@^2.4.0
;   adafruit/Adafruit ST7735 and ST7789 Library@^1.6.0
    bodmer/TFT_eSPI@^2.3.66

If a pin is not available, TFT_eSPI expects a pin number of -1, per their wiki Installing on PlatformIO · Bodmer/TFT_eSPI Wiki · GitHub. This tells it to use GPIO 0.

Okay so here you say it’s a ST7735 based display but in the link you’ve posted

It talks about a ST7789 based display? Which one is it? Do you have the link to the seller page?

Have you tried -DST7789_DRIVER=1?

What is the cpp code you’re currently testing with?

3 Likes

their wiki Installing on PlatformIO · Bodmer/TFT_eSPI Wiki · GitHub.

Omg I should have found that page sooner, I would have left you alone hahaha

I am using ST7789, I realize I didnt understand correctly how the library worked… So yeah I just switched to ST7789 in the macros and it works now!

I owe you my life for like then tenth time this year, thanks again

2 Likes