What is the ILI9341 2.8" TFT?
The 2.8" ILI9341 TFT is the step up from small OLEDs: a 320 × 240 colour screen big enough for a real user interface, with a resistive touch panel on top and usually a microSD slot on the back, all for a few dollars. It talks over SPI, so it needs only a handful of pins, and the ILI9341 driver chip holds the whole image in its own memory, so your microcontroller only sends what changes.
The common red module is a 3.3 V logic device. That one fact decides how you wire it: an ESP32 connects directly, while a 5 V Arduino Uno needs level shifting on its outputs. This page explains the pinout, the voltage question, the three devices that share its SPI bus (display, touch, SD card), speed and memory limits, and which library to use. For code, see the Arduino Uno guide and the ESP32 guide.
Specifications
- Display
- 2.8" TFT, 320 × 240 pixels (QVGA), transmissive
- Driver chip
- ILI9341 with 172,800 bytes of built-in frame memory
- Colour
- 16-bit RGB565 (65,536 colours) over SPI; the chip also supports 18-bit
- Interface
- 4-wire SPI: SCK, MOSI, MISO (optional), CS, plus DC and RESET
- SPI clock
- 10 MHz in the datasheet; 27 to 40 MHz works on most modules in practice
- Touch
- 4-wire resistive panel, XPT2046 12-bit controller on SPI (2.5 MHz clock maximum)
- Storage
- microSD slot on its own 4-pin header (SPI)
- Module supply
- 5 V or 3.3 V on VCC: onboard 3.3 V regulator; short J1 to bypass it at 3.3 V
- Logic level
- 3.3 V. The common red module has no level shifter
- Current
- About 0.31 W (LCDwiki MSP2807 spec), roughly 60 mA at 5 V
- Backlight
- LED pin, active HIGH: tie it to 3.3 V for always on
- Active area
- 43.2 × 57.6 mm; module about 50 × 86 mm
Figures for the common red 2.8" SPI module (often marked TJCTM24028-SPI) and the ILI9341 / XPT2046 datasheets. Branded breakouts, such as Adafruit's, add level shifting and may use other pin names.
Pinout (14-pin header)
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Module power, 5 V or 3.3 V (see J1) |
| 2 | GND | Ground |
| 3 | CS | Display chip select, active LOW |
| 4 | RESET | Display reset, active LOW. Can be tied to 3.3 V if you are short of pins |
| 5 | DC / RS | Data / command select: LOW = command, HIGH = pixel data |
| 6 | SDI (MOSI) | SPI data into the display |
| 7 | SCK | SPI clock |
| 8 | LED | Backlight. 3.3 V for always on, or a GPIO / PWM pin for on-off and dimming |
| 9 | SDO (MISO) | SPI data out of the display. Only needed to read back from it; leave it off if it upsets other SPI devices |
| 10 | T_CLK | Touch SPI clock: join to SCK |
| 11 | T_CS | Touch chip select, active LOW |
| 12 | T_DIN | Touch data in: join to MOSI |
| 13 | T_DO | Touch data out: join to MISO |
| 14 | T_IRQ | Goes LOW while the screen is touched (optional) |
The separate 4-pin header on the other edge is the SD card: SD_CS, SD_MOSI, SD_MISO, SD_SCK.
Wiring & code
Setting up ILI9341 2.8" TFT with ESP32
Library
TFT_eSPI by Bodmer
Library Manager: install "TFT_eSPI", then edit User_Setup.h in the library folder (ILI9341_DRIVER and your pins), as described in the guide
On an ESP32 the 2.8" ILI9341 is a different experience from the Uno: 3.3 V logic means direct wiring, a 40 MHz SPI clock makes full-screen updates almost instant, and the TFT_eSPI library adds built-in touch calibration and sprites for flicker-free graphics. This guide covers TFT_eSPI's one-time setup step by step, a speed test, touch buttons that switch a GPIO, and a smooth sprite-based gauge. Pinout and background are on the ILI9341 overview.
What you need
1ESP32 DevKit (30- or 38-pin)
- Notes
- ESP32-S3 works too with different pin numbers
12.8" ILI9341 SPI TFT with touch
- Notes
- The common red module
1Jumper wires
- Notes
- Female-to-female if you plug straight onto both headers; keep them short
Wiring: ILI9341 to ESP32 (VSPI)
| Display pin | ESP32 pin | Notes |
|---|---|---|
| VCC | 3V3 or 5V (VIN) | 5V gives the regulator headroom; J1 stays open |
| GND | GND | |
| CS | GPIO15 | TFT_eSPI default |
| RESET | GPIO4 | |
| DC / RS | GPIO2 | A strapping pin, but safe here because the display does not pull it at boot |
| SDI (MOSI) | GPIO23 | VSPI MOSI |
| SCK | GPIO18 | VSPI SCK |
| LED | 3V3 | Or GPIO 32 for software on/off |
| SDO (MISO) | GPIO19 | VSPI MISO; needed for touch |
| T_CLK | GPIO18 | Shared with SCK |
| T_CS | GPIO21 | Touch chip select |
| T_DIN | GPIO23 | Shared with MOSI |
| T_DO | GPIO19 | Shared with MISO |
| T_IRQ | Not connected | TFT_eSPI polls the touch controller |
Set up TFT_eSPI (once)
TFT_eSPI is fast because the display type and pins are fixed at compile time, in a setup file inside the library folder rather than in your sketch. This is the step people skip, and the cause of most "white screen with TFT_eSPI" posts.
- 1Install "TFT_eSPI" by Bodmer from the Library Manager.
- 2Open the library folder: Documents/Arduino/libraries/TFT_eSPI.
- 3Open User_Setup.h in a text editor. Make sure only one driver line is active: #define ILI9341_DRIVER.
- 4Further down, set the ESP32 pins to match the table: TFT_MISO 19, TFT_MOSI 23, TFT_SCLK 18, TFT_CS 15, TFT_DC 2, TFT_RST 4, and TOUCH_CS 21. Comment out any other pin block.
- 5Leave the font lines (LOAD_GLCD, LOAD_FONT2 to LOAD_FONT8, SMOOTH_FONT) enabled. The sketches below use fonts 2, 4 and 7, and a disabled font simply draws nothing.
- 6Set #define SPI_FREQUENCY 40000000 (drop to 27000000 if the image is unstable) and keep SPI_TOUCH_FREQUENCY 2500000.
- 7Save. Library updates overwrite User_Setup.h, so keep a copy of your edited file.
// The lines that matter in TFT_eSPI/User_Setup.h for this wiring
#define ILI9341_DRIVER
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
#define TOUCH_CS 21
#define LOAD_GLCD // font 1: 8 px
#define LOAD_FONT2 // 16 px
#define LOAD_FONT4 // 26 px
#define LOAD_FONT6 // large digits
#define LOAD_FONT7 // 7-segment digits (Sketch 3)
#define LOAD_FONT8 // very large digits
#define SMOOTH_FONT
#define SPI_FREQUENCY 40000000
#define SPI_TOUCH_FREQUENCY 2500000Sketch 1 - Hello and speed test
Draws text in two fonts, then times ten full-screen fills so you can see what 40 MHz SPI buys you. Expect around 30 ms per fill, against 200 to 300 ms on an Uno.
#include <TFT_eSPI.h>
TFT_eSPI tft; // pins and driver come from User_Setup.h
void setup() {
Serial.begin(115200);
tft.init();
tft.setRotation(1); // landscape, 320 x 240
uint32_t t0 = millis();
const uint16_t colours[] = {TFT_RED, TFT_GREEN, TFT_BLUE, TFT_YELLOW, TFT_BLACK};
for (int i = 0; i < 10; i++) tft.fillScreen(colours[i % 5]);
uint32_t perFill = (millis() - t0) / 10;
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("SolderHub", 10, 10, 4); // font 4: 26 px high
tft.drawString("ILI9341 + ESP32 + TFT_eSPI", 10, 50, 2);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawString("Full-screen fill: " + String(perFill) + " ms", 10, 90, 4);
Serial.printf("Full-screen fill: %lu ms\n", perFill);
}
void loop() {}Sketch 2 - Touch buttons with saved calibration
TFT_eSPI has touch built in when TOUCH_CS is set. The first time it runs, the sketch asks you to tap four arrows in the corners and stores the result in the ESP32's flash (via the Preferences library), so later boots skip straight to the buttons. Two buttons switch an LED on GPIO27; getTouch() returns pixel coordinates already mapped to the screen.
#include <TFT_eSPI.h>
#include <Preferences.h>
TFT_eSPI tft;
Preferences prefs;
const int LED_PIN = 27; // an LED + 220 ohm resistor to GND (GPIO2 is busy as DC)
void calibrate() {
uint16_t cal[5];
prefs.begin("touch", false);
if (prefs.getBytes("cal", cal, sizeof(cal)) == sizeof(cal)) {
tft.setTouch(cal); // reuse saved values
} else {
tft.fillScreen(TFT_BLACK);
tft.drawCentreString("Touch the arrow in each corner", 160, 100, 2);
tft.calibrateTouch(cal, TFT_MAGENTA, TFT_BLACK, 15); // interactive
prefs.putBytes("cal", cal, sizeof(cal));
}
prefs.end();
}
void drawButton(int x, const char *label, uint16_t colour) {
tft.fillRoundRect(x, 140, 130, 70, 10, colour);
tft.setTextColor(TFT_WHITE, colour);
tft.drawCentreString(label, x + 65, 165, 4);
}
void setup() {
pinMode(LED_PIN, OUTPUT);
tft.init();
tft.setRotation(1);
calibrate();
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("LED control", 20, 40, 4);
drawButton(20, "ON", TFT_DARKGREEN);
drawButton(170, "OFF", TFT_MAROON);
}
void loop() {
uint16_t x, y;
if (!tft.getTouch(&x, &y)) return; // false when not pressed
if (y > 140 && y < 210) {
bool on = x < 160;
digitalWrite(LED_PIN, on ? HIGH : LOW);
tft.setTextColor(on ? TFT_GREEN : TFT_RED, TFT_BLACK);
tft.drawString(on ? "LED is ON " : "LED is OFF", 20, 90, 4);
delay(200); // simple debounce
}
}Tip
Why not the onboard LED? On most DevKits it is on GPIO2, which this wiring uses for the display's DC line, so it would flicker with every frame. Wire an LED and 220 Ω resistor from GPIO27 to GND instead. To redo the calibration later, call prefs.clear() once inside prefs.begin("touch"), or change the key name.
Sketch 3 - Flicker-free gauge with a sprite
A sprite is an off-screen image in RAM. You draw the whole gauge into it (background, arc, needle, number) and push it to the display in one fast transfer, so the viewer never sees a half-drawn frame. A 200 × 200 sprite at 16-bit colour needs 80 KB, easy for an ESP32; a full-screen 320 × 240 sprite (150 KB) often fails to allocate without PSRAM, which is why you draw just the part that animates.
#include <TFT_eSPI.h>
TFT_eSPI tft;
TFT_eSprite gauge(&tft); // off-screen buffer
const int SIZE = 200;
void setup() {
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.drawString("ADC on GPIO34", 10, 10, 2);
if (!gauge.createSprite(SIZE, SIZE)) { // 200 x 200 x 2 bytes = 80 KB
tft.drawString("Not enough RAM for sprite", 10, 40, 2);
while (true) delay(1000);
}
}
void drawGauge(int percent) {
gauge.fillSprite(TFT_BLACK);
int c = SIZE / 2;
// Background track and value arc, 0-100 % mapped to 30-330 degrees
gauge.drawSmoothArc(c, c, 90, 75, 30, 330, TFT_DARKGREY, TFT_BLACK);
int end = 30 + percent * 3;
if (percent > 0)
gauge.drawSmoothArc(c, c, 90, 75, 30, end, percent > 80 ? TFT_RED : TFT_GREEN, TFT_BLACK);
gauge.setTextColor(TFT_WHITE, TFT_BLACK);
gauge.setTextDatum(MC_DATUM); // centre the text on (x, y)
gauge.drawNumber(percent, c, c - 8, 7); // font 7: 7-segment style
gauge.drawString("%", c, c + 40, 4);
gauge.pushSprite(60, 30); // one transfer, no flicker
}
void loop() {
int percent = map(analogRead(34), 0, 4095, 0, 100); // a potentiometer on GPIO34
drawGauge(percent);
delay(30);
}Why this matters. The same pattern (draw into a sprite, push once) builds clocks, graphs and dashboards that update 30 or more times a second without tearing. drawSmoothArc needs TFT_eSPI 2.5 or newer. Feed the gauge from a real sensor, such as current from an INA219, instead of a potentiometer.
Troubleshooting on the ESP32
White screen with TFT_eSPI
- Likely cause
- User_Setup.h still has another driver or pin block active
- Fix
- Leave only ILI9341_DRIVER and the pin defines above active
Worked, then white after a library update
- Likely cause
- The update replaced User_Setup.h
- Fix
- Restore your saved copy, or use a custom setup file outside the library
Garbled image
- Likely cause
- 40 MHz too fast for long jumper wires
- Fix
- Set SPI_FREQUENCY to 27000000 or shorten the wires
getTouch() always false
- Likely cause
- TOUCH_CS not defined, or T_DO not on MISO (GPIO19)
- Fix
- Define TOUCH_CS 21 in User_Setup.h and wire T_DO to GPIO19
Touch offset after changing rotation
- Likely cause
- Calibration stored for another rotation
- Fix
- Clear the saved calibration and run it again
createSprite() fails
- Likely cause
- Not enough contiguous RAM
- Fix
- Use a smaller sprite or 8-bit colour: gauge.setColorDepth(8)
ESP32 FAQ
Can I use Adafruit_ILI9341 on the ESP32 instead?
Yes, with the same pins passed in the constructor: Adafruit_ILI9341 tft(15, 2, 4);. It is slower than TFT_eSPI but needs no setup file, which helps if you share code between boards.
Will Wi-Fi slow the display down? A little. Wi-Fi runs on the ESP32's other core and the display has its own SPI peripheral, so drawing keeps going while a web server or MQTT client works. Expect an occasional dropped frame in animations, not a slow screen.
Which pins should I avoid? GPIO6 to 11 (flash) and the input-only GPIO34 to 39 for any output such as CS, DC or RST. GPIO2 and GPIO15 are strapping pins but work for DC and CS on this module. The ESP32 SPI pins guide explains VSPI, HSPI and how to remap them.
Can I use the SD card at the same time?
Yes. Wire SD_CS to a free GPIO such as 5, join SD_MOSI, SD_MISO and SD_SCK to GPIO23, 19 and 18, and call SD.begin(5). TFT_eSPI and the SD library share the bus as long as each device has its own CS.
Where next? Compare with the ILI9341 Arduino Uno guide, or put live sensor data on screen with the INA219 power meter.








