The XPT2046 communicates over SPI and exposes five pins on most TFT breakout modules:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/PaulStoffregen/XPT2046_Touchscreen/llms.txt
Use this file to discover all available pages before exploring further.
T_CLK (clock), T_DIN (MOSI), T_DO (MISO), T_CS (chip select), and T_IRQ (touch interrupt). The first four are required; T_IRQ is optional but enables interrupt-driven touch detection. The SPI data pins are shared with the board’s hardware SPI bus, while T_CS and T_IRQ can be connected to any available digital GPIO.
SPI Pin Mapping by Board
The library uses the hardware SPI peripheral automatically. ConnectT_CLK, T_DIN, and T_DO to the corresponding SPI pins for your board:
| Board | MOSI | MISO | SCK |
|---|---|---|---|
| Arduino Uno / Nano | 11 | 12 | 13 |
| Arduino Mega | 51 | 50 | 52 |
| Teensy 4.x (SPI0) | 11 | 12 | 13 |
| ESP32 (VSPI) | 23 | 19 | 18 |
| ESP8266 | D7 | D6 | D5 |
TFT Module Wiring Table
Most low-cost TFT modules label their touch pins with aT_ prefix. Wire them as follows:
| TFT Module Pin | Function | Connect To |
|---|---|---|
| T_CS | Chip Select | Any GPIO (e.g. D8) |
| T_CLK | SPI Clock | SCK |
| T_DIN | SPI MOSI | MOSI |
| T_DO | SPI MISO | MISO |
| T_IRQ | Touch Interrupt | Any interrupt-capable pin (optional) |
Defining Pins in Your Sketch
The CS pin number is passed directly to theXPT2046_Touchscreen constructor. The TIRQ_PIN argument is optional — pass it only if you have T_IRQ wired up and want interrupt-driven touch detection.
ts.begin() inside setup() to initialise the SPI bus and configure the CS pin as an output:
Sharing SPI with a TFT Display
When a TFT display driver (such as ILI9341) and the XPT2046 touchscreen share the same SPI bus, each device must have its own dedicated CS pin. The library uses Arduino’s
SPI.beginTransaction() / SPI.endTransaction() API, so bus access is correctly arbitrated between devices.