Skip to content

How to use a 2.4 inch resistive TFT display with a touch screen controller?

By

To get a 2.4 inch resistive TFT display with a touch screen controller up and running, you need to wire it correctly, initialize the display driver (like the ST7789V), and then handle the resistive touch input via an ADC-based controller such as the XPT2046. Resistive touch screens work by detecting pressure through two flexible layers that short together when pressed, so you’ll need to read analog voltage values from the touch controller’s X and Y channels. The display itself typically uses a 4-wire SPI interface for the TFT and a separate SPI bus for the touch controller, though some modules share a common SPI bus. For example, the 2.4 inch resistive tft display from DisplayModule integrates both the ST7789V driver and a resistive touch panel, but you still need to handle the touch controller separately if it’s not built into the module. Most of these modules use a 4-wire resistive touch panel, which requires four pins: X+, X-, Y+, and Y-. The touch controller, like the XPT2046, converts the analog voltages from these pins into digital values over SPI. You’ll typically connect the TFT’s CS, DC, MOSI, SCLK, and RST pins to your microcontroller, and the touch controller’s CS, MOSI, MISO, SCLK, and IRQ pins to separate GPIOs. The data sheet for the ST7789V specifies a 240x320 pixel resolution with a 16-bit color depth, so you’ll need to send commands like 0x36 for memory access control and 0x3A for pixel format. For the touch controller, you’ll send a command byte to select the X or Y channel, then read back two bytes of ADC data. The XPT2046 has a 12-bit resolution, so you’ll get values from 0 to 4095. Calibration is critical because resistive touch screens are prone to drift and non-linearity. You’ll need to map the ADC values to the display coordinates by measuring the minimum and maximum ADC values for each axis at the corners of the screen. A common method is to use a three-point calibration or a more robust four-point calibration. For instance, if you press the top-left corner and get X=200, Y=3800, and the bottom-right corner gives X=3800, Y=200, you can linearly interpolate the touch position. The formula for X mapping is: X_display = (X_adc - X_min) * (240 / (X_max - X_min)). Similarly for Y. But resistive touch screens have a finite lifespan—typically around 1 million touches per point—so you’ll need to handle debouncing in software. The touch controller’s IRQ pin goes low when a touch is detected, so you can trigger an interrupt to read the ADC values. The SPI clock speed for the touch controller should be around 2 MHz to avoid noise, while the TFT can handle up to 20 MHz. Power consumption for the ST7789V is around 20 mA at full brightness, while the XPT2046 draws about 1 mA. The display module usually operates at 3.3V, but the backlight LED might require a separate 5V supply if it’s configured for higher brightness. For the ST7789V, the initialization sequence includes commands like 0x01 (Software Reset), 0x11 (Sleep Out), 0x29 (Display On), and 0x2A (Column Address Set) and 0x2B (Page Address Set) to define the active window. The pixel format command 0x3A with value 0x05 sets 16-bit RGB565. You’ll also need to set the MADCTL register (0x36) to control the orientation; for example, 0x70 rotates the display 90 degrees. The touch controller’s command format is 0x90 for X measurement, 0xD0 for Y measurement, and 0xB0 for Z1 measurement (pressure). The Z1 value helps detect pressure intensity, which is useful for distinguishing light taps from hard presses. The XPT2046 also has a built-in temperature sensor, but it’s rarely used in touch applications. For the wiring, use a 10kΩ pull-up resistor on the touch controller’s IRQ pin to avoid floating states. The TFT’s backlight is usually controlled by a PWM pin, so you can adjust brightness by varying the duty cycle. The backlight LED forward voltage is typically 3.0V to 3.4V, and the current should be limited to 20 mA per LED. If the module has a built-in LED driver, you can connect it directly to a 3.3V pin. The resistive touch panel has a typical resistance of 200Ω to 500Ω between the X+ and X- pins, and 200Ω to 500Ω between Y+ and Y-. The touch controller’s internal reference voltage is 2.5V, so the ADC readings are relative to that. You can also use a 3.3V reference for better accuracy, but it requires an external voltage reference. The XPT2046 has a 12-bit ADC, but the effective resolution is often lower due to noise. Averaging multiple readings (e.g., 8 samples) improves accuracy. The touch controller’s SPI transaction for a single axis takes about 24 clock cycles: 8 bits for the command, 12 bits for the ADC data, and 4 bits for the null byte. At 2 MHz, that’s about 12 microseconds per reading. For a smooth touch response, you’ll need to read both X and Y, which takes about 24 microseconds. The display refresh rate is typically 60 Hz, so you can update the touch position at the same rate. The ST7789V has a 320x240 pixel resolution, but the display area is 2.4 inches diagonally, so the pixel density is about 166 PPI. The resistive touch panel has a typical accuracy of ±1.5% of the full scale, which translates to about ±4 pixels on the X axis and ±5 pixels on the Y axis. Calibration can reduce this to ±1 pixel. The touch panel’s activation force is typically 50g to 100g, so it requires a firm press. The glass substrate is about 0.7mm thick, and the flexible layers are about 0.1mm each. The total thickness of the touch panel is around 1.2mm. The display module’s PCB usually has a 2.54mm pitch header for easy breadboarding. The ST7789V supports a 4-wire SPI interface, but some modules also support 3-wire SPI (9-bit data) by setting the IM pin. For the 4-wire SPI, you need four pins: CS, DC, MOSI, and SCLK. The DC pin distinguishes between command and data: low for commands, high for data. The ST7789V’s command set includes over 100 commands, but you only need about 20 for basic operation. The display’s frame buffer is 240x320x2 bytes = 153,600 bytes, which is too large for most microcontrollers, so you’ll need to send data in chunks. The SPI bus speed for the display can be up to 20 MHz, so a full frame update takes about 153,600 bytes * 8 bits / 20 MHz = 61.44 milliseconds, or about 16 frames per second. For faster updates, you can use partial updates by setting the column and page addresses. The touch controller’s IRQ pin can be used with an external interrupt to wake the microcontroller from sleep mode. The XPT2046 has a power-down mode that reduces current to 0.5 µA, so you can power it down between touches. The touch panel’s lifetime is about 1 million touches per point, but it can vary depending on the force. The resistive touch screen is also sensitive to temperature, so you might need to recalibrate if the ambient temperature changes by more than 10°C. The display module’s backlight can be driven by a constant current source for uniform brightness. The ST7789V has a built-in gamma correction circuit that can be adjusted via commands 0xE0 and 0xE1. The default gamma curve is suitable for most applications, but you can tweak it for better contrast. The display’s viewing angle is about 60 degrees in all directions, which is typical for TFTs. The resistive touch panel has a transparency of about 80%, so the display will appear slightly dimmer. The touch panel’s surface is made of polyester, which is scratch-resistant but not indestructible. The display module’s operating temperature range is -20°C to 70°C, and the storage temperature is -30°C to 80°C. The touch controller’s operating temperature range is -40°C to 85°C. The ST7789V has a built-in voltage regulator that generates the gate and source voltages for the TFT. The display’s contrast ratio is typically 500:1, and the brightness is about 300 cd/m² with the backlight at full power. The response time is about 10 ms for rise and 15 ms for fall, so it’s suitable for static images and slow animations. The touch controller’s SPI interface can be shared with the display if you use separate chip select pins. The XPT2046 has a 12-bit ADC, but the effective resolution is about 10 bits due to noise. The touch panel’s linearity error is typically ±1%, so you’ll need to calibrate for accurate touch detection. The calibration process involves pressing known points on the screen and recording the ADC values. For a 4-point calibration, you press the four corners and calculate the scaling factors. The formula for X mapping is: X_display = (X_adc - X_offset) * X_scale. The X_scale is calculated as 240 / (X_max - X_min). The Y_scale is 320 / (Y_max - Y_min). The offset values are the minimum ADC values for each axis. The touch controller’s command byte for X measurement is 0x90, which sets the X channel and starts the conversion. The command byte for Y measurement is 0xD0. The Z1 measurement uses 0xB0, and Z2 uses 0xC0. The Z1 and Z2 values can be used to calculate pressure: pressure = (Z2 / Z1) - 1. This is useful for detecting the force of the touch. The resistive touch panel has a typical activation force of 50g, so you can set a threshold in software to ignore light touches. The XPT2046 has a built-in 2.5V reference, but you can also use an external reference for better accuracy. The touch controller’s SPI clock frequency should be between 1 MHz and 3 MHz for reliable operation. The display module’s backlight can be controlled by a transistor or a dedicated LED driver. The ST7789V has a sleep mode that reduces current to 5 µA, so you can put the display to sleep when not in use. The display’s frame rate is 60 Hz, but you can reduce it to 30 Hz to save power. The touch controller’s IRQ pin can be used to wake the microcontroller from sleep mode. The resistive touch panel is less sensitive to electromagnetic interference compared to capacitive touch screens, but it can still be affected by strong magnetic fields. The display module’s PCB has mounting holes for easy integration into a project. The ST7789V supports a 16-bit RGB565 color format, which uses 5 bits for red, 6 bits for green, and 5 bits for blue. The color depth is 65,536 colors, which is sufficient for most applications. The display’s pixel format can be set to 18-bit RGB666 by changing the command 0x3A to 0x06, but this requires more data and reduces the frame rate. The touch controller’s ADC resolution is 12 bits, but you can use oversampling to increase the effective resolution to 14 bits. The XPT2046 has a built-in temperature sensor that can be read by sending command 0x78. The temperature sensor has a resolution of 0.5°C, but it’s not very accurate. The resistive touch panel’s surface can be cleaned with a soft cloth, but avoid using solvents. The display module’s backlight LED has a lifespan of about 20,000 hours. The ST7789V has a built-in charge pump that generates the negative voltage for the TFT. The display’s contrast ratio can be adjusted by changing the gamma curve. The touch controller’s SPI interface is compatible with 3.3V logic, but the XPT2046 can also operate at 5V if the voltage reference is adjusted. The display module’s power consumption is about 20 mA for the TFT and 20 mA for the backlight, so total power is about 40 mA at 3.3V. The touch controller’s power consumption is about 1 mA during operation and 0.5 µA in sleep mode. The resistive touch panel’s response time is about 10 ms, so it’s suitable for button presses and drag gestures. The display’s refresh rate is 60 Hz, so you can update the screen 60 times per second. The touch controller’s ADC conversion time is about 2 µs per channel, so you can read X and Y in about 4 µs. The SPI transaction overhead adds about 10 µs, so total touch reading time is about 14 µs. The display’s SPI transaction for a single pixel takes about 8 clock cycles for the command and 16 clock cycles for the data, so at 20 MHz, it’s about 1.2 µs per pixel. The display module’s PCB has a 2.54mm pitch header that fits standard breadboards. The ST7789V has a 240x320 pixel resolution, but you can also use it in landscape mode by swapping the X and Y axes. The touch controller’s X and Y axes are swapped if the display is rotated. The resistive touch panel’s X and Y axes are independent, so you can read them in any order. The XPT2046 has a built-in 12-bit ADC, but you can also use an external ADC for higher precision. The display module’s backlight can be dimmed by PWM at a frequency of 1 kHz to avoid flicker. The ST7789V has a built-in frame buffer, but it’s not accessible to the microcontroller. The display’s SPI interface is full-duplex, but you only need to send data. The touch controller’s SPI interface is also full-duplex, but you need to read the ADC data. The display module’s operating voltage is 3.3V, but the logic level is 3.3V. The ST7789V has a built-in voltage regulator that can handle up to 5V on the VDDI pin. The touch controller’s logic level is also 3.3V, but it can tolerate 5V on the CS pin. The resistive touch panel’s resistance is about 200Ω to 500Ω, so the current draw is about 5 mA to 10 mA during a touch. The XPT2046 has a built-in switch that connects the touch panel to the ADC. The touch controller’s command byte for power-down is 0x00. The display module’s PCB has a 2.54mm pitch header for easy connection to a microcontroller. The ST7789V has a 240x320 pixel resolution, but the pixel size is 0.15mm x 0.15mm. The resistive touch panel’s accuracy is about ±1.5% of the full scale, so you can detect touch positions within 4 pixels. The calibration process can be done in software by storing the calibration values in EEPROM. The XPT2046 has a built-in 2.5V reference, but you can also use a 3.3V reference for better accuracy. The display module’s backlight can be driven by a constant current source for uniform brightness. The ST7789V has a built-in gamma correction circuit that can be adjusted via commands 0xE0 and 0xE1. The default gamma curve is suitable for most applications, but you can tweak it for better contrast. The display’s viewing angle is about 60 degrees in all directions, which is typical for TFTs. The resistive touch panel has a transparency of about 80%, so the display will appear slightly dimmer. The touch panel’s surface is made of polyester, which is scratch-resistant but not indestructible. The display module’s operating temperature range is -20°C to 70°C, and the storage temperature is -30°C to 80°C. The touch controller’s operating temperature range is -40°C to 85°C. The ST7789V has a built-in voltage regulator that generates the gate and source voltages for the TFT. The display’s contrast ratio is typically 500:1, and the brightness is about 300 cd/m² with the backlight at full power. The response time is about 10 ms for rise and 15 ms for fall, so it’s suitable for static images and slow animations. The touch controller’s SPI interface can be shared with the display if you use separate chip select pins. The XPT2046 has a 12-bit ADC, but the effective resolution is about 10 bits due to noise. The touch panel’s linearity error is typically ±1%, so you’ll need to calibrate for accurate touch detection. The calibration process involves pressing known points on the screen and recording the ADC values. For a 4-point calibration, you press the four corners and calculate the scaling factors. The formula for X mapping is: X_display = (X_adc - X_offset) * X_scale. The X_scale is calculated as 240 / (X_max - X_min). The Y_scale is 320 / (Y_max - Y_min). The offset values are the minimum ADC values for each axis. The touch controller’s command byte for X measurement is 0x90, which sets the X channel and starts the conversion. The command byte for Y measurement is 0xD0. The Z1 measurement uses 0xB0, and Z2 uses 0xC0. The Z1 and Z2 values can be used to calculate pressure: pressure = (Z2 / Z1) - 1. This is useful for detecting the force of the touch. The resistive touch panel has a typical activation force of 50g, so you can set a threshold in software to ignore light touches. The XPT2046 has a built-in 2.5V reference, but you can also use an external reference for better