TFT_eSPI calibration problem

I’m using the TFT_eSPI library successfully, together with XPT2046_Touchscreen, and they both work great.
But I’m experiencing calibration problems. So I wanted to try the Touch_calibrate example of the TFT_eSPI library.

It doesn’t compile, I get the following error message :

Arduino : 1.8.2 (Windows 10), Carte : "ESP32 Dev Module, Default, QIO, 80MHz, 4MB (32Mb), 921600, None"

C:\Users\Chuwi\Documents\Arduino\libraries\TFT_eSPI\examples\Generic\Touch_calibrate\Touch_calibrate.ino: In function 'void loop()':

Touch_calibrate:46: error: 'class TFT_eSPI' has no member named 'getTouch'

   boolean pressed = tft.getTouch(&x, &y);


C:\Users\Chuwi\Documents\Arduino\libraries\TFT_eSPI\examples\Generic\Touch_calibrate\Touch_calibrate.ino: In function 'void touch_calibrate()':

Touch_calibrate:78: error: 'class TFT_eSPI' has no member named 'calibrateTouch'

   tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);


exit status 1
'class TFT_eSPI' has no member named 'getTouch'

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.

I understand the message. I was expecting to see some instanciation of the touch panel by using the XPT2046 library.
Maybe I’m not using the last version of the library, although I installed it recently. Did anyone have any such problem with this example?

Here is the full code :

  Sketch to generate the setup() calibration values, these are reported
  to the Serial Monitor.

  The sketch has been tested on the ESP8266 and screen with XPT2046 driver.

#include <SPI.h>
#include <TFT_eSPI.h>      // Hardware-specific library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library


void setup() {
  // Use serial port

  // Initialise the TFT screen

  // Set the rotation before we calibrate

  // Calibrate the touch screen and retrieve the scaling factors

  // Replace above line with the code sent to Serial Monitor
  // once calibration is complete, e.g.:
  uint16_t calData[5] = { 286, 3534, 283, 3600, 6 };

  // Clear the screen
  tft.drawCentreString("Touch screen to test!",tft.width()/2, tft.height()/2, 2);


void loop(void) {
  uint16_t x = 0, y = 0; // To store the touch coordinates

  // Pressed will be set true is there is a valid touch on the screen
  boolean pressed = tft.getTouch(&x, &y);

  // Draw a white spot at the detected coordinates
  if (pressed) {
    tft.fillCircle(x, y, 2, TFT_WHITE);
    //Serial.print("x,y = ");


// Code to run a screen calibration, not needed when calibration values set in setup()
void touch_calibrate()
  uint16_t calData[5];
  uint8_t calDataOK = 0;

  // Calibrate
  tft.setCursor(20, 0);
  tft.setTextColor(TFT_WHITE, TFT_BLACK);

  tft.println("Touch corners as indicated");


  tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);

  Serial.println(); Serial.println();
  Serial.println("// Use this calibration code in setup():");
  Serial.print("  uint16_t calData[5] = ");
  Serial.print("{ ");

  for (uint8_t i = 0; i < 5; i++)
    if (i < 4) Serial.print(", ");

  Serial.println(" };");
  Serial.print("  tft.setTouch(calData);");
  Serial.println(); Serial.println();

  tft.setTextColor(TFT_GREEN, TFT_BLACK);
  tft.println("Calibration complete!");
  tft.println("Calibration code sent to Serial port.");


If you define a pin for the touch chip select then it should be OK:

Thanks Bodmer, I'll try this tonight (french time). Does this mean that I don't need the XPT2046_Touchscreen library with your TFT_eSPI library if I want to use the touch (after calibration) in my sketch?

The XPT2046 touch controller support is built into the TFT_eSPI library. You can use a different touch library but you will then need to modify the examples.

OK, I'll study that deeper. Thank you !

I finally had it work : if you want to see the results, it's here (in french of course, sorry :confused: )