Skip to content

ESP32 ILI9341 TFT Touchscreen: Show Text and Touch | ShillehTek

April 17, 2026

Project Overview

ESP32 with 2.8 inch TFT LCD Touchscreen (ILI9341): This guide shows how to wire and program a 2.8 inch SPI TFT LCD touchscreen module (ILI9341 + XPT2046) to an ESP32 so it displays text and reports touch coordinates and pressure on-screen and in the Serial Monitor.

  • Time: 20 to 30 minutes
  • Skill level: Beginner to Intermediate
  • What you will build: A touchscreen interface on the ESP32 that displays text and responds to touch input with coordinate and pressure readings.
ESP32 dev board connected to a 2.8 inch ILI9341 TFT LCD touchscreen showing Hello World text
The finished setup: ESP32 driving a 2.8 inch ILI9341 TFT touchscreen display.

Parts List

From ShillehTek

External

  • USB-C cable - to program the ESP32 and provide power
  • Computer with Arduino IDE installed

Note: The TFT display VCC pin can accept either 5V or 3.3V depending on the J1 solder bridge on the back of the board. By default, J1 is open, meaning VCC should be connected to 5V. If J1 is closed (bridged), connect VCC to 3.3V instead.

Step-by-Step Guide

Step 1 - Introducing the TFT LCD Touchscreen Display

Goal: Understand the display module you will be working with.

What to do: The 2.8 inch TFT LCD used in this project communicates over SPI and uses the ILI9341 driver. It supports a 240x320 pixel resolution, which is enough for text, shapes, and simple images. The touchscreen overlay also communicates over SPI using a separate chip select line. The module additionally includes an SD card slot for loading files if needed.

Close-up of a 2.8 inch ILI9341 TFT LCD touchscreen module showing the screen and pin header
The 2.8 inch TFT LCD touchscreen module with ILI9341 driver.

Step 2 - Wire the TFT Display to the ESP32

Goal: Connect all display and touchscreen pins to the correct ESP32 GPIOs.

What to do: Wire the TFT LCD and touchscreen pins to the following ESP32 GPIOs. Use these exact pins for the code and library configuration to work correctly.

ESP32 dev board wired to a 2.8 inch ILI9341 TFT LCD touchscreen on a breadboard with jumper wires
Wiring the TFT LCD touchscreen to the ESP32 on a breadboard.

Use this pin mapping table:

TFT LCD / Touchscreen Pin ESP32 GPIO
T_IRQ GPIO 36
T_OUT GPIO 39
T_DIN GPIO 32
T_CS GPIO 33
T_CLK GPIO 25
SDO (MISO) GPIO 12
LED GPIO 21
SCK GPIO 14
SDI (MOSI) GPIO 13
D/C GPIO 2
RESET EN/RESET
CS GPIO 15
GND GND
VCC 5V (or 3.3V)*
Close-up of the TFT LCD touchscreen module pin labels for wiring reference
Pin labels on the TFT LCD touchscreen module.
Back of the TFT LCD module showing the J1 solder bridge selection for 5V or 3.3V VCC
J1 solder bridge on the back: open = 5V, closed = 3.3V.

Expected result: All 14 wires are connected between the ESP32 and the TFT display module. Double-check every connection before powering on.

Step 3 - Install the Required Arduino Libraries

Goal: Install the TFT_eSPI and XPT2046_Touchscreen libraries in the Arduino IDE.

What to do: Open the Arduino IDE and go to Sketch > Include Library > Manage Libraries. Search for and install the following two libraries:

1. TFT_eSPI by Bodmer - handles all communication with the TFT display.

Arduino IDE Library Manager showing the TFT_eSPI by Bodmer library ready to install
Installing the TFT_eSPI library by Bodmer.

2. XPT2046_Touchscreen by Paul Stoffregen - handles touchscreen input reading.

Arduino IDE Library Manager showing the XPT2046_Touchscreen by Paul Stoffregen library ready to install
Installing the XPT2046_Touchscreen library by Paul Stoffregen.

Expected result: Both libraries appear as "Installed" in the Library Manager.

Step 4 - Configure the User_Setup.h File

Goal: Replace the default TFT_eSPI configuration file with one that matches the pin wiring.

What to do: The TFT_eSPI library requires a User_Setup.h file with the correct pin definitions. A ready-to-use configuration file is provided in the original Random Nerd Tutorials guide (linked below), so you do not need to edit anything manually.

First, download the User_Setup.h file from Random Nerd Tutorials.

Download link shown for the TFT_eSPI User_Setup.h configuration file used with ESP32 and ILI9341 TFT
Download the pre-configured User_Setup.h file.

Windows steps:

  1. In the Arduino IDE, go to File > Preferences.
  2. Copy the Sketchbook location path shown in the Preferences window.
  3. Open that path in File Explorer and browse to the libraries folder.
  4. Open the TFT_eSPI folder.
  5. Replace the existing User_Setup.h with the downloaded file.
Arduino IDE Preferences menu on Windows used to find the sketchbook location
Open Preferences in the Arduino IDE on Windows.
Arduino IDE Preferences window on Windows showing the sketchbook location path
Copy the Sketchbook location path from Preferences.
Windows File Explorer browsing to the Arduino libraries folder
Browse to the Arduino libraries folder on Windows.
Arduino libraries folder shown in Windows File Explorer
The Arduino libraries folder on Windows.
TFT_eSPI library folder open on Windows showing files including User_Setup.h
Open the TFT_eSPI folder inside your Arduino libraries.
Copying and replacing User_Setup.h in the TFT_eSPI library folder on Windows
Replace User_Setup.h in the TFT_eSPI folder on Windows.

Mac steps:

  1. In the Arduino IDE, go to Arduino IDE > Settings and copy the Sketchbook location path.
  2. Open that path in Finder and navigate to the Arduino folder.
  3. Open the libraries folder.
  4. Open the TFT_eSPI folder.
  5. Copy the downloaded User_Setup.h file into the TFT_eSPI folder, replacing the existing one.
Arduino IDE Settings menu on macOS used to find the sketchbook location
Open Settings in the Arduino IDE on Mac.
Arduino IDE Preferences window on macOS showing the sketchbook location path
Copy the Sketchbook location path on Mac.
macOS Finder showing the Arduino sketchbook folder used to locate libraries
Open the Arduino folder on Mac.
macOS Finder showing the Arduino libraries folder contents
The Arduino libraries folder on Mac.
TFT_eSPI library folder open in Finder on macOS
Open the TFT_eSPI folder on Mac.
macOS Finder copying and replacing User_Setup.h into the TFT_eSPI library folder
Copy User_Setup.h into the TFT_eSPI folder on Mac.
macOS file replacement dialog confirming User_Setup.h overwrite in the TFT_eSPI folder
Confirm the file replacement on Mac.
User_Setup.h file open showing TFT_eSPI pin definitions for ESP32 wiring to ILI9341 display
The User_Setup.h configuration file with pin definitions matching the wiring.

Note: Use the specific User_Setup.h file linked in the original tutorial. Other versions found online may have different pin assignments and will not work with this wiring setup.

Expected result: The User_Setup.h file in your libraries/TFT_eSPI/ folder matches the pin wiring from Step 2.

Step 5 - Upload the Code

Goal: Upload the touchscreen test sketch to the ESP32.

What to do: Copy the code below into the Arduino IDE. Go to Tools > Board and select ESP32 > ESP32 Dev Module. Select the correct COM port under Tools > Port, then click Upload.

Arduino IDE upload button highlighted for flashing code to an ESP32 dev board
Click the Upload button in the Arduino IDE to flash the code.

Code:

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

TFT_eSPI tft = TFT_eSPI();

// Touchscreen pins
#define XPT2046_IRQ 36   // T_IRQ
#define XPT2046_MOSI 32  // T_DIN
#define XPT2046_MISO 39  // T_OUT
#define XPT2046_CLK 25   // T_CLK
#define XPT2046_CS 33    // 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

int x, y, z;

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();
}

void printTouchToDisplay(int touchX, int touchY, int touchZ) {
  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 SPI for the touchscreen and initialize
  touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
  touchscreen.begin(touchscreenSPI);
  touchscreen.setRotation(1);

  // Start the TFT display
  tft.init();
  tft.setRotation(1);

  tft.fillScreen(TFT_WHITE);
  tft.setTextColor(TFT_BLACK, TFT_WHITE);

  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() {
  if (touchscreen.tirqTouched() && touchscreen.touched()) {
    TS_Point p = touchscreen.getPoint();

    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);
  }
}

Expected result: The code compiles and uploads without errors. The TFT display should show "Hello, world!" and "Touch screen to test" on a white background.

ESP32 connected to a 2.8 inch ILI9341 TFT display showing Hello World and Touch screen to test text
The TFT display showing the welcome text after uploading the code.

Step 6 - Test the Touchscreen

Goal: Verify that touch input is working correctly.

What to do: Press the touchscreen with your finger or a stylus. The display should update to show the X and Y coordinates along with the pressure value. Open the Arduino IDE Serial Monitor (baud rate 115200) to see the same data printed there as well.

ESP32 ILI9341 TFT touchscreen showing X and Y coordinates and pressure values after a touch
Touching the screen updates the display with coordinate and pressure data.
Arduino IDE Serial Monitor showing X, Y, and Pressure values from the ESP32 touchscreen
The Serial Monitor also prints the touch coordinates and pressure values.

Expected result: Each time you touch the screen, the X, Y, and Pressure values update on both the display and the Serial Monitor. Note that this is a resistive touchscreen with 240x320 pixel resolution.

Note: If the touchscreen appears to be mirrored or upside down, try changing touchscreen.setRotation(1) to touchscreen.setRotation(3) in the setup() function.

Conclusion

You wired and programmed a 2.8 inch TFT LCD touchscreen display (ILI9341) with an ESP32 using the Arduino IDE. With TFT_eSPI and XPT2046_Touchscreen installed and a matching User_Setup.h configuration, the test sketch displays text and reports touch coordinates and pressure in real time.

Reference credits for the original guide and many of the images used here go to Random Nerd Tutorials.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.