ESP32 S3 with display IPS 240x240 not working (solved) - Page 1
Forum section: electronics / general

author: ggchab
author_rank: Frequent Contributor
timestamp: August 02, 2025, 07:53:54 am
content: In my project, I want to use a display module IPS 240x240 (ST8879) with an ESP32 S3 module.My simple test code is the following one:Code:#include <Arduino_GFX_Library.h>#define TFT_DC 47 // pins assignement#define TFT_RST 21#define TFT_SCK 12#define TFT_MOSI 11#define TFT_MISO -1#define TFT_CS -1#define TFT_BL 48Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO, &SPI, true);Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_CS, 240, 240, 0, false, true);void setup() {pinMode(TFT_BL, OUTPUT);digitalWrite(TFT_BL, HIGH); // Turn on backlightgfx->begin(1000000);Serial.println("begin done");gfx->fillScreen(GREEN);gfx->setCursor(10, 10);gfx->setTextColor(WHITE);gfx->setTextSize(2);gfx->println("Display OK");}void loop() {// Your loop code here}As usual (from my personal Arduino experience), this did not work. From the SPI trafic, it was clear that data to fill the screen or write text was never sent.I also tried the "TFT_eSPI" library but I could never make the SPI bus working properly.So, I dug a bit in the "GFX_Library_for_Arduino" library and found something I don't understand:in "Arduino_GFX.cpp", _width, _height, _max_x, _max_y, ... are not initialized and remain null.As a test, I set the correct values directly in the library and I got the expected result (green screen with text).What am I doing wrong ?Thanks for any help.

author: peter-h
author_rank: Super Contributor
timestamp: August 02, 2025, 08:12:25 am
content: I used a similar or same LCD with a 32F417. You have a typo: ST7789 not 8879, I think.https://www.eevblog.com/forum/projects/graphics-on-an-embedded-system-tft-display-need-help-with-some-pointers/msg3861806/#msg3861806https://www.eevblog.com/forum/projects/small-tft-display-5x5cm-for-moving-graphics-over-spi/msg3860261/#msg3860261https://www.eevblog.com/forum/microcontrollers/anyone-here-using-the-ramtex-graphics-library/Lots of things to go wrong. You need to probe the signals with a scope. Get the SPI working first, outputting some known data.After that, I used the above mentioned Ramtex lib. There is much free code online but most just sets a pixel which is too slow for any practical use especially over SPI.

author: hans
author_rank: Super Contributor
timestamp: August 02, 2025, 08:41:59 am
content: Is there a reason why SPI CS (and perhaps MISO) pin number is -1? Maybe the library code halts on that condition, since almost universally all SPI devices need a CS.Unless the display is simply a shift register interface but I doubt it.

author: peter-h
author_rank: Super Contributor
timestamp: August 02, 2025, 09:38:09 am
content: The ST7789 needs data, clock, D/C selector, and CS.The magenta trace is the D/C selector; not moving in this case. You can have a lot of fun with D/C; it needs to be set up on a per-byte basis. With some commands like fills (basically drawing horizontal lines etc - see linked threads above) you can have D/C=1 for long periods and then you can use DMA to shift the data fast. This chip will do 60MHz clock speed. I posted videos in the other thread showing the differences. The timing in the pic would actually produce very slow graphics, even on this 240x240.The /CS could in principle be low all the time, possibly, but I doubt it. Unwise anyway since any crap would be loaded.Practical implementations also need an ambient light sensor and a DAC-driven backlight driver for variable brightness. With some controllers you have to blank the backlight during some ops like reset (see linked threads) but not with this one, thankfully.

author: ggchab
author_rank: Frequent Contributor
timestamp: August 02, 2025, 02:39:45 pm
content: Yes, pins are set to -1 for "do not use". They are not available on the display. I guess this type of displays needs a dedicated SPI bus ...

author: ggchab
author_rank: Frequent Contributor
timestamp: August 02, 2025, 02:58:12 pm
content: I have no problem with the SPI bus with the "GFX_Library_for_Arduino" library.I could make the display working but not without defining some internal variables (_width, _height, ..., directly in the library files) that remained uninitalized.Of course, this is a bad solution and I would like to find a better way."fillScreen()" function in file Arduino_GFX.cpp":Code:/**************************************************************************//*!@brief Fill the screen completely with one color. Update in subclasses if desired!@param color 16-bit 5-6-5 Color to fill with*//**************************************************************************/void Arduino_GFX::fillScreen(uint16_t color){_width = 240; // temporary solution to make it work_height = 240; // temporary solution to make it work_max_x = 239; // temporary solution to make it work_max_y = 239; // temporary solution to make it work_max_text_x = _max_x; // temporary solution to make it work_max_text_y = _max_y; // temporary solution to make it workfillRect(0, 0, _width, _height, color);}

author: ggchab
author_rank: Frequent Contributor
timestamp: August 02, 2025, 07:38:58 pm
content: Solved: the call to "Arduino_ST7789()" I found in the example was not correct.It must be (in the case of my display):Code:Arduino_GFX *gfx = new Arduino_ST7789(bus, -1, 0, true, 240, 240, 0, 0, 0, 0);Parameters:- Pointer to your Arduino_DataBus object- Reset pin (use -1 if not connected)- Display rotation (0–3)- true if using IPS panel- Width and height of the display- Column offset from left- Row offset from top- Column offset from right- Row offset from bottom