My touchscreen does not work with ESP32 DEVKIT V2 and ili9341

I'm afraid the display has failed.
Now it doesn't highlight this simple sketch for me:

  /***************************************************
    ----> http://www.adafruit.com/products/1651
    These displays use SPI to communicate, 4 or 5 pins are required to
    interface (RST is optional
                     
   17 gennaio 2025
   ****************************************************/
  #include "SPI.h"
  #include "Adafruit_GFX.h"
  #include "Adafruit_ILI9341.h"
  
  // For the Adafruit shield.
  #define TFT_CS  15   
  #define TFT_RST  4    
  #define TFT_DC   2    
  #define TFT_MOSI 23   
  #define TFT_CLK  16   
  #define TFT_MISO 19   

  Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
  void setup() {
    Serial.begin(9600);
    tft.begin();
  }
  void loop(void) {
    uint8_t rotation = 3; // scrittura orizzontale sul display
      tft.setRotation(rotation);
      Text1();
      //delay(1000);
  }
  
  unsigned long Text1() {
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(10, 20); // colonna, riga
    tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
    tft.println("Abcdef ghilm nopqrstuvZ");
    delay(5000);
    tft.setCursor(130, 80); // colonna, riga
    tft.setTextColor(ILI9341_CYAN); tft.setTextSize(10);
    tft.println("X");
    delay(5000);
    tft.setCursor(130, 80); // colonna, riga
    tft.setTextColor(ILI9341_BLACK); tft.setTextSize(10);
    tft.println("X");
    delay(3000);

  }

Even if I load a sketch on the ESP32 with the TouchScreen, I can see the values on the Serial Monitor but not on the display.
I made the direct connections for the display test, as per the attached photo.


The LED pin of the display is connected to pin 3v3 of ESP32.

You said the above in post #1 .
Which code did you use then?

List the connections between the screen module and the ESP32. From the picture it is impossible to see. However, if you have it working previously then the first thing to suspect is a wiring error.

I checked the wiring harness again and it is correct.
The sketch is the one in Post#21.
I will try changing the ESP32 pins to see what happens.
I have attached the connections.

You have to work much more carefully. There is at least this inconsistency:

You are right.
Haste is always a bad counselor.
I updated the sketch with the right pin and now it works
Thank you for your help.

Excellent progress. So at least you can go back to "square 1" as the idiom says.
So all you have to do now is make the additional connections between the ESP32 and the screen module, then integrate the touch screen code and it should all work fine.

I made the recommended changes, verified the connections, and now they look right.
With all pins connected this happens to me:
If I use the sketch recommended by Horace I see on the Serial Monitor the data when I press the screen, but I don't see it on the screen as well, which remains blank.
If I use the following sketch instead:

  /***************************************************
    ----> http://www.adafruit.com/products/1651
    These displays use SPI to communicate, 4 or 5 pins are required to
    interface (RST is optional)
    https://www.danielealberti.it/2019/12/come-utilizzare-un-display-tft-ili9341.html
   
   ****************************************************/
  #include "SPI.h"
  #include "Adafruit_GFX.h"
  #include "Adafruit_ILI9341.h"
  
  #define TFT_CS   15  
  #define TFT_RST  4    
  #define TFT_DC   2    
  #define TFT_MOSI 23   
  #define TFT_CLK  18   
  #define TFT_MISO 19   

  Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
  void setup() {
    Serial.begin(9600);
    tft.begin();
  }
  void loop(void) {
    uint8_t rotation = 3; 
      tft.setRotation(rotation);
      TextIni();
      //delay(100);
  }
  
  unsigned long TextIni() {
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(10, 20); 
    tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
    tft.println("AbcdefghilmnopqrstuvZ");
    tft.setCursor(1, 50); 
    tft.setTextColor(ILI9341_BLUE); tft.setTextSize(2);
    tft.println("12345678901234567890123456");  
    delay(3000);
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(130, 80); 
    tft.setTextColor(ILI9341_CYAN); tft.setTextSize(10);
    tft.println("X");
    delay(5000);
    tft.setCursor(130, 80); 
    tft.setTextColor(ILI9341_BLACK); tft.setTextSize(10);
    tft.println("X");
    delay(1000);
  }

I can see correctly the screen that presents the writings to me.
I can't understand why it doesn't work when I use it as Touch.
I'm stranded...

Does the code that you have posted in post #27 print successfully print something to the screen? It looks like it should print "12345678901234567890123456" then "X" then again "X".

The code that @horace supplied uses a different library to yours for the TFT screen and maybe that is not compatible with the way your screen is configured. However, you have said that the touch screen part of Horace's code can detect presses and write values to the serial monitor.

My suggestion is that you use the code in post #27, which writes to the screen correctly, as a basis and add in the touch screen handling part taken from Horace's code. That is you make a hybrid of the two sketches. Remember that some pins are common between the TFT screen and the touch screen as mentioned previously.

I will resume editing the sketch, aided by your advice.
Until now it had not been possible for me to do this for various reasons.

Hi Horace,
which “BOARD” do you use in post #13 to do the test?
Looking at the picture I can't trace it back to the model?
I tried with the ESP32-VROOM-DA board but it leaves my screen blank.
The sketch I use is the one in post #13 and I followed the connections meticulously as recommended.
All I see in the serial monitor are “?”
To compile I use a MacOS Catalina and Arduino 1.8.19.
If I install the sketch in post #21 it works for me regularly.

the display was a Heltec 240X320 Resolution 2.8" SPI TFT LCD Display Touch Panel ILI9341
ESP-WROOM-32
Windows 10
IDE 2.3.4
ESP32 core 3.1.0

have you set the Serial Monitor speed correctly? I use 115200baud

Yes I set it to “Serial.begin(115200);”
I will check the connections again and I had connected the VCC of the ILI 3v leaving the jumper behind the board on 5v.
Now if I touch the video with the “supplied pen,” the various values show up on the Serial Monitor.

X = 136 | Y = 88 | Pressure = 2039
X = 213 | Y = 90 | Pressure = 1226
X = 78 | Y = 69 | Pressure = 2108
X = 78 | Y = 70 | Pressure = 2150
X = 78 | Y = 69 | Pressure = 2122
X = 129 | Y = 113 | Pressure = 2115
X = 79 | Y = 64 | Pressure = 1222

I do not show up on the display, which remains white.
I have made a small step forward. :slightly_smiling_face:

Now I can't compile the sketch anymore, it gives me this error:

Arduino:1.8.19 (Mac OS X), Scheda:"ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"

[11495] Error loading Python lib '/var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIo3eKzr/libpython3.8.dylib': dlopen: dlopen(/var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIo3eKzr/libpython3.8.dylib, 10): Symbol not found: _preadv
  Referenced from: /var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIo3eKzr/libpython3.8.dylib (which was built for Mac OS X 12.7)
  Expected in: /usr/lib/libSystem.B.dylib

exit status 255

An hour ago he was compiling and installing it regularly.
I no longer know where I am wrong

Solved by installing the old version of the esp32 card.
2.0.17

I do this configuration on my side but it still does not work I use an ESP32 S3 and ILI9488 the screen gives good but the touch does not give

// TFT_eSPI touch test 240X320 Resolution 2.8_ SPI TFT LCD Display Touch Panel ILI9341

/*  Rui Santos & Sara Santos - Random Nerd Tutorials
    THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE:
    1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd/
    2) REGULAR ESP32 Dev Board + 2.8 inch 240x320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240x320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft/
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

#include <SPI.h>

/*  Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI
    *** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
    *** YOU MUST USE THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd/ or https://RandomNerdTutorials.com/esp32-tft/   */
#include <TFT_eSPI.h>

// Install the "XPT2046_Touchscreen" library by Paul Stoffregen to use the Touchscreen - https://github.com/PaulStoffregen/XPT2046_Touchscreen
// Note: this library doesn't require further configuration
#include <XPT2046_Touchscreen.h>

TFT_eSPI tft = TFT_eSPI();

// Touchscreen pins
#define XPT2046_IRQ 9                 // T_IRQ
#define XPT2046_MOSI MOSI   // GPIO23  // T_DIN
#define XPT2046_MISO MISO   // GPIO19  // T_OUT
#define XPT2046_CLK SCK     // GPIO18   // T_CLK
#define XPT2046_CS 8                    // T_CS

SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define FONT_SIZE 2

// Touchscreen coordinates: (x, y) and pressure (z)
int x, y, z;

// Print Touchscreen info about X, Y and Pressure (Z) on the Serial Monitor
void printTouchToSerial(int touchX, int touchY, int touchZ) {
  Serial.print("X = ");
  Serial.print(touchX);
  Serial.print(" | Y = ");
  Serial.print(touchY);
  Serial.print(" | Pressure = ");
  Serial.print(touchZ);
  Serial.println();
}

// Print Touchscreen info about X, Y and Pressure (Z) on the TFT Display
void printTouchToDisplay(int touchX, int touchY, int touchZ) {
  // Clear TFT screen
  tft.fillScreen(TFT_WHITE);
  tft.setTextColor(TFT_BLACK, TFT_WHITE);

  int centerX = SCREEN_WIDTH / 2;
  int textY = 80;
 
  String tempText = "X = " + String(touchX);
  tft.drawCentreString(tempText, centerX, textY, FONT_SIZE);

  textY += 20;
  tempText = "Y = " + String(touchY);
  tft.drawCentreString(tempText, centerX, textY, FONT_SIZE);

  textY += 20;
  tempText = "Pressure = " + String(touchZ);
  tft.drawCentreString(tempText, centerX, textY, FONT_SIZE);
}

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

  // Start the SPI for the touchscreen and init the touchscreen
  touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
  touchscreen.begin(touchscreenSPI);
  // Set the Touchscreen rotation in landscape mode
  // Note: in some displays, the touchscreen might be upside down, so you might need to set the rotation to 3: touchscreen.setRotation(3);
  touchscreen.setRotation(1);

  // Start the tft display
  tft.init();
  // Set the TFT display rotation in landscape mode
  tft.setRotation(1);

  // Clear the screen before writing to it
  tft.fillScreen(TFT_WHITE);
  tft.setTextColor(TFT_BLACK, TFT_WHITE);
  
  // Set X and Y coordinates for center of display
  int centerX = SCREEN_WIDTH / 2;
  int centerY = SCREEN_HEIGHT / 2;

  tft.drawCentreString("Hello, world!", centerX, 30, FONT_SIZE);
  tft.drawCentreString("Touch screen to test", centerX, centerY, FONT_SIZE);
}

void loop() {
  // Checks if Touchscreen was touched, and prints X, Y and Pressure (Z) info on the TFT display and Serial Monitor
  if (touchscreen.tirqTouched() && touchscreen.touched()) {
    // Get Touchscreen points
    TS_Point p = touchscreen.getPoint();
    // Calibrate Touchscreen points with map function to the correct width and height
    x = map(p.x, 200, 3700, 1, SCREEN_WIDTH);
    y = map(p.y, 240, 3800, 1, SCREEN_HEIGHT);
    z = p.z;

    printTouchToSerial(x, y, z);
    printTouchToDisplay(x, y, z);

    delay(100);
  }
}

can you remind us which ESP32 S3 and ILI9488 display you are using - give links if possible - if not photos
which pins are you using for the display?

my User_Setup.h


#define USER_SETUP_INFO "User_Setup"


#define ILI9488_DRIVER     // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)



#define TFT_MISO 13
#define TFT_MOSI 11
#define TFT_SCLK 12
#define TFT_CS   10  // Chip select control pin
#define TFT_DC    3  // Data Command control pin
#define TFT_RST   4  // Reset pin (could connect to RST pin)
//#define TFT_RST  -1  // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST



#define TOUCH_CS 8     // Chip select pin (T_CS) of touch screen




#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT



// #define SPI_FREQUENCY   1000000
// #define SPI_FREQUENCY   5000000
// #define SPI_FREQUENCY  10000000
 //#define SPI_FREQUENCY  20000000
#define SPI_FREQUENCY  27000000
 //#define SPI_FREQUENCY  40000000
// #define SPI_FREQUENCY  55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
 //#define SPI_FREQUENCY  80000000

// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY  60000000

// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY  2500000
#define USE_HSPI_PORT

tft 3.5 inch

The display works well and the touch screen too when they are separated but once I put them together in a code the touch screen no longer works