Touch TFT, 2.8 inch ILI9341 with XPT2046
The 2.8 inch TFT with a resistive touch panel on its own SPI bus. Press on the picture to touch it.
- 14 pins
- In 2 projects
The Touch TFT, 2.8 inch ILI9341 with XPT2046 in brief
What it is, and where it sits on the bench.
The red 2.8 inch 240x320 TFT with a resistive touch panel is an ILI9341 display and an XPT2046 touch controller on one board. Both halves are SPI devices. The display takes CS, RST, DC, MOSI, SCK and LED, with MOSI on 11 and SCK on 13 of an Uno; the touch half has T_CLK, T_CS, T_DIN, T_DO and T_IRQ, and most sketches share the bus by wiring T_CLK to SCK, T_DIN to MOSI and T_DO to MISO, with each chip select on a pin of its own. In Mokxi you press on the picture and drag to move. Each reading is a real XPT2046 conversation, a twelve-bit result in bits 14 to 3 of sixteen clocks, with X, Y and the Z1 and Z2 pressure channels worked out from the plate resistances, and T_IRQ low while pressed. The edges read about 200 and 3900 rather than 0 and 4095, so a sketch maps them to pixels, and a rotated display needs its touch readings rotated too. The usual mistakes are T_DO left off MISO, which reads 0, and T_CS left floating. Noise and jitter are not modeled.
- Family
- Displays
- Pins
- 14
14 pins
Named as the editor names them, so a wire lands where you expect it.
How to use an ILI9341 touch screen with an Arduino
The display goes on the hardware SPI pins: MOSI to 11, SCK to 13, CS to 10, DC to 9 and RST to 8, with LED on 5 V. The touch controller here has a bus of its own, T_CLK on A2, T_DIN on A0 and T_DO on A1, built as an SPIClass and handed to ts.begin(), with T_CS on pin 7.
Check ts.touched(), read ts.getPoint(), and map() the raw x and y from about 200 and 3900 to the screen’s width and height. Give the display and the touch the same setRotation(), or the dots land in the wrong place. If every reading is 0, check that T_DO really reaches the pin the touch bus reads from.
What is true about the Touch TFT, 2.8 inch ILI9341 with XPT2046, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The touch controller. Each reading is a real conversation with the XPT2046: a
control byte with its start bit and channel, then sixteen clocks with the twelve-bit
result in bits 14 to 3 (the >> 3 in every driver). X, Y and the two pressure
channels Z1 and Z2 are computed from the resistance of the two plates and of the
contact between them, so the libraries' own pressure sum, 4095 + Z1 - Z2, is large
for a press and near 0 for none. T_IRQ goes low while the panel is pressed, as long
as the last command left the interrupt enabled.
The film is on the glass. Readings come from where your finger is on the glass,
not on the picture. Rotate the display and a sketch has to turn its touch readings the
same way, as on the bench; the X reading runs along the 240-pixel edge and Y along the
320 whatever the rotation. The edges of the picture read about 200 and 3900, not 0 and
4095, because the film is a little bigger than the picture; map() them to pixels.
The display half is the ILI9341 part exactly.
Not modeled
Noise and jitter, which real panels have plenty of, so averaging does nothing here. Conversion time and the busy pin. The temperature, battery and auxiliary inputs, which read 0. The pressure of a press does not change with how hard you click.
From ILI9341 touch TFT, in full.
See the Touch TFT, 2.8 inch ILI9341 with XPT2046 in a project
2 built-in projects use it. Each opens in the editor, already wired.
The boards it is shown on
Each of these 2 boards has a built-in project with the Touch TFT, 2.8 inch ILI9341 with XPT2046 in it.
Arduino libraries for the Touch TFT, 2.8 inch ILI9341 with XPT2046
Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Touch TFT, 2.8 inch ILI9341 with XPT2046
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.