ESP32 and ILI9341, which pins to use in the sketch taken from the examples?

Hi,
I am always looking for a sketch that works with the ESP32 DEVKIT V1 and the ILI9341 display.
I found in the Adafruit TouchScreen examples this sketch:

// Touch screen library with X Y and Z (pressure) readings as well
  // as oversampling to avoid 'bouncing'
  // This demo code returns raw readings, public domain
  
  #include <stdint.h>
  #include "TouchScreen.h"
  
  #define YP A2  // must be an analog pin, use "An" notation!
  #define XM A3  // must be an analog pin, use "An" notation!
  #define YM 8   // can be a digital pin
  #define XP 9   // can be a digital pin
  
  // For better pressure precision, we need to know the resistance
  // between X+ and X- Use any multimeter to read it
  // For the one we're using, its 300 ohms across the X plate
  TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
  
  void setup(void) {
    Serial.begin(9600);
  }
  
  void loop(void) {
    // a point object holds x y and z coordinates
    TSPoint p = ts.getPoint();
    
    // we have some minimum pressure we consider 'valid'
    // pressure of 0 means no pressing!
    if (p.z > ts.pressureThreshhold) {
       Serial.print("X = "); Serial.print(p.x);
       Serial.print("\tY = "); Serial.print(p.y);
       Serial.print("\tPressure = "); Serial.println(p.z);
    }
  
    delay(100);
  }

But a problem immediately arises for me.
To which pins of the ILI9341 display should I associate the four pins of the #defines.
I couldn't find any information.
Any advice is welcome

I know what are the analog pins and digital pins of ESP32.
But my problem is to associate #define YP A2, #define XM A3, #define YM 8, #define XP 9 with which of the 14pins on the ILI9341.
Which of the 9 pins that are needed for the display or the 5 pins that are needed for the touch.

which specific ILI9341 based display do you have? give a link?
it looks like the code of post 1 is for the Adafruit 2.8" TFT LCD with Touchscreen

The link is this: 1PCS NEW 2.8 inch SPI LCD module 240*320 TFT with touch ILI9341 #YT | eBay.
It was taken from the examples of Adafruit.

the Adafruit code is probably for a different touch technology to the display you are using

try the following using the TFT_eSPI library

file Test_Touch_Controller.ino

// toutch screen connections
// connect T_CS to GPIO 5
// T_CLK to GPIO 18 CLK
// T_DO to GPIO 19 MISO
// T_DIN to GPIO 23 MOSI

// This sketch is to test the touch controller, nothing is displayed
// on the TFT.  The TFT_eSPI library must be configured to suit your
// pins used. Make sure both the touch chip select and the TFT chip
// select are correctly defined to avoid SPI bus contention.

// Make sure you have defined a pin for the touch controller chip
// select line in the user setup file or you will see "no member"
// compile errors for the touch functions!

// It is a support and diagnostic sketch for the TFT_eSPI library:
// https://github.com/Bodmer/TFT_eSPI

// The "raw" (unprocessed) touch sensor outputs are sent to the
// serial port. Touching the screen should show changes to the x, y
// and z values. x and y are raw ADC readings, not pixel coordinates.

#include <SPI.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();

//====================================================================

void setup(void) {
  Serial.begin(115200);
  Serial.println("\n\nStarting...");

  tft.init();
}

//====================================================================

void loop() {

  uint16_t x, y;

  tft.getTouchRaw(&x, &y);
  
  Serial.printf("x: %i     ", x);

  Serial.printf("y: %i     ", y);

  Serial.printf("z: %i \n", tft.getTouchRawZ());

  delay(500);

}

//====================================================================


User_Setup.h file (place in same directory as the above Test_Touch_Controller.ino file

// TFT_eSPI setup.h file for Arduino Due Module
// RP2040 Waveshare General 2inch LCD Display Module IPS Screen 240×320 ST7789

#define USER_SETUP_INFO "User_Setup"

#define ILI9341_DRIVER

// For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
//  #define TFT_RGB_ORDER TFT_RGB  // Colour order Red-Green-Blue
//  #define TFT_RGB_ORDER TFT_BGR  // Colour order Blue-Green-Red

// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation
#define TFT_WIDTH  240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 320 // ST7789 240 x 320

// If colours are inverted (white shows as black) then uncomment one of the next
// 2 lines try both options, one of the options should correct the inversion.

// #define TFT_INVERSION_ON
// #define TFT_INVERSION_OFF

#define TFT_CS   15 
#define TFT_MOSI MOSI 
#define TFT_SCLK SCK 
#define TFT_MISO MISO 

#define TFT_DC   2
#define TFT_RST  4

#define TOUCH_CS 5    // toutch screen CS pin

#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   10000000

#define SPI_TOUCH_FREQUENCY  2500000



serial monitor output as the pen is moved around the screen

x: 73     y: 3631     z: 4 
x: 0     y: 3846     z: 26 
x: 1450     y: 3512     z: 1122 
x: 1436     y: 2544     z: 1535 
x: 1371     y: 1848     z: 1802 
x: 1074     y: 952     z: 1829 
x: 1105     y: 632     z: 2074 
x: 1780     y: 715     z: 2114 
x: 2560     y: 815     z: 2121 
x: 3478     y: 988     z: 2268 
x: 0     y: 3948     z: 19 
x: 0     y: 3328     z: 43 
x: 294     y: 3578     z: 23 

once that works try the touch examples in the library, e.g. File>Examples>TFT_eSPI>GUI Widgets>Buttons>Button_demo

also worth looking at is the XPT2046_Touchscreen library

I copied the sketch and the User_Setup and put them in the same directory.
When I compile it it gives me this error:

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

/Users/ezio/Desktop/Test_Touch_Controllr/Test_Touch_Controllr.ino: In function 'void loop()':
Test_Touch_Controllr:43:7: error: 'class TFT_eSPI' has no member named 'getTouchRaw'
   tft.getTouchRaw(&x, &y);
       ^~~~~~~~~~~
Test_Touch_Controllr:49:33: error: 'class TFT_eSPI' has no member named 'getTouchRawZ'
   Serial.printf("z: %i \n", tft.getTouchRawZ());
                                 ^~~~~~~~~~~~
exit status 1
'class TFT_eSPI' has no member named 'getTouchRaw'

I rechecked the connections a couple of times and they are correct.
Especially T_CLK, T_DO and T_DIN.
I am stranded

just recompiled and linked the code OK

I am using IDE 2.3.5, ESP32 core 3.2.0, TFT_eSPI 2.5.43

Tools>Board "ESP32 Dev Module"

what is your configuration?

During Compilation the wire connections play no role.

Arduino IDE 1.8.19, TFT_eSPI 2.5.43
Tools>Board “ESP32 Dev Module”
I don't know where to find these indications: ESP32 core 3.2.0

select Tools>Board then select Boards Manager then enter ESP32
you should see a display such as

thinking again - did you copy the User_Setup.h file in to the same directory (Windows calls them Folders) as the test program .ino file?
the IDE should show tabs for the .ino and User_Setup.h files

the User_Setup.h defines the touch pin

#define TOUCH_CS 5    // touch screen CS pin

if that is not defined the function getTouchRaw() is not compiled

I copied and verified the User_Setup.h.
It is in the same folder as the .ino file.
The T_Cs is connected to the GPIO5.
The version of ESP32 that I use is 2.0.17.
If I update it to version 3.2.0 it gives me this error:

Arduino:1.8.19 (Mac OS X), Scheda:"ESP32 Dev Module, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled, Disabled"
[8206] Error loading Python lib '/var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIXQ3MAj/libpython3.8.dylib': dlopen: dlopen(/var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIXQ3MAj/libpython3.8.dylib, 10): Symbol not found: _preadv
  Referenced from: /var/folders/sf/6l3wtqc949v0lvxt3030y21m0000gn/T/_MEIXQ3MAj/libpython3.8.dylib (which was built for Mac OS X 12.7)
  Expected in: /usr/lib/libSystem.B.dylib

exit status 255
/Applications/Arduino.app/Contents/Java/arduino-builder ha restituito 255

I installed ESP32 version 3.0.0 and the sketch works.
I see on the Serial Monitor the numbers changing if I press on the display.
With versions of ESP32 higher than 3.0.0 it gives me the previous error.

if the problem is solved click the Solution button at the bottom of the reply that answered the question - this helps others with a similar question

It works now.
Thanks for the advice.