Skip to content
Jasmine Tame Online Jasmine Tame Online Est. 2019 · London

New work every Tuesday

Vol. VII · No. 41

How to get started with a 2.8 inch capacitive TFT display module?

· · About the author

Getting started with a 2.8 inch capacitive TFT display module is straightforward if you understand the hardware interface, power requirements, and initialization sequence. Most of these modules, like the one based on the ILI9341 controller, use either SPI or I2C communication. The first step is to identify the pinout: typically, you’ll find VCC (3.3V or 5V), GND, CS (chip select), DC (data/command), RESET, MOSI, MISO, SCK, and LED (backlight control). For the 2.8 inch capacitive tft display module, the SPI mode runs at up to 40 MHz, which gives you a refresh rate of around 60 Hz for 240x320 resolution. The capacitive touch overlay uses a separate I2C interface, typically with an FT6206 or similar controller, running at 100 kHz to 400 kHz. You need to connect the touch controller’s SDA and SCL lines to your microcontroller’s I2C pins, and the interrupt pin (INT) to a GPIO for touch detection. The display’s pixel clock is derived from the SPI clock, and the ILI9341 datasheet specifies a minimum SPI clock period of 62.5 ns for read operations and 25 ns for write operations. This means you can push data at 40 Mbps if your microcontroller supports it. The module’s backlight draws about 20 mA at 3.3V, and the display itself consumes around 40 mA during normal operation, totaling 60 mA. For capacitive touch, the FT6206 draws 2.5 mA in active mode and 0.5 mA in sleep mode. If you’re using a 3.3V logic microcontroller like an ESP32 or STM32, you can power the module directly. For 5V systems like Arduino Uno, you’ll need a level shifter for the SPI lines, though the module’s VCC can tolerate 5V if it has an onboard regulator—check the module’s datasheet. The initialization sequence for the ILI9341 involves sending a series of commands: first, a software reset (0x01) with a 120 ms delay, then set the power control (0xC0) with parameters 0x23, 0x10, and 0x3E. Next, set the pixel format (0x3A) to 0x55 for 16-bit color, followed by the memory access control (0x36) to 0x48 for portrait orientation. The frame rate control (0xB1) should be set to 0x00, 0x18 for 60 Hz. Finally, exit sleep mode (0x11) with a 150 ms delay, and turn on the display (0x29). After initialization, you can write pixel data by setting the column address (0x2A) and page address (0x2B), then sending pixel data via SPI. For capacitive touch, the FT6206 requires an I2C write to set the device address (0x38) and then read touch data from registers 0x02 to 0x07. The touch data includes the number of touch points (register 0x02), X and Y coordinates for each point. For a single touch, you read 6 bytes: status, touch 1 X high, touch 1 X low, touch 1 Y high, touch 1 Y low, and a reserved byte. The X and Y values are 12-bit, ranging from 0 to 4095, but you need to map them to your display resolution. For a 240x320 display, the mapping formula is: display_x = (touch_x * 240) / 4096, and display_y = (touch_y * 320) / 4096. The touch controller’s interrupt pin goes low when a touch is detected, so you can use an interrupt service routine to read the I2C data. The FT6206’s I2C address is 0x38, and you need to write a 0x02 to the register pointer before reading. The I2C clock speed should be set to 100 kHz for reliable operation, though some modules support 400 kHz. If you’re using an Arduino, the Wire library handles I2C communication, but you need to set the clock speed with Wire.setClock(100000). For SPI, use the SPI library with a clock divider of SPI_CLOCK_DIV2 for 8 MHz on a 16 MHz Arduino, or SPI_CLOCK_DIV4 for 4 MHz. The display’s SPI mode is 0 (CPOL=0, CPHA=0), meaning the clock idle state is low and data is sampled on the rising edge. The CS pin must be held low during the entire transaction, and the DC pin controls whether you’re sending a command (DC low) or data (DC high). For the backlight, you can control brightness with a PWM signal on the LED pin. The backlight’s forward voltage is 3.2V at 20 mA, so a 100 ohm resistor in series with a PWM pin works well. If you’re using a transistor to drive the backlight, a 2N2222 with a 1k base resistor is sufficient. The module’s power consumption increases with backlight brightness, so at 100% PWM, it draws 60 mA total, but at 50% PWM, it drops to 40 mA. For battery-powered projects, you can reduce power by putting the display in sleep mode (0x10) and the touch controller in sleep mode (write 0x03 to register 0x00). The display’s sleep current is 5 µA, and the touch controller’s sleep current is 0.5 µA, giving you a total of 5.5 µA in sleep mode. To wake up, send the display a wake command (0x11) and reset the touch controller by toggling its reset pin. The module’s physical dimensions are 68.5 mm x 50.0 mm x 7.5 mm, with a viewing area of 43.2 mm x 57.6 mm. The capacitive touch panel has a hardness of 6H and supports up to 5 simultaneous touches. The touch response time is 10 ms, and the display’s response time is 25 ms. The module’s operating temperature range is -20°C to 70°C, and the storage temperature is -30°C to 80°C. For software libraries, the Adafruit GFX library and Adafruit ILI9341 library work well for the display, but you need to modify the pin definitions for your specific module. For the touch controller, the Adafruit FT6206 library handles the I2C communication. If you’re using a Raspberry Pi, you can use the Python spidev library for SPI and the smbus2 library for I2C. The SPI bus on the Raspberry Pi runs at 32 MHz, but you may need to reduce it to 16 MHz for stability. The touch controller’s I2C bus runs at 100 kHz, and you can use the i2c-tools package to detect the device. The module’s default I2C address is 0x38, and you can verify it with i2cdetect -y 1. For the display, you need to enable the SPI interface in raspi-config and set the SPI buffer size to 4096 bytes. The display’s frame buffer is 153,600 bytes (240x320x2 bytes per pixel), so you need to allocate that much memory. For a microcontroller, you can use a partial update technique to reduce memory usage. For example, update only the changed region by setting the column and page addresses to the bounding box. The ILI9341 supports a windowed update, so you can write to a 100x100 pixel area without rewriting the entire screen. This reduces SPI traffic by 87% for small updates. The capacitive touch controller supports gestures like tap, double-tap, and swipe, but you need to implement gesture detection in software. The FT6206 provides raw touch data, so you can track the touch position over time to detect gestures. For a tap, the touch duration is less than 200 ms, and for a swipe, the touch moves more than 50 pixels in 100 ms. The module’s touch accuracy is 0.5 mm, and the linearity is 1.5%. The display’s viewing angle is 80 degrees in all directions, and the contrast ratio is 500:1. The color depth is 262,000 colors with 16-bit RGB565 format. The pixel format is 5 bits for red, 6 bits for green, and 5 bits for blue. To convert a 24-bit color to 16-bit, use the formula: R = (color >> 19) & 0x1F, G = (color >> 10) & 0x3F, B = (color >> 3) & 0x1F, then pack into a 16-bit word: (R << 11) | (G << 5) | B. The display’s gamma correction is set by default, but you can adjust it with the gamma set commands (0xE0 and 0xE1). The default gamma curve is 2.2, but you can change it to 1.8 or 2.5 by writing different values to the gamma registers. The module’s PCB has mounting holes for M3 screws, and the connector is a 2.54 mm pitch header. The touch panel’s surface is oleophobic, so it resists fingerprints. The module’s weight is 35 grams, and it’s suitable for handheld devices. For EMI shielding, the module has a ground plane on the back of the PCB. The display’s pixel clock is generated internally, and the SPI clock is independent. The module’s SPI bus can be shared with other devices if you use separate CS pins. The touch controller’s I2C bus can also be shared, but the address is fixed at 0x38. If you have multiple touch modules, you need to change the I2C address by modifying the module’s hardware. The module’s firmware is stored in the ILI9341’s internal ROM, so no external flash is needed. The capacitive touch controller’s firmware is also internal, so no programming is required. The module’s initialization sequence is the same for all ILI9341-based displays, but some modules may have different pin mappings. Always check the datasheet for your specific module. The module’s power-on sequence is: apply VCC, then wait 10 ms, then pull RESET low for 10 ms, then release RESET and wait 120 ms. Then send the initialization commands. If you skip the reset, the display may not initialize correctly. The touch controller’s power-on sequence is: apply VCC, then wait 5 ms, then pull the reset pin low for 1 ms, then release it. The touch controller will then start sending interrupts. The module’s maximum SPI clock speed is 40 MHz, but most microcontrollers can’t achieve that. The ESP32 can run SPI at 40 MHz, but the STM32F4 can run at 30 MHz. The Arduino Uno’s SPI runs at 8 MHz, which is enough for 60 fps with 16-bit color. The frame rate is calculated as: fps = SPI clock speed / (240 * 320 * 2 * 8). For 8 MHz, fps = 8,000,000 / (240 * 320 * 16) = 6.5 fps. For 40 MHz, fps = 40,000,000 / (240 * 320 * 16) = 32.5 fps. To achieve 60 fps, you need an SPI clock of 73.7 MHz, which is beyond most microcontrollers. So, for high frame rates, use a smaller display or lower color depth. The module’s touch controller supports up to 5 touches, but the ILI9341 doesn’t handle multi-touch natively. You need to implement multi-touch gestures in software. The touch controller’s FIFO buffer stores up to 5 touch points, so you can read all of them in one I2C transaction. The buffer is cleared after each read. The module’s power consumption can be reduced by using a lower backlight brightness. At 50% brightness, the display draws 30 mA, and at 0% brightness, it draws 20 mA. The touch controller draws 2.5 mA regardless of backlight. The module’s total power consumption is 22.5 mA at 0% brightness and 60 mA at 100% brightness. For battery life, use a 1000 mAh battery, you get 16.6 hours at full brightness and 44.4 hours at 0% brightness. The module’s operating voltage is 3.3V, but the I/O pins are 5V tolerant. The SPI and I2C lines can handle 5V logic, but the VCC pin must be 3.3V. If you use 5V on VCC, the module may be damaged. The module’s backlight LED has a forward voltage of 3.2V, so a 3.3V supply is enough. The module’s capacitive touch panel has a sensitivity of 10 pF, and it can detect a finger through a 1 mm glass overlay. The module’s touch resolution is 4096 x 4096, but the display resolution is 240x320, so you need to map the coordinates. The mapping is linear, but you may need to calibrate for offset. The calibration process involves touching known points and calculating the offset and scale. The module’s touch controller has a built-in calibration, but it’s for the touch panel itself, not the display. You need to calibrate the touch to the display in software. The module’s SPI bus is 4-wire, but some modules have a 5-wire SPI with a separate MISO pin. The module’s I2C bus is 2-wire, but some modules have an interrupt pin. The module’s pinout is: 1: VCC, 2: GND, 3: CS, 4: RESET, 5: DC, 6: MOSI, 7: SCK, 8: LED, 9: MISO, 10: SDA, 11: SCL, 12: INT. The touch controller’s I2C address is 0x38, but some modules use 0x48. Check the module’s datasheet. The module’s display driver is the ILI9341, which is a 240x320 RGB565 driver. The driver supports rotation, but the touch controller doesn’t. You need to rotate the touch coordinates manually. The module’s display has a built-in frame buffer, so you don’t need an external one. The module’s touch controller has a 16-point FIFO buffer. The module’s SPI command set includes: 0x01 (software reset), 0x11 (sleep out), 0x29 (display on), 0x2A (column address set), 0x2B (page address set), 0x2C (memory write), 0x36 (memory access control), 0x3A (pixel format set). The touch controller’s I2C registers include: 0x00 (device mode), 0x01 (gesture ID), 0x02 (number of touch points), 0x03-0x08 (touch data). The module’s initialization sequence is: reset, sleep out, pixel format set, memory access control, display on. The module’s touch initialization is: reset, device mode set to 0x00 (normal mode). The module’s power management can be done by setting the display to sleep mode and the touch controller to sleep mode. The module’s sleep mode is entered by sending 0x10 to the display and writing 0x03 to the touch controller’s device mode register. The module’s wake-up sequence is: send 0x11 to the display, wait 120 ms, then write 0x00 to the touch controller’s device mode register. The module’s reset sequence is: pull RESET low for 10 ms, then release it. The module’s touch reset is: pull the touch reset pin low for 1 ms, then release it. The module’s SPI transaction is: set CS low, set DC low for command, send command byte, set DC high for data, send data bytes, set CS high. The module’s I2C transaction is: write the register pointer, then read or write data. The module’s touch interrupt is active low, so you can connect it to a GPIO with a pull-up resistor. The module’s backlight can be controlled with a PWM signal at 1 kHz. The module’s display has a refresh rate of 60 Hz, but the touch controller’s scan rate is 100 Hz. The module’s touch latency is 10 ms, and the display latency is 25 ms. The module’s total latency is 35 ms, which is suitable for most applications. The module’s display has a viewing angle of 80 degrees, and the touch panel has a viewing angle of 90 degrees. The module’s display has a brightness of 300 cd/m², and the touch panel has a transparency of 85%. The module’s display has a contrast ratio of 500:1, and the touch panel has a contrast ratio of 1000:1. The module’s display has a color gamut of 50% NTSC, and the touch panel has a color gamut of 70% NTSC. The module’s display has a pixel pitch of 0.18 mm, and the touch panel has a pixel pitch of 0.1 mm. The module’s display has a resolution of 240x320, and the touch panel has a resolution of 4096x4096. The module’s display has a response time of 25 ms, and the touch panel has a response time of 10 ms. The module’s display has a power consumption of 40 mA, and the touch panel has a power consumption of 2.5 mA. The module’s display has a weight of 30 grams, and the touch panel has a weight of 5 grams. The module’s display has a size of 68.5 mm x 50.0 mm x 7.5 mm, and the touch panel has a size of 68.5 mm x 50.0 mm x 1.5 mm. The module’s display has a connector of 2.54 mm pitch, and the touch panel has a connector of

— Jasmine Tame Online