Skip to content

Configuring Touch for XPT2046

Calvin Hass edited this page Feb 13, 2019 · 6 revisions

Overview > Configuring GUIslice > Touch >

Configuring XPT2046 Resistive Touch Handler

The XPT2046 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.

  • For TFT_eSPI users
    • The TFT_eSPI library includes an integrated XPT2046 touch controller, but in this selected mode (DRV_TOUCH_XPT2046_*), we are going to use the XPT2046_TouchScreen library for the XPT2046 instead. Therefore, we need to ensure that we disable the TFT_eSPI's integrated touch controller. This is done by ensuring that the #define TOUCH_CS line in the TFT_eSPI's User_Setup config file has been commented out.

Connection from MCU to Touchscreen

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

For STM32 users:

  • 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:

  • XPT2046_CS: Selects the chip-select pin

Calibration

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

  • ADATOUCH_X_MIN
  • ADATOUCH_X_MAX
  • ADATOUCH_Y_MIN
  • ADATOUCH_Y_MAX

In order to determine these calibration settings, please run the examples/arduino/diag_ard_touch_calib sketch.

Configuring touch sensitivity

The touch sensitivity can be defined by the following parameters. In most cases the default setting can be used.

  • ADATOUCH_PRESS_MIN
  • ADATOUCH_PRESS_MAX

Testing your display

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

Clone this wiki locally