• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Touchpad Wakeup, Understanding callback

Q&A Forum › Category: ESP32 › Touchpad Wakeup, Understanding callback
0 Vote Up Vote Down
Charles Phillips asked 3 years ago

Hi all.. I’m  currently working with Module 3 Unit 3 of the ESP32 with Arduino IDE course.
I’m trying to understand the callback in the  touchAttachInterrupt(T3, callback, Threshold); piece of code.
My understanding is that callback is a user defined function that is executed when the interrupt is triggered, is that correct? I ask because I put a simple Serial.println() statement inside the callback function and it doesn’t seem to execute. What am I missing?

7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Charles, you are correct.
But, you need to take this into account:

“The callback() function will only be executed if the ESP32 is awake.

  • If the ESP32 is asleep and you touch T3, the ESP will wake up – the callback() function won’t be executed if you just press and release the touch pin;
  • If the ESP32 is awake and you touch T3, the callback function will be executed. So, if you want to execute the callback() function when you wake up the ESP32, you need to hold the touch on that pin for a while, until the function is executed.”

I hope this is clear.

Can you try it and see if it works?

Regards,
Sara

0 Vote Up Vote Down
Charles Phillips answered 3 years ago

Thank you Sara for your answer. I was aware of this but I didn’t hold the tap long enough. Holding longer did the trick. While playing around with the touch pins I found them somewhat flaky. Phantom touches even when setting the threshold variable low. 

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Charles.
Yes, that can happen.
Specially if you don’y have good quality jumper wires. 
Instead of using the touch pins for wake up, you can consider using pushbuttons with the external wake up instead.
Regards,
Sara

0 Vote Up Vote Down
Mose Brancato answered 2 years ago

Ciao Sara,
I’m having the same problem: I’m trying to execute a simple  “serial.print” inside the callback function:

void callback(){
//placeholder callback function
Serial.println("*** inside callback function ***");
}

BUT, Holding the cable for more then one second, the ESP32 goes to sleep and wakes up itself again and again very fast, without calling the “callback” function.
Following the monitor outuput:

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Boot number: 23
Wakeup caused by touchpad
Touch detected on GPIO 15
Going to sleep now
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Boot number: 24
Wakeup caused by touchpad
Touch detected on GPIO 15
Going to sleep now
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Boot number: 25
Wakeup caused by touchpad
Touch detected on GPIO 15
Going to sleep now

 
 

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
As I explained previously:
The callback() function will only be executed if the ESP32 is awake.

  • If the ESP32 is asleep and you touch T3, the ESP will wake up – the callback() function won’t be executed if you just press and release the touch pin;
  • If the ESP32 is awake and you touch T3, the callback function will be executed. So, if you want to execute the callback() function when you wake up the ESP32, you need to hold the touch on that pin for a while, until the function is executed.”

You need to hold the touch for a while.

Additionally, you may need to put a delay() somewhere in your code.

What is exactly the code that you are trying to run?

Regards,
Sara

0 Vote Up Vote Down
Mose Brancato answered 2 years ago

thanks for your answer Sara. I’m running the code you’ve shared in the unit, I did just copy and paste. As I’ve wrote, I’m already holding the touch for many seconds.
Now I’ve inserted a delay, as you’ve suggested:

//Setup interrupt on Touch Pad 3 (GPIO15)
touchAttachInterrupt(T3, callback, Threshold);
delay(1000);

Holding the cable now the callback function is executed! 🙂
Many thanks,
Mosè

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Great!

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.