TFT_eSPI library

Trying to program a 2.8" ILI9341 240 * 320 TFT LCD Screen using TFT_eSPI library. I have tried PlatformIO and the IDE, changed the pin number regime and all that happens is the Nano locks up.

Any thoughts?

Yup. Yet another newbie who didn't read the forum guide!

"I don't need to read that, because I'm certain that the forum members all have amazing psychic powers."

Welcome to the forum

What sketch are you using to test the display ?

Please post it in full using code tags when you do.

Have you made the required changes to the User_Setup_Select.h file ?

Sorry to upset the system. I will read the guidelines.

Yes the user setting file has been updated.

User_Setup.h (18.2 KB). This is a txt file I'll have to do some research before I upload the script.

John

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post full error messages in code tags as it makes it easier to scroll through them and copy them for examination

To post the error message, click the "COPY ERROR MESSAGES" button in the IDE, paste the copied messages in a reply here, select all of it and click the < CODE > icon above the reply editor to add the code tags and then save the reply

Can you please confirm that you are using a Nano ESP32 board and not a generic ESP32 board ? If so, which pin mapping option you have selected in the IDE ?

A schematic showing how the board and screen are connected would also be helpful

For Clarification, are you using an Arduino Nano or a Nano ESP32 ? They are 2 different boards.

In your User Setup file, you have ILI9341_DRIVER uncommented, but right below it is an alternative driver that might work. I also needed to use the ILI9341_2_DRIVER for my display.

If you are using a basic Nano, then you will need to use a level shifter to drop the 5v logic down to 3.3v that the display needs.

If you are using a Nano ESP32, then no level shifter is needed.

Please confirm what you have and how everything is wired with a wiring diagram. Hand drawn is fine, just make it look clean.

Yes it is a Nano esp32. Here is a table of connections.

```

VCC 3.3
GND Ground
CS (Display) D10
RESET / RST D9
DC / RS D8
SDI (MOSI) D11

SCK D13
SDO (MISO) D12
LED 3.3V
SDO (MISO) D12
T_CLK D13
T_CS (Touch) D7
T_DIN (MOSI) D11
T_DO (MISO) D12
T_IRQ D2

```

If you disconnect the touch pins, what does the screen do? Also please try that second driver.

Hi. Back on the case.

Disconnecting the touch pins makes no difference. I tried the second driver listed and it made no difference.

Symptoms. The screen is blank except for the backlight. The project compiles with no error message and seems to upload correctly. The serial connection on the board then keeps disconnecting/connecting. The RGB led also gives an interesting colourful display.

Recovery is 2 taps of the reset button and upload a different sketch.

I've tried 2 nano esp32s and 2 display boards.

The present sketch is very basic. I'll upload tomorrow, but I don't think it's to blame.

I should also mention that I have tried GPIO numbering as well. I also have an other Nano esp32 drive 1.8" SPI display with no problems.

Sketch follows

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

void setup() {
  tft.init();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.drawString("TFT_eSPI Configured!", 20, 20);

  // Check if touch chip responds
  uint16_t x = 0, y = 0;
  if (tft.getTouch(&x, &y)) {
    // Touch interface active
  }
}

void loop() {
  uint16_t x, y;
  if (tft.getTouch(&x, &y)) {
    tft.fillCircle(x, y, 2, TFT_GREEN); // Draw where you touch
  }
}

Does it stay white if you change the fillscreen(TFT_BLACK) from black to say red? Perhaps the screen is correct, its just inverted and you have white on white.

Sorry tried that. Remember the nano esp32 is in a locked state too.

In the process of fault finding I tried a 1.8" TFT on the Nano esp32 using TFT_eSPI and got the same result, blank screen and red, green, blue sequence on the RGB Led.

Using Adafruit_GFX.h and Adafruit_ST7735.h works exactly as expected.

By the way, yes I did modify the User_Setup.h file. Its as if TFT_eSPI and nano esp32 have a problem. Lets hope its not just me.

Did you answer this question ?

I did, I selected Arduino mapping.

My apologies, I missed that

Hi @JohnJT. Unfortunately there is a compatibility problem between the TFT_eSPI library and boards that use the ESP32-S3 microcontroller, such as the Nano ESP32:

With most 3rd party boards, we see some debug information in the Arduino IDE Serial Monitor that makes it easier to understand the nature of the problem:

Core  1 register dump:
PC      : 0x42002edf  PS      : 0x00060530  A0      : 0x82002fb8  A1      : 0x3fcebce0  
A2      : 0x3fc97768  A3      : 0x00000000  A4      : 0x0000000c  A5      : 0x0000000b  
A6      : 0x000000ff  A7      : 0x60004000  A8      : 0x00000010  A9      : 0x08000000  
A10     : 0x3fc9788c  A11     : 0x02625a00  A12     : 0x00000001  A13     : 0x00000000  
A14     : 0x02625a00  A15     : 0x3fcebcb8  SAR     : 0x00000009  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000010  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0xffffffff  


Backtrace: 0x42002edc:0x3fcebce0 0x42002fb5:0x3fcebd10 0x42001de2:0x3fcebd30 0x42007d99:0x3fcebd60 0x4037b2ad:0x3fcebd80


ELF file SHA256: 405ab02e6

Rebooting...

However, the Nano ESP32 board does not produce this debug output when in the default "TinyUSB" USB Mode configuration. The exception instead only causes the board to no longer produce a serial port.

I saw that users reported finding a solution:

https://github.com/Bodmer/TFT_eSPI/issues/3284#issuecomment-2663236298

I found a tip on Redit, enable the following line in your User_Setup.h

#define USE_HSPI_PORT

Now for me it works like a charm!

You can see the setting is present in your User_Setup.h file, but commented out (as is default):

// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
// If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam)
// then uncomment the following line:
// #define USE_HSPI_PORT

So uncomment that line in your User_Setup.h file, save the modified file, then upload the sketch to your board once again. Hopefully it will work as expected after that.