Skip to content

Configuring Touch for XPT2046 (TFT_eSPI)

Calvin Hass edited this page May 20, 2019 · 8 revisions

Overview > Configuring GUIslice > Touch >

Configuring TFT_eSPI XPT2046 Resistive Touch Handler

  • Touch mode selected by: DRV_TOUCH_TFT_ESPI
  • Library used: TFT_eSPI from Bodmer/TFT_eSPI

The TFT_eSPI's XPT2046 library provides filtering and easy access to the raw touch readings. The software then is responsible for performing a remapping between the raw analog read values and the corresponding display coordinates.

Configuring TFT_eSPI

  • When the TFT_eSPI's integrated XPT2046 touch controller is selected by GUIslice configuration (DRV_TOUCH_TFT_ESPI), then it is important that the TFT_eSPI library's configuration has been set correctly.
  • The TFT_eSPI library's User_Setup configuration file is responsible for defining the chip-select for an XPT2046 touch controller chip. The corresponding line in the config file is: #define TOUCH_CS. Please ensure this line is not commented out, and assign it to a pin that matches your wiring.

Connection from MCU to Touchscreen

With the XPT2046 touch driver, connectivity is provided via the SPI interface.

On some devices (such as STM32), multiple hardware SPI interfaces may be available. In order to maximize compatibility, the SPI interface can be selected via the XPT2046_DEFINE_DPICLASS setting (documentation coming soon).

To configure the hardware SPI interface:

  • TFT_eSPI's User_Setup: TOUCH_CS: Selects the chip-select pin

Calibration

The TFT_eSPI XPT2046 uses calibration settings that are specific to your display, defined in the following configuration parameters:

  • TFT_ESPI_TOUCH_CALIB: Calibration parameter output by TFT_eSPI's calibration utility, found in your GUIslice config file section 4B.
  • In order to determine these values, please run TFT_eSPI's Touch_calibrate sketch and copy the 5 numbers reported as the “calibration code” into TFT_ESPI_TOUCH_CALIB. For example:
  • #define TFT_ESPI_TOUCH_CALIB { 321,3498,280,3593,3 }

Testing your display

Run examples/arduino/diag_ard_touch_test to assess whether the touch handling is operating correctly.

Clone this wiki locally