ESP32 ILI9341 TFT_eSPI white screen

Hello. I try to connect display ILI9341 2.4:

to esp32, like this:

and try to use for it this code:


#define ILI9341_DRIVER

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    5
#define TFT_DC    0
#define TFT_RST   4

//#define TOUCH_CS 13

#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF

#define SMOOTH_FONT

#define SPI_FREQUENCY  40000000

#define SPI_TOUCH_FREQUENCY  2500000


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

TFT_eSPI tft = TFT_eSPI();

void setup() {

Serial.begin(115200);



tft.begin();
  
  tft.setRotation(1); //Landscape
  tft.fillScreen(TFT_BLACK);
  tft.setSwapBytes(true);

delay(1000);  



}

void loop() {

  tft.fillScreen(TFT_BLACK);
        tft.setTextColor(TFT_RED);
  tft.setCursor(20, 40);
        tft.setTextSize(1.5);
        tft.println(  "TEST"  );

Serial.println("test");

delay(1000);

}

But when the sketch upload I get white screen. Please, help what can be problem?

Show an image of the actual project all wired up, please.


On the MCU, what kind of connection is that with the red wire and orange wire and bent pin?

Show how the project is being powered.

Can you show me in the TFT's API that text size is done in increments of a tenth?

red - power of tft
orange - led of tft
red and orange connect to esp32 power 3.3v

sorry, what you mean about tft’s api?

This is the library, I think, you are using.

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

When I open the .h file, TFT_eSPI/TFT_eSPI.h at master · Bodmer/TFT_eSPI · GitHub and I do a search for seTextSize I get setTextSize(uint8_t size); // Set character size multiplier (this increases pixel size) . I am shown that setTextSize takes a certain data type that does not accept decimals.

I'm not clear about the power thing you got going on.

I do not see an orange wire going to the tft in the image posted. I see a white and gray wire.

The way you got the power wired is hinky.

I don't think that the trouble in setTextSize, because tft.fillScreen(TFT_BLACK); not work too

I connect this like:

Generally, when trying to work thru hardware/software issues, the best approach is to go to the library site, make certain you have the most recent release, and find an appropriate example to test your project:

https://github.com/Bodmer/TFT_eSPI/tree/master/examples/320%20x%20240

If I use an example (All_Free_Fonts_Demo) it's need the same set

#define ILI9341_DRIVER

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    5
#define TFT_DC    0
#define TFT_RST   4

//#define TOUCH_CS 13

#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF

#define SMOOTH_FONT

#define SPI_FREQUENCY  40000000

#define SPI_TOUCH_FREQUENCY  2500000

I assume you are indicating that the screen is still "all white"?

You may wish to try another ILI9341 library: Adafruit has one and their wiring and example code.
https://github.com/adafruit/Adafruit_ILI9341

Additionally, it is a good idea to completely remove all the Dupont wiring and use fresh jumper cables; just a precaution as these jumpers have been the source of numerous prototyping issues.

/***************************************************
  Sketch uses 18226 bytes (7%) of program storage space. Maximum is 253952 bytes.
  Global variables use 608 bytes (7%) of dynamic memory, leaving 7584 bytes for local variables. Maximum is 8192 bytes.
  Arduino 1.9.0-beta on Windows 10 Pro
  Note: Works at 80MHz and 160MHz
  python /home/ray/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 /home/ray/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/partitions/boot_app0.bin 0x1000 /home/ray/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/sdk/bin/bootloader_qio_80m.bin 0x10000 /tmp/arduino_build_528244/graphicstest.ino.bin 0x8000 /tmp/arduino_build_528244/graphicstest.ino.partitions.bin 
  esptool.py v2.6
  Serial port /dev/ttyUSB0
  Connecting........___
  Chip is ESP32D0WDQ6 (revision 0)
  Features: WiFi, BT, Dual Core, Coding Scheme None
  MAC: 24:0a:c4:05:78:6c
  Uploading stub...
  
 Modified graphics demo for the ESP-WROVER-KIT and equivalent 
 projects using Ardiono-ESP32 with an ILI9341 LCD display
 By Martin Falatic
 Implemented by MRB 20200527 on Win 10 PRo w/ IDE 1.8.12
 ****************************************************/


#include <SPI.h>
#include <Adafruit_GFX.h">
#include <Adafruit_ILI9341.h>

// For the ESP-WROVER_KIT, these are the default.
#define TFT_CS   22
#define TFT_DC   21
#define TFT_MOSI 23
#define TFT_CLK  19
#define TFT_RST  18
#define TFT_MISO 25
#define TFT_LED   5  // GPIO not managed by library

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);  // software SPI
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);                            // hardware SPI

The ILI9341 and the ESP32 are rather capable together. Full code attached.

#include "SPI.h"
#include "./Adafruit_GFX.h"F
#include "./Adafruit_ILI9341.h"

const char *progname = "\n\n ILI9341 GfxTest...(20200418)";
const char *xxxx = "- requires Adafruit_ILI9341_050519";

#define USE_HSPI_PORT                                 // optional it seems

// Software Pin Name  // GPIO: HSPI    VSPI           //  ILI9341 J2      // Notes: all HSPI pins can remap
// -------------------------------------------------- //    1 VDD 3.3V
// -------------------------------------------------- //    2 GND
#define HSP_CS                  15                    //    3 CS          <========== xSPI centric
#define VSP_CS                           5
#define HSP_RST                 27                    //    4 RST         <========== User Defined (Tie to VDD)
#define VSP_RST                         25
#define HSP_DC                  26                    //    5 D/C         <========== User Defined
#define VSP_DC                          16
#define HSP_MOSI                13                    //    6 SDI-MOSI    <========== xSPI centric
#define VSP_MOSI                        23      
#define HSP_SCLK                14                    //    7 SCK         <========== xSPI centric
#define VSP_SCLK                        18
// -------------------------------------------------- //    8 LED                     !!! 3.3V NOT 5V !!!
#define HSP_MISO                12                    //    9 SDO-MISO    <========== xSPI centric (Not used ILI9341)
#define VSP_MISO                        19

// VSPI (default under Arduino)
SPIClass  SPI1(VSPI);
// Use ESP32 hardware VSPI and above defines
//Adafruit_ILI9341 tft0=Adafruit_ILI9341(VSP_CS,VSP_DC,VSP_RST);
Adafruit_ILI9341 tft0 = Adafruit_ILI9341(&SPI1, VSP_DC, VSP_CS, VSP_RST);

// HSPI 
SPIClass  SPI2(HSPI);
// static const int spiClk = 1000000;           // 1 MHz ... default is 40MHz
// Use ESP32 hardware HSPI and above defines
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(&SPI2, HSP_DC, HSP_CS, HSP_RST);


void setup(void) 
{
  pinMode(VSP_CS, OUTPUT); //VSPI SS (may not be required for 'default')
  pinMode(HSP_CS, OUTPUT); //HSPI SS
  Serial.begin(115200);
  Serial.println(progname); 
  Serial.println(xxxx);
  tft0.begin();
  tft1.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x0 = tft0.readcommand8(ILI9341_RDMODE);
  uint8_t x1 = tft1.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode 0: 0x"); Serial.println(x0, HEX);
  Serial.print("Display Power Mode 1: 0x"); Serial.println(x1, HEX);
  x0 = tft0.readcommand8(ILI9341_RDMADCTL);
  x1 = tft1.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode 0: 0x"); Serial.println(x0, HEX);
  Serial.print("MADCTL Mode 1: 0x"); Serial.println(x1, HEX);
  x0 = tft0.readcommand8(ILI9341_RDPIXFMT);
  x1 = tft1.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format 0: 0x"); Serial.println(x0, HEX);
  Serial.print("Pixel Format 1: 0x"); Serial.println(x1, HEX);
  x0 = tft0.readcommand8(ILI9341_RDIMGFMT);
  x1 = tft1.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format 0: 0x"); Serial.println(x0, HEX);
  Serial.print("Image Format 1: 0x"); Serial.println(x1, HEX);
  x0 = tft0.readcommand8(ILI9341_RDSELFDIAG);
  x1 = tft1.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic 0: 0x"); Serial.println(x0, HEX);
  Serial.print("Self Diagnostic 1: 0x"); Serial.println(x1, HEX);
}

void loop(void) 
{
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft0.setRotation(rotation);
    testText0();
    delay(1000);
  }
  gfxtest0();

  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft1.setRotation(rotation);
    testText1();
    delay(1000);
  }
  gfxtest1();
}


ESP32_HSPI_VSPI_ILI9341_OK.zip (56.8 KB)

1 Like

DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY

Make sure all the display driver and pin connections are correct by
editing the User_Setup.h file in the TFT_eSPI library folder.

hm… when using Adafruit get strange bag:

Are you using the Adafruit /Arduino/libraries updated library files (current) or the older ones that I had in the Zip I attached to this thread?

Adafruit has gone thru a big architectural rewrite of their libraries and if you are using the newest version, you will need to refer to their latest documentation.

The "sketch bound" ILI9341" in my Zip file are dated by a few years... I find these files very stable and usable across ESP8266/ESP32/STM32 devices.

It is not that I have a significant "issue" with the new architecture of Adafruit drivers; rather, I find it totally impossible to regression test libraries that change as often as Adafruit's.

I use the latest version. Now will try from your arhive

with your library I have the same result...

As you can see in the pix in post#14, I'm driving 2 ILI9341 displays from the exact code in the Zip (sketch folder.)

From your pix, it seems that the display is not configured as 320x240, or perhaps the font is being improperly displayed and not spacing out correctly.

Try my Zip with your display ... you should see the standard Adafruit test suite from years back.