ESP32 with ST7796S 4.0inch TFT SPI

I am trying to use ESP32 with 4.0inch TFT SPI ST7796S

I am using bodmer library and trying the examples but it is not working and I am getting a white screen. GitHub - Bodmer/TFT_eSPI: Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips

Here are my connections from TFT to ESP32 with setup files attached. I have an SD card inserted, and don’t plan to use the touch screen functionality:
TFT_VCC - 3.3V
TFT_GND - GND
TFT_CS - 5
TFT_RESET - 4
TFT_DC/RS - 2
TFT_MOSI - 23
TFT_SCLK - 18
TFT_LED - 3.3V
TFT_MISO - 19

Should this LCD be compatible with my setup? If not is there a 4.0inch LCD that you can recommend (or 3.5inch, but I prefer 4.0inch or greater size) or a different library I should use?

Also when I run “Read_User_Setup” for some reason I get TFT_CS = GPIO 15 even though it should be 5.

TFT_eSPI ver = 2.1.3
Processor    = ESP50
Frequency    = 240 MHz
Transactions = Yes 
Interface    = SPI 
Display driver = 7796
Display width  = 320 
Display height = 480 

MOSI    = D-1 (GPIO 23)
MISO    = D-1 (GPIO 19)
SCK     = D-1 (GPIO 18)
TFT_CS   = D8 (GPIO 15)
TFT_DC   = D4 (GPIO 2)
TFT_RST  = D2 (GPIO 4)

TOUCH_CS = D-1 (GPIO 22)

Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled

Display SPI frequency = 80.0 MHz 
Touch SPI frequency   = 2.5 MHz

User_Setup_Select.h (8.68 KB)

my_custom_setup.h (4.4 KB)

ILI9481, ILI9486 and ILI9488 can only write 6-6-6 format for each pixel. i.e. Three SPI bytes.

ILI9341 can write 5-6-5 format for each pixel. i.e. Two SPI bytes ST7796S can write 5-6-5 format for each pixel. i.e. Two SPI bytes

ILI9341, ST7796S can write 6-6-6 if you ask them to. But there is no point in wasting SPI traffic. Unless your TFT panel really wants 18-bit resolution.

Untested for ST7796S. I do not have this screen.

David.

Ok thanks I will try and order ILI9488 and see if that works. Better be safe with that since ST7796S no luck for me so far

Your User_Setup_Select.h has got two includes. You should only have one.

Make sure that your Read_User_Setup reports as expected.

Personally, I use this wiring for SPI displays:

#if defined(ESP32)
#define RESET_PIN 12
#define CD_PIN    13
#define CS_PIN    5
#define NO_CS_PIN 14
#define MOSI_PIN  23
#define SCK_PIN   18

My apologies. I just made statements about ST7796S and had not read your files. It looks as if Bodmer supports ST7796 parallel. And it should support SPI too.

I suggest that you wire the display with my scheme. (ignore the NO_CS_PIN) Edit your User_Setup to match.

Try it. It will take 10 minutes from your life. Buying a new screen from China means waiting for 8-59 days

I note that your ST7796S SPI screen is not common on AliExpress. And none of the ST7796S screens have the XPT2046 mounted. i.e. no Touch !!

David.

I fixed the #include of two files and reduce to 1 file and still doesn't work, but "Read_User_Setup" is now showing correctly.

Your setup doesn't include MISO Pin. Shouldn't MISO be required?

Also my board doesn't have CD and has DC/RS instead.

Here is the pinout I found http://www.lcdwiki.com/4.0inch_SPI_Module_ST7796

I took the defines from one of my files. CD means the same as DC. You don't need to connect MISO but it would be 19.

I would guess that Bodmer's TFT_eSPI will be fine for ST7796 SPI. I know that it works with ST7735, ILI9341, ILI9488 SPI.

ILI9488 does not 3-state its SDO pin (MISO) properly. (ILI9341 is good) When you get your ST7796 operational, it will be good to test its SDO bahaviour.

David.

I tried your connections but still not working.

Power, LED, and GND connections
TFT_VCC - 3.3V
TFT_LED - 3.3V
TFT_GND - GND

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 5 // Chip select control pin
#define TFT_DC 13 // Data Command control pin
#define TFT_RST 12 // Reset pin (could connect to RST pin)

Output of Read_User_Setup:

TFT_eSPI ver = 2.1.3
Processor    = ESP50
Frequency    = 240 MHz
Transactions = Yes 
Interface    = SPI 
Display driver = 7796
Display width  = 320 
Display height = 480 

MOSI    = D-1 (GPIO 23)
MISO    = D-1 (GPIO 19)
SCK     = D-1 (GPIO 18)
TFT_CS   = D1 (GPIO 5)
TFT_DC   = D7 (GPIO 13)
TFT_RST  = D6 (GPIO 12)

Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled

Display SPI frequency = 80.0 MHz

User_Setup_Select.h (8.68 KB)

Setup27_RPi_ST7796_ESP32.h (4.4 KB)

Your link shows a regular Red SPI display.

Why have you selected RPI_DISPLAY_TYPE ?

I would select regular SPI. SPI Frequency = 27MHz (or lower)

Otherwise your settings look correct.

Do you possess a Red ILI9341 or ST7735 display? These could verify your wiring is correct.

David.

// With an RPi ST7796 MH4.0 display 80MHz is OK for ESP32, 40MHz maximum for ESP8266

I saw above comment in the file which said 80MHz was OK, but I tried lowering the frequency and still not working and double confirmed all the connections matches.

Unfortunately, I don't have ILI9341 or ST7735 at the moment. I did order ILI9488 in early February at the same time as a back up to the ST7796S because I had a feeling this ST7796S wouldn't work, but I wanted the 4.0inch screen and thought it was worth the try since I saw in the notes ST7796 was compatible. Hopefully ILI9488 comes in a couple weeks and I can try it out.

https://www.aliexpress.com/item/4000294208897.html?spm=a2g0s.9042311.0.0.32324c4dfv4Wna

ILI9488 should work right? Or should I consider also getting ILI9341 or ST7735 as a backup? I don't see much available in the US that I can purchase for quick shipment with 3.5 inch or greater display.

Your link shows a regular Red SPI display.

The RPi abortions are generally Blue pcb. These use a shift register to drive a parallel TFT module. And come in both Arduino Shield format or RaspberryPi Hat format.

Bodmer has always supported regular SPI TFT displays like the Red display that you have bought.

Bodmer supports the RPi abortions but obviously you require a RPi Hat or Arduino Shield. His 80MHz comment refers to the shift register on some RPi abortions. Most of the shift register boards will not go very fast.

I don't own your specific ST7796S Red SPI display. But I do have ST7735, ILI9341, ILI9488 Red SPI displays and they all work with Bodmer's TFT_eSPI library. 27MHz is a suitable SPI frequency.

David.

Thanks for all your help David, I did not know that.

I will wait for my ILI9488 to arrive and will try again.

Go on. The ST7796S is sitting on your desk. Why not try it with native SPI i.e. like

C:\Users\David Prentice\Documents\Arduino\libraries\TFT_eSPI\User_Setups\Setup15_HX8357D.h

but with

#define ST7796_DRIVER

If you start with one of Bodmer's sample setups, you can be confident that the wiring scheme has been tested. I tend to follow my historic schemes because I have already soldered the relevant Protoboard. It is wiser to start with Bodmer's scheme.

Incidentally, the ST7796S should be significantly faster than ILI9488. Which is why it is worth 10 minutes of your life.

David.

Yes I have tried that. I wished it worked, but it hasn't worked thus far.

The AliExpress offerings are VERY ambiguous. Many of them show photos of a Touch Panel in the "headline image" but photos of a "missing XPT2046" in the body of the page.

There seems little point in buying a board with "touch terminals" on the pcb but no touch panel or controller.

I have ordered ST7796S with Touch Panel

I will let you know how it compares with my ILI9488 board when it arrives.

David.

Hi David,

Thank you! You are awesome, yes definitely let me know how it turns out. I will have it on the side as a backup =)

If it's significantly faster than ILI9488, then I may revert back to it if I can get it working

The one I ordered has no Touch, but does have touch terminals.

I thought it did have touch when I ordered, so yes I agree very confusing

Edit: Also I just ordered ILI9341 with 2 day shipping so will get to try that soon

I just got ILI9341 in the mail and its working no problem! :grinning:

Hello,

i have made the change shown here https://github.com/lcdwiki/LCDWIKI_SPI/pull/1/files

using softwareSPI mylcd(ST7796S, 5, 13, 19, 23, 12, 18, -1); //ESP32

ST7796S 4.0inch TFT SPI is working fine with esp32 need to try touch function now

Thanks a lot david for your work !

David has identifed the problem in the init file which affects SPI displays. The TFT_eSPI library on Github has been updated. Alternatively edit the init file to read as shown here.

Thanks a lot, everything is working now, using github.com/Bodmer/TFT_eSPI

just a small issue with touch function, 2048 AND 4095 Z value appearing randomly (certainly hardware issue), i just add "if (z1 == 4095) return false" same for 2048 in touch.ccp / validTouch function.

For info lcdwiki_touch is not working with esp32, but is useless regarding the great Bodmer's work !

lost73: Thanks a lot, everything is working now, using github.com/Bodmer/TFT_eSPI

just a small issue with touch function, 2048 AND 4095 Z value appearing randomly (certainly hardware issue), i just add "if (z1 == 4095) return false" same for 2048 in touch.ccp / validTouch function.

For info lcdwiki_touch is not working with esp32, but is useless regarding the great Bodmer's work !

May I know how you made the ST7796s work with ESP32, I also having white screen.

below is the link of my 4" TFT with driver ST7796s detail http://www.lcdwiki.com/4.0inch_SPI_Module_ST7796

the same display did work on my Arduino nano & mega but just can't work on ESP32 board.

my read user_setup as below

TFT_eSPI ver = 2.2.8
Processor    = ESP32
Frequency    = 240MHz
Transactions = Yes
Interface    = SPI
Display driver = 7796
Display width  = 320
Display height = 480
MOSI    = GPIO 23
MISO    = GPIO 19
SCK     = GPIO 13
TFT_CS   = GPIO 2
TFT_DC   = GPIO 12
TFT_RST  = GPIO 4
Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled

Display SPI frequency = 80.00