Compilation error: 'class TFT_eSPI' has no member named 'getTouch' ESP32 Error

Hello everyone, I have a small piece of code that works like this: The program starts with a "Hello" message on an ILI9341, 15 seconds later, the "Hello" message is cleared and a menu with 2 buttons appears, Button 1 sets both Button 1 and Button 2 on a green color, while Button 2 sets both buttons back into their standard color (blue). Then an error appears, here is all of it:

In function 'void loop()':

error: 'class TFT_eSPI' has no member named 'getTouch'
     if (tft.getTouch(&touchX, &touchY)) {
             ^
error: 'class TFT_eSPI' has no member named 'getTouch'
     if (tft.getTouch(&touchX, &touchY)) {
             ^

exit status 1

Compilation error: 'class TFT_eSPI' has no member named 'getTouch'

I have Arduino IDE 2.1.0 and I just updated the libraries, I saw a solution that is downgrading the TFT_eSPI from the lastest version to version 2.3.4, I did it, even restarted Arduino, and still nothing. Here's my code:

#include <Arduino.h>
#include <TFT_eSPI.h>

// Initialize TFT display
TFT_eSPI tft;

const unsigned long timerInterval = 15000;
hw_timer_t *timer = NULL;
volatile bool alarmActivated = false;

int buttonX1 = 30;  // X-coordinate of the button's top-left corner
int buttonY1 = 30;  // Y-coordinate of the button's top-left corner

int buttonX2 = 30;  // X-coordinate of the button's top-left corner
int buttonY2 = 70;  // Y-coordinate of the button's top-left corner

int tiempo_temp;  // Variable to store the selected time

int buttonWidth = 300;  // Width of the button
int buttonHeight = 30;  // Height of the button

int control1 = 0;

int done = 0;

void drawButton() {
  tft.fillRect(10, 30, 300, 30, TFT_BLUE);
  tft.fillRect(10, 70, 300, 30, TFT_BLUE);
  //-----------------------------------
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.drawString("Button 1", 120, 40);
  tft.drawString("Button 2", 120, 80);
}

void greenButton() {
  tft.fillRect(10, 30, 300, 30, TFT_GREEN);
  tft.fillRect(10, 70, 300, 30, TFT_GREEN);
  //-----------------------------------
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.drawString("Button 1", 120, 40);
  tft.drawString("Button 2", 120, 80);
}

void btn1() {
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.drawString("Hello", 160, 40);

  tft.fillRect(240, 200, 70, 30, TFT_WHITE);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.drawString("Menu", 245, 210);

  delay(1000);
}

void btn2() {
  tft.fillScreen(TFT_BLACK);
  tft.setTextColor(TFT_WHITE);
  tft.setTextSize(2);
  tft.drawString("Bye", 160, 40);

  tft.fillRect(240, 200, 70, 30, TFT_WHITE);
  tft.setTextColor(TFT_BLACK);
  tft.setTextSize(2);
  tft.drawString("Menu", 245, 210);

  delay(1000);
}

void IRAM_ATTR callback() {
  alarmActivated = true;
}

void setup() {
  Serial.begin(115200);

  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);

  while (!Serial);

  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &callback, true);
  timerAlarmWrite(timer, timerInterval * 1000, true);

  Serial.println("Timer started");
}

void loop() {
  // Check touch input
  uint16_t touchX, touchY;
  if (control1 == 1) {
    if (done == 0) {tft.fillScreen(TFT_BLACK); drawButton(); done = 1;}
    if (tft.getTouch(&touchX, &touchY)) {
      
      // ======================= BUTTON 1 TOUCH ============================
      if (touchX >= buttonX1 && touchX <= buttonX1 + buttonWidth && touchY >= buttonY1 && touchY <= buttonY1 + buttonHeight) {
        // Button 1 is pressed
        greenButton();
      }
      // ====================== BUTTON 2 TOUCH =============================
      if (touchX >= buttonX2 && touchX <= buttonX2 + buttonWidth && touchY >= buttonY2 && touchY <= buttonY2 + buttonHeight) {
        // Button 2 is pressed
        drawButton();
      }
    }
  }

  timerAlarmEnable(timer);
  if (control1 == 0) {
    if (!alarmActivated) {
      btn1();
      delay(100);
    } else {
      control1 = 1;
      drawButton();
      delay(100);
    }

    if (tft.getTouch(&touchX, &touchY)) {
      if (touchX >= 240 && touchX <= 240 + 70 && touchY >= 200 && touchY <= 200 + 30) {
        control1 = 1;
        drawButton();
      }
    }
  }
}

@someonethatcodes Welcome to the forum..

hmm, my guess, you haven't defined TOUCH_CS??
from TFT_eSPI.h..

/***************************************************************************************
**                         Section 9: TFT_eSPI class conditional extensions
***************************************************************************************/
// Load the Touch extension
#ifdef TOUCH_CS
  #if defined (TFT_PARALLEL_8_BIT) || defined (RP2040_PIO_INTERFACE)
    #if !defined(DISABLE_ALL_LIBRARY_WARNINGS)
      #error >>>>------>> Touch functions not supported in 8/16 bit parallel mode or with RP2040 PIO.
    #endif
  #else
    #include "Extensions/Touch.h"        // Loaded if TOUCH_CS is defined by user
  #endif
#else
    #if !defined(DISABLE_ALL_LIBRARY_WARNINGS)
      #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
    #endif
#endif

it's defined inside User_Setup.h
check the screen docs for which pin..

good luck.. ~q

Hello @qubits-us, Yes, that was the problem, every single time I update the library it always has that line commented, the screen works great now. Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.