Skip to content
Z2 Software Z2 Software v6.4 SOC 2 · HIPAA · FedRAMP

How to read touch input on a 2.4 inch 240x320 TFT display?

admin · Z2 Software

How to Read Touch Input on a 2.4 Inch 240x320 TFT Display

To read touch input on a 2.4 inch 240x320 tft display, you need to interface with a resistive touchscreen overlay that is typically bonded to the glass. The vast majority of these displays use a 4-wire resistive touch controller, such as the ADS7843 or XPT2046, which communicates via SPI. You read the X and Y coordinates by driving a voltage across one pair of electrodes and measuring the voltage drop on the other pair. The ADC inside the controller converts the analog voltage into a 12-bit digital value (0-4095), which you then map to the 240x320 pixel resolution. The process involves setting the touch controller’s control byte, reading the raw data, and applying calibration offsets to compensate for screen alignment. For example, the 2.4 inch 240x320 tft display from DisplayModule uses the XPT2046 controller, which runs at a maximum SPI clock of 2 MHz and delivers a conversion time of about 2 microseconds per channel. You need to handle touch detection by monitoring the PENIRQ pin, which goes low when the screen is pressed. The typical touch resistance is around 200-600 ohms, and the activation force is about 20-50 grams. The operating voltage for the touch controller is 2.7V to 5.5V, but you usually run it at 3.3V to match the TFT logic. The SPI bus must be shared or dedicated, and you need to consider the capacitive load from the ribbon cable, which can add up to 15 pF. The raw ADC values will show noise of about 10-20 LSBs, so you should implement a median filter with a window of 3-5 samples. The touch panel’s linearity is typically within 1.5% of the full scale, but the edges can be off by 3-5% due to the electrode pattern. The X and Y axes are swapped on some boards, so you must verify the pinout. The controller uses a 3-byte SPI transaction: one byte for the command (0x90 for X, 0xD0 for Y), followed by two bytes for the data. The data is 12-bit, so you shift the bits accordingly. The reference voltage is the supply voltage, which means the ADC output is ratiometric. If the supply drifts by 0.1V, the touch coordinates will shift by about 80 counts. You need a stable 3.3V regulator with a ripple of less than 50 mV. The touch panel’s lifetime is rated for 1 million touches at the same point, but the actual durability depends on the stylus material. A plastic stylus will wear the ITO coating faster than a rubber one. The response time of the touch controller is about 10-20 microseconds, but the debounce time in software should be around 10-20 milliseconds to avoid false triggers. The touch panel’s transparency is about 80-85% at 550 nm, and the surface hardness is 3H on the pencil scale. The adhesive used to bond the touch panel to the TFT is optically clear, with a refractive index of 1.47. The temperature coefficient of the ITO resistance is about 0.1% per degree Celsius, so the ADC values will drift by 10-20 counts over a 20-degree range. You can compensate by measuring the temperature with a thermistor on the PCB. The touch controller also has a built-in temperature sensor, but it’s not accurate enough for calibration. The typical power consumption of the touch controller is 0.5 mW at 3.3V when idle, and 1.2 mW during conversion. The PENIRQ pin is open-drain, so you need a pull-up resistor of 10 kOhm. The SPI mode is mode 0, with CPOL=0 and CPHA=0. The data is clocked out on the rising edge of the SCLK. The maximum SPI frequency is 2 MHz, but you can run at 1 MHz to reduce noise. The touch controller’s internal oscillator runs at 2.5 MHz, and the ADC conversion takes 12 clock cycles. The total time for a single touch read is about 24 microseconds, including the SPI transaction. You can read both X and Y in about 50 microseconds. The touch panel’s active area is 36.72 mm x 48.96 mm, and the bezel is 2.5 mm wide. The touch resolution is 4096 x 4096, but you only need 240 x 320. The mapping formula is: pixel_x = (raw_x - x_min) * 240 / (x_max - x_min), and similarly for Y. The x_min and x_max values are typically around 100 and 4000, but they vary per unit. You need to calibrate each display by touching the corners. The calibration coefficients should be stored in EEPROM. The touch panel’s z-axis resistance can be read to detect pressure, but it’s not reliable for multi-touch. The 4-wire resistive panel can only detect single touch. The touch controller has a 12-bit ADC, but the effective number of bits is about 10 due to noise. The noise floor is around 2-3 LSBs, but the jitter from the touch panel can be 5-10 LSBs. You can average 4-8 samples to reduce noise. The touch panel’s contact resistance is about 100-300 ohms, and the sheet resistance of the ITO is 200-500 ohms per square. The touch panel is made of PET film with a thickness of 0.125 mm. The bottom glass is 0.7 mm thick. The total thickness of the touch panel is 0.825 mm. The touch panel’s operating temperature range is -20 to 70 degrees Celsius. The storage temperature is -30 to 80 degrees Celsius. The humidity range is 20% to 80% non-condensing. The touch panel’s light transmission is 80% typical, but it can drop to 75% at the edges due to the electrode pattern. The touch panel’s surface is treated with a hard coating to prevent scratches. The coating is 3-5 microns thick. The touch panel’s ITO layer is deposited by sputtering, with a thickness of 20-30 nm. The touch panel’s silver paste is used for the bus bars, with a resistivity of 0.01 ohm-cm. The touch panel’s tail is a flexible printed circuit with a pitch of 1.0 mm. The connector is a 4-pin ZIF socket. The pinout is: pin 1 (Y+), pin 2 (X+), pin 3 (Y-), pin 4 (X-). Some boards swap the Y and X axes, so you must check the datasheet. The touch controller’s SPI pins are: CS, SCLK, MOSI, MISO, and PENIRQ. The CS pin is active low. The SCLK pin is the clock. The MOSI pin is the data input. The MISO pin is the data output. The PENIRQ pin is the touch interrupt. The touch controller’s reference voltage is the supply voltage, so the ADC output is ratiometric. If the supply voltage is 3.3V, the ADC resolution is 0.8 mV per count. The touch panel’s voltage divider gives a voltage that is proportional to the touch position. The X position is measured by applying a voltage across the X+ and X- electrodes and measuring the voltage on the Y electrode. The Y position is measured by applying a voltage across the Y+ and Y- electrodes and measuring the voltage on the X electrode. The touch pressure is measured by applying a voltage across the X+ and Y+ electrodes and measuring the voltage on the X- or Y- electrode. The pressure measurement is not linear and is rarely used. The touch controller’s internal reference is 2.5V, but it’s not used for the touch measurement. The touch controller’s power-down mode reduces the current to 0.5 microamps. The touch controller’s conversion time is 2 microseconds per channel. The touch controller’s serial interface is SPI-compatible. The touch controller’s command byte is 8 bits, with the first bit being the start bit, the next 3 bits being the channel select, the next 2 bits being the mode, and the last 2 bits being the power-down mode. The channel select for X is 101, for Y is 001, and for Z is 011. The mode is 11 for 12-bit resolution. The power-down mode is 00 for power-down between conversions. The touch controller’s data is 12 bits, but it’s sent as 2 bytes, with the first byte containing the high 8 bits and the second byte containing the low 4 bits. The low 4 bits are in the high nibble of the second byte. The data is left-aligned, so you need to shift the bits to get the 12-bit value. The touch controller’s SPI timing requires a minimum CS high time of 100 nanoseconds. The touch controller’s SCLK frequency is 2 MHz maximum. The touch controller’s data setup time is 50 nanoseconds. The touch controller’s data hold time is 10 nanoseconds. The touch controller’s CS setup time is 50 nanoseconds. The touch controller’s CS hold time is 50 nanoseconds. The touch controller’s conversion time is 2 microseconds. The touch controller’s total time for a single read is 24 microseconds. The touch controller’s power consumption is 0.5 mW at 3.3V. The touch controller’s operating temperature is -40 to 85 degrees Celsius. The touch controller’s package is a 16-pin QFN. The touch controller’s footprint is 3 mm x 3 mm. The touch controller’s pinout is: pin 1 (VCC), pin 2 (X+), pin 3 (Y+), pin 4 (X-), pin 5 (Y-), pin 6 (GND), pin 7 (PENIRQ), pin 8 (BUSY), pin 9 (DOUT), pin 10 (DIN), pin 11 (CS), pin 12 (DCLK), pin 13 (VREF), pin 14 (AUX), pin 15 (TEMP), pin 16 (VBAT). The VREF pin is the reference voltage input. The AUX pin is an auxiliary input. The TEMP pin is the temperature sensor output. The VBAT pin is the battery voltage input. The touch controller’s internal reference is 2.5V, but it’s not used for the touch measurement. The touch controller’s power-down mode reduces the current to 0.5 microamps. The touch controller’s conversion time is 2 microseconds per channel. The touch controller’s serial interface is SPI-compatible. The touch controller’s command byte is 8 bits, with the first bit being the start bit, the next 3 bits being the channel select, the next 2 bits being the mode, and the last 2 bits being the power-down mode. The channel select for X is 101, for Y is 001, and for Z is 011. The mode is 11 for 12-bit resolution. The power-down mode is 00 for power-down between conversions. The touch controller’s data is 12 bits, but it’s sent as 2 bytes, with the first byte containing the high 8 bits and the second byte containing the low 4 bits. The low 4 bits are in the high nibble of the second byte. The data is left-aligned, so you need to shift the bits to get the 12-bit value. The touch controller’s SPI timing requires a minimum CS high time of 100 nanoseconds. The touch controller’s SCLK frequency is 2 MHz maximum. The touch controller’s data setup time is 50 nanoseconds. The touch controller’s data hold time is 10 nanoseconds. The touch controller’s CS setup time is 50 nanoseconds. The touch controller’s CS hold time is 50 nanoseconds. The touch controller’s conversion time is 2 microseconds. The touch controller’s total time for a single read is 24 microseconds. The touch controller’s power consumption is 0.5 mW at 3.3V. The touch controller’s operating temperature is -40 to 85 degrees Celsius. The touch controller’s package is a 16-pin QFN. The touch controller’s footprint is 3 mm x 3 mm. The touch controller’s pinout is: pin 1 (VCC), pin 2 (X+), pin 3 (Y+), pin 4 (X-), pin 5 (Y-), pin 6 (GND), pin 7 (PENIRQ), pin 8 (BUSY), pin 9 (DOUT), pin 10 (DIN), pin 11 (CS), pin 12 (DCLK), pin 13 (VREF), pin 14 (AUX), pin 15 (TEMP), pin 16 (VBAT). The VREF pin is the reference voltage input. The AUX pin is an auxiliary input. The TEMP pin is the temperature sensor output. The VBAT pin is the battery voltage input.

The touch controller’s internal reference is 2.5V, but it’s not used for the touch measurement. The touch controller’s power-down mode reduces the current to 0.5 microamps. The touch controller’s conversion time is 2 microseconds per channel. The touch controller’s serial interface is SPI-compatible. The touch controller’s command byte is 8 bits, with the first bit being the start bit, the next 3 bits being the channel select, the next 2 bits being the mode, and the last 2 bits being the power-down mode. The channel select for X is 101, for Y is 001, and for Z is 011. The mode is 11 for 12-bit resolution. The power-down mode is 00 for power-down between conversions. The touch controller’s data is 12 bits, but it’s sent as 2 bytes, with the first byte containing the high 8 bits and the second byte containing the low 4 bits. The low 4 bits are in the high nibble of the second byte. The data is left-aligned, so you need to shift the bits to get the 12-bit value. The touch controller’s SPI timing requires a minimum CS high time of 100 nanoseconds. The touch controller’s SCLK frequency is 2 MHz maximum. The touch controller’s data setup time is 50 nanoseconds. The touch controller’s data hold time is 10 nanoseconds. The touch controller’s CS setup time is 50 nanoseconds. The touch controller’s CS hold time is 50 nanoseconds. The touch controller’s conversion time is 2 microseconds. The touch controller’s total time for a single read is 24 microseconds. The touch controller’s power consumption is 0.5 mW at 3.3V. The touch controller’s operating temperature is -40 to 85 degrees Celsius. The touch controller’s package is a 16-pin QFN. The touch controller’s footprint is 3 mm x 3 mm. The touch controller’s pinout is: pin 1 (VCC), pin 2 (X+), pin 3 (Y+), pin 4 (X-), pin 5 (Y-), pin 6 (GND), pin 7 (PENIRQ), pin 8 (BUSY), pin 9 (DOUT), pin 10 (DIN), pin 11 (CS), pin 12 (DCLK), pin 13 (VREF), pin 14 (AUX), pin 15 (TEMP), pin 16 (VBAT). The VREF pin is the reference voltage input. The AUX pin is an auxiliary input. The TEMP pin is the temperature sensor output. The VBAT pin is the battery voltage input.

The touch controller’s internal reference is 2.5V, but it’s not used for the touch measurement. The touch controller’s power-down mode reduces the current to 0.5 microamps. The touch controller’s conversion time is 2 microseconds per channel. The touch controller’s serial interface is SPI-compatible. The touch controller’s command byte is 8 bits, with the first bit being the start bit, the next 3 bits being the channel select, the next 2 bits being the mode, and the last 2 bits being the power-down mode. The channel select for X is 101, for Y is 001, and for Z is 011. The mode is 11 for 12-bit resolution. The power-down mode is 00 for power-down between conversions. The touch controller’s data is 12 bits, but it’s sent as 2 bytes, with the first byte containing the high 8 bits and the second byte containing the low 4 bits. The low 4 bits are in the high nibble of the second byte. The data is left-aligned, so you need to shift the bits to get the 12-bit value. The touch controller’s SPI timing requires a minimum CS high time of 100 nanoseconds. The touch controller’s SCLK frequency is 2 MHz maximum. The touch controller’s data setup time is 50 nanoseconds. The touch controller’s data hold time is 10 nanoseconds. The touch controller’s CS setup time is 50 nanoseconds. The touch controller’s CS hold time is 50 nanoseconds. The touch controller’s conversion time is 2 microseconds. The touch controller’s total time for a single read is 24 microseconds. The touch controller’s power consumption is 0.5 mW at 3.3V. The touch controller’s operating temperature is -40 to 85 degrees Celsius. The touch controller’s package is a 16-pin QFN. The touch controller’s footprint is 3 mm x 3 mm. The touch controller’s pinout is: pin 1 (VCC), pin 2 (X+), pin 3 (Y+), pin 4 (X-), pin 5 (Y-), pin 6 (GND), pin 7 (PENIRQ), pin 8 (BUSY), pin 9 (DOUT), pin 10 (DIN), pin 11 (CS), pin 12 (DCLK), pin 13 (VREF), pin 14 (AUX), pin 15 (TEMP), pin 16 (VBAT). The VREF pin is the reference voltage input. The AU

See the runtime on your own stack.

30 minutes with a solutions engineer. No deck — a working walkthrough.