ESP32-S3-LCD-1.28 display not working

Hi!

I bought a development board with a built-in screen ESP32-S3-LCD-1.28 from this link https://www.aliexpress.us/item/1005006754030454.html?spm=a2g0o.order_list.order_list_main.20.3bf41c24AWBO9i&gatewayAdapt=4itemAdapt

I’m trying using PlatformIO display something on the screen but it doesn’t working. This is my code:

main.cpp

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

TFT_eSPI tft = TFT_eSPI();

void setup() {
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_WHITE);
  tft.setTextFont(4);
}

void loop() {
  tft.fillScreen(TFT_WHITE);
  tft.fillRectHGradient(0, 0, 160, 50, TFT_MAGENTA, TFT_BLUE);
  tft.setCursor(10, 10);
  tft.print("test");

  delay(100);
}

platformio.ini

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
board_build.partitions = default.csv
board_build.extra_flags = 
	-DBOARD_HAS_PSRAM
lib_deps = bodmer/TFT_eSPI@^2.5.43

After run that i see only black screen. I learn this board from this https://www.youtube.com/watch?v=GosqWcScwC0

All of this seems wrong when the official reference says 16 MByte of QIO Flash and QSPI PSRAM. You’re setting it for 4MB QIO Flash and OPI PSRAM.

This should be

board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qspi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv

Where do you configure the TFT_eSPI library for your display? Just including the library is not enough. You have to setup all the defines or an include file for the display.

The official Wiki for the board (no touch version) at

https://www.waveshare.com/wiki/ESP32-S3-LCD-1.28#Install_library

provides a modified TFT_eSPI version at https://files.waveshare.com/wiki/ESP32-S3-LCD-1.28/ESP32-S3-LCD-1.28-Demo.zip which has the necessary library and files

So if you just want a very easy way to that premade library:

  1. Delete the lib_deps expression from your platformio.ini
  2. Delete the .pio folder of your project
  3. Copy in the downloaded TFT_eSPI folder into lib/TFT_eSPI
  4. Copy in the downloaded TFT_eSPI_Setups folder into lib/TFT_eSPI_Setups
  5. Build again

Ok, thank you. I changed my platformio.ini file and i have this content:

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qspi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
board_build.extra_flags = 
	-DBOARD_HAS_PSRAM

My main.cpp file:

#include <TFT_eSPI.h>
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI();

void setup() {
  Serial.begin(115200);

  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_WHITE);
  tft.setTextFont(4);
}

void loop() {
  tft.fillScreen(TFT_WHITE);
  tft.fillRectHGradient(0, 0, 160, 50, TFT_MAGENTA, TFT_BLUE);
  tft.setCursor(10, 10);
  tft.print("test");
}

And my lib directory content:

I tried include #include <Setup207_GC9A01.h> or #include <Setup208_ST7789.h> file but still doesn’t working

The Setup208_ST7789.h seems to be for ESP32-S3-Touch-LCD-1.69, not ESP32-S3-Touch-LCD-1.28 like the Setup207_GC9A01.h file says.

Does basic blinky and serial work at all? The chip might not be booting with wrong flash / psram configuration.

#include <Arduino.h>
#define LED 40 /* LCD backlight as LED.. */
void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
}

void loop() {
  digitalWrite(LED, LOW);
  delay(1000);
  digitalWrite(LED, HIGH);
  delay(1000);
  Serial.println("Blinky!");
}

with a platformio.iniof

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qspi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
board_build.extra_flags = 
	-DBOARD_HAS_PSRAM
monitor_speed = 115200

Full screen blink and I have Blinky! message in serial monitor

Okay.

I just noticed a slew of redefinition warnings when I compile a test firmware.

Can you go into lib/TFT_eSPI/USer_Setup_select.h and comment out line 27? Then these warnings should go away.

Within the same platformio.ini as in the previous post, can you use this code

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

TFT_eSPI tft = TFT_eSPI();

#if defined(ILI9341_DRIVER)
#error "Wrong screen type defiend (ILI9341)"
#endif

#if defined(GC9A01_DRIVER)
#warning "Right screen type defiend"
#endif

void setup() {
  delay(2000); // give serial monitor time to startup
  Serial.begin(115200);
  Serial.println("Firmware start");
  tft.init();
  Serial.println("TFT init done");
  tft.setRotation(1);
  tft.fillScreen(TFT_WHITE);
  tft.setTextFont(4);
  Serial.println("Set done");
}

void loop() {
  Serial.println("loop");
  tft.fillScreen(TFT_WHITE);
  tft.fillRectHGradient(0, 0, 160, 50, TFT_MAGENTA, TFT_BLUE);
  tft.setCursor(10, 10);
  tft.print("test");

  delay(1000);
}

During build, hopefully this message should appear

src/main.cpp:11:2: warning: #warning "Right screen type defiend" [-Wcpp]
   11 | #warning "Right screen type defiend"
      |  ^~~~~~~

confirming the right screen type. What’s the seiral output?

yyy now after upload i see something like this:

ELF file SHA256: aabd2728d

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x38 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4037984e
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x1188
load:0x403c8700,len:0x4
load:0x403c8704,len:0xbf0
load:0x403cb700,len:0x30e4
entry 0x403c88ac
Firmware start
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x42003167  PS      : 0x00060530  A0      : 0x82003240  A1      : 0x3fca2ef0  
A2      : 0x3fc97d38  A3      : 0x00000000  A4      : 0x0000000b  A5      : 0x0000000b  
A6      : 0x000000ff  A7      : 0x60004000  A8      : 0x00000010  A9      : 0x08000000  
A10     : 0x3fc997cc  A11     : 0x04c4b400  A12     : 0x00000001  A13     : 0x00000000  
A14     : 0x00001000  A15     : 0x04c4b400  SAR     : 0x0000000c  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000010  LBEG    : 0x4201be14  LEND    : 0x4201be21  LCOUNT  : 0x00000000  


Backtrace: 0x42003164:0x3fca2ef0 0x4200323d:0x3fca2f20 0x4200203b:0x3fca2f40 0x42006ec6:0x3fca2f70 0x4037cc72:0x3fca2f90

But when i compile i see:

Compiling .pio/build/esp32-s3-devkitc-1/liba86/SPI/SPI.cpp.o
In file included from src/main.cpp:2:
lib/TFT_eSPI/TFT_eSPI.h:973:8: warning: #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available! [-Wcpp]
  973 |       #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
      |        ^~~~~~~
src/main.cpp:11:2: warning: #warning "Right screen type defiend" [-Wcpp]
   11 | #warning "Right screen type defiend"
      |  ^~~~~~~

Okay, so it’s crashing.

Please add the following to the platformio.ini:

build_type = debug
monitor_filters =
  esp32_exception_decoder

And press “upload and monitor” again. What’s the output?

Also, what is the platform and packages that PlatformIO uses? That’s printed at the beginning of the build output. For me, I’m on (pioarduino) platform 54.3.20 with Arduino-ESP 3.2.0

PLATFORM: Espressif 32 (54.3.20) > Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, 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.2.0
 - framework-arduinoespressif32-libs @ 5.4.0+sha.2f7dcd862a
 - tool-esptoolpy @ 4.8.9
 - tool-mklittlefs @ 3.2.0
 - tool-riscv32-esp-elf-gdb @ 14.2.0+20240403
 - tool-xtensa-esp-elf-gdb @ 14.2.0+20240403
 - toolchain-riscv32-esp @ 14.2.0+20241119
 - toolchain-xtensa-esp-elf @ 14.2.0+20241119
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 43 compatible libraries
Scanning dependencies...
Dependency Graph
|-- TFT_eSPI @ 2.5.34

I have it:


Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x38 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4037984e
  #0  0x4037984e in esp_cpu_wait_for_intr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/cpu.c:64

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x1188
load:0x403c8700,len:0x4
load:0x403c8704,len:0xbf0
load:0x403cb700,len:0x30e4
entry 0x403c88ac
Firmware start
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x42003cdd  PS      : 0x00060530  A0      : 0x82003ee9  A1      : 0x3fca2ee0  
A2      : 0x3fc97d38  A3      : 0x00000000  A4      : 0x0000000b  A5      : 0x0000000b  
A6      : 0x000000ff  A7      : 0x3fc97ee4  A8      : 0x00000010  A9      : 0x08000000  
A10     : 0x3fc997cc  A11     : 0x04c4b400  A12     : 0x00000001  A13     : 0x00000000  
A14     : 0x00001000  A15     : 0x00000031  SAR     : 0x0000000c  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000010  LBEG    : 0x4201d810  LEND    : 0x4201d81d  LCOUNT  : 0x00000000  


Backtrace: 0x42003cda:0x3fca2ee0 0x42003ee6:0x3fca2f10 0x4200204a:0x3fca2f40 0x420087b2:0x3fca2f70 0x4037cc72:0x3fca2f90
  #0  0x42003cda in TFT_eSPI::begin_tft_write() at lib/TFT_eSPI/TFT_eSPI.cpp:81
      (inlined by) TFT_eSPI::writecommand(unsigned char) at lib/TFT_eSPI/TFT_eSPI.cpp:982
  #1  0x42003ee6 in TFT_eSPI::init(unsigned char) at lib/TFT_eSPI/TFT_eSPI.cpp:692
  #2  0x4200204a in setup() at src/main.cpp:18
  #3  0x420087b2 in loopTask(void*) at /home/kevin/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:59
  #4  0x4037cc72 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139

This is wild. The Espressif macro for “give me the register base for SPI0” just returns a nullpointer (0x0), at i = 0.

#define REG_SPI_BASE(i)         (((i)>=2) ? (DR_REG_SPI2_BASE + (i-2) * 0x1000) : (0))    // GPSPI2 and GPSPI3

It’s crashing because it wants to write to 0x00000010.

I need a moment to look at this.

I done this with commented 27 line in User_Setup_Select.h file

This seems relevant:

Can you please use this exact platformio.ini and reupload?

[env:esp32-s3-devkitc-1]
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qspi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
board_build.extra_flags = 
	-DBOARD_HAS_PSRAM
monitor_speed = 115200

build_type = debug
monitor_filters =
  esp32_exception_decoder

It’s working. Thank you so much. But what was wrong?

Output from serial:

Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x39 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a80
entry 0x403c98d0
Firmware start
TFT init done
Set done
loop
loop
loop
loop

At the base, some TFT_eSPI or Espressif code is wrong. I think https://github.com/Bodmer/TFT_eSPI/issues/3329#issuecomment-2808875061 is close to a good explanation.

Arduino cores before 2.0.16 did not define REG_SPI_BASE, so TFT_eSPI defines it in this case to always DR_REG_SPI2_BASE as a bugfix. Arduino cores after 2.0.16 do define it to

#define REG_SPI_BASE(i)         (((i)>=2) ? (DR_REG_SPI2_BASE + (i-2) * 0x1000) : (0))  

which, together with the definition of what’s used for i is FSPI and

#define FSPI 0

gives a null pointer (0) instead of DR_REG_SPI2_BASE. This crashes execution.

So it seems like the definition of FSPI is wrong for ESP32S3 or TFT_eSPI should be using HSPI not FSPI as the SPI_PORT.

We ““fixed”” it by downgrading the platform in the platformio.ini to use an older Arduino core, where TFT_eSPI uses the right REG_SPI_BASE value.

Other ports suggest that it should also work on the newer Arduino cores and ESP32S3 if you define the USE_HSPI_PORT macro to make that happen.

So, if you want another test:

[env:esp32-s3-devkitc-1]
; uses Arduino-ESP32 2.0.17
platform = espressif32@6.11.0
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qspi
board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv
; PSRAM + bugfix against TFT_eSPI/issues/3329 on newer Arduino cores
board_build.extra_flags = 
   -DBOARD_HAS_PSRAM
   -DUSE_HSPI_PORT
monitor_speed = 115200

build_type = debug
monitor_filters =
  esp32_exception_decoder

Long story short the REG_SPI_BASE in IDF is wrong. Submitted a PR and espressif IDF messed the PR up by changing it. In my private fork i have corrected. To make the Bodmer TFT_eSPI (which is outdated BTW.) you have to manually override which SPI is used