Problem with touchAttachInterrupt

Hello everyone,
I am programming an ESP32 with a touch screen and one of the things I want to do is sleep the device and wake it up every 5 minutes or when the screen is touched and touch is activated.
I use the instruction:

esp_deep_sleep_start();´

for it to sleep.
I use the instruction:

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

to wake it up every 5 minutes.
and I use the instructions:

     touchAttachInterrupt(T0...T9, Touched, 40); 
     esp_sleep_enable_touchpad_wakeup();

To try to get it to wake up with touch, but as soon as it falls asleep it wakes up again and tells me that it was due to activating the touch and that is not possible because the screen has not been touched.

Boot number: 2
Wakeup caused by touchpad
Touch detected on GPIO 4

I have tried with all the pins from T0 to T9 and Either they fire on their own or they don't detect touches.

Can someone help me find a solution? Thanks.
Greetings.

Does the touch interrupt work if you don't put the ESP to sleep?

Post links to the used hardware and a wiring diagram!

Hello, the hardware is:
2.8 inch ESP32 module ESP32-2432S028R

And it don`t use wiring diagram because it has the built-in TFT.
If I deactivate sleep, I have a check in the Touch function that is within the parameters of touchAttachInterrupt and it tells me that it is constantly activated without stopping.
This is the Touch pin configuration:

#define DOUT 39 /* Data out pin (T_DO) of touch screen */
#define DIN  32 /* Data in pin (T_DIN) of touch screen */
#define DCS  33  /* Chip select pin (T_CS) of touch screen */
#define DCLK 25  /* Clock pin (T_CLK) of touch screen */

I have now included a new instruction that I found by looking in the ESP-IDF Programming Guide ESPRESSIF, but still the same:

     touchAttachInterrupt(T6, Tocado, threshold);
    **esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_AUTO);**
    esp_sleep_enable_touchpad_wakeup();

Thanks for your help.

Can you provide links to the libraries, documentation, etc. you have for that board?

Hello, this is the link to Aliexpress where I bought the ESP32, in it there is a link to information.

The library that I use to control the touch is TFT_Touch.h.

Link ESP32

I guess this library is meant. Is it that hard to provide links to used libraries if they are not available in the Library Manager?

Please post that code!

T6 is GPIO14 but the IRQ line of the XPT2046 is connected to GPIO36 in your module. Unfortunately that isn't a touch input pin, so you cannot use that functionality.

I understand that I will have to use an external button to wake it up, so I won't have any problems?
Thank you very much for your help, I am new to this and I am quite lost.

No guarantees for that but you probably have one less :slight_smile: .

I have been looking at how to put an external button to wake it up, but I am not sure how to do it either, because the only thing I see is that it has an extended IO, a temperature to humidity interface and a speak.
I understand that I should use the extended IO with an ESP8266 IO Expander for ESP32, for example.
Is it correct or can I do it another way. Can you help me with this?
Thanks.

I have no clue what you mean by this. You haven't provided a link to your hardware yet, so it's hard to follow you.

Hello, I have been looking for information on the motherboard and this is what I have found.




I don't know this will be enough for you.
My problem is that I'm trying to place an external button to wake up the device, but I don't know how to do it.
I've tried using the temperature and humidity interface connector to add a deep sleep wake-up button to the ESP32. Following the diagram that I have attached, I have connected one part to the 3.3V output and the other to where it says IO27, but when I have tried the GPIO27 it is always active, even if I do not put the button.
Having only I/O through connectors I don't know how to attack the pins.
Thanks for your help.
Greetings.

Thanks, this helps a lot.

I would also use the connector labeled External IO, you can use any of these pins.

Hello,
I wanted to ask you another question:
I am trying to control the brightness of my screen to turn it off progressively if it is not touched, but I cannot find the pin that I have to act on to achieve it.
Could you help me?
These are the instructions I'm using:

#define BACKLIGHT_CHANNEL 0
#define BACKLIGHT_FREQUENCY 12000
#define BACKLIGHT_RESOLUTION_BITS 8
**#define TFT_LITE ??** 

float percent = 0.75;
int dutyCycle = (int) round(255 * percent);

void setup()
{  
    Serial.begin( 115200 ); /* prepare for possible serial debug */
    delay(1000);

    pinMode( TFT_LITE, OUTPUT );      
    ledcSetup( BACKLIGHT_CHANNEL, BACKLIGHT_FREQUENCY, BACKLIGHT_RESOLUTION_BITS );
}

void loop()
{
      if ( millis() - durmiendo > 60000 ) {
        Serial.println ("Un minuto ");
        percent = 0.50;
        ledcWrite( BACKLIGHT_CHANNEL, dutyCycle ); 
      }     
      if ( millis() - durmiendo > 75000 ) {
        Serial.println ("Un minuto y 1/4 ");
        percent = 0.25;
        ledcWrite( BACKLIGHT_CHANNEL, dutyCycle ); 
      }     
      if ( millis() - durmiendo > 90000 ) {
        Serial.println ("Un minuto y 1/2 ");
        percent = 0.01;
        ledcWrite( BACKLIGHT_CHANNEL, dutyCycle );
        durmiendo = millis();
      } 
}

Could you tell me which pin I have to use or if I'm doing something wrong.
Thanks.

I would try IO21. Although I found nothing in the schematics, on the picture it is marked this way.