-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add touch sleep wakeup API #7439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+85
−24
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d8a1e3e
touch_sleep_wakeup_api
P-R-O-C-H-Y 2f33ba8
update example
P-R-O-C-H-Y d0a7b26
update touch docs
P-R-O-C-H-Y 7317a04
Merge branch 'master' into Touch_sleep_wakeup
P-R-O-C-H-Y ff856e1
Merge branch 'master' into Touch_sleep_wakeup
SuGlider ecefe75
add note to docs
P-R-O-C-H-Y 555c2c4
Merge branch 'Touch_sleep_wakeup' of https://github.com/P-R-O-C-H-Y/a…
P-R-O-C-H-Y 5f90810
added multiple touchpads + edit threshold
P-R-O-C-H-Y 3903189
fixed missing #endif
P-R-O-C-H-Y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,20 @@ This code displays how to use deep sleep with | |
a touch as a wake up source and how to store data in | ||
RTC memory to use it over reboots | ||
|
||
ESP32 can have multiple touch pads enabled as wakeup source | ||
ESP32-S2 and ESP32-S3 supports only 1 touch pad as wakeup source enabled | ||
|
||
This code is under Public Domain License. | ||
|
||
Author: | ||
Pranav Cherukupalli <[email protected]> | ||
*/ | ||
|
||
#define Threshold 40 /* Greater the value, more the sensitivity */ | ||
#if CONFIG_IDF_TARGET_ESP32 | ||
#define THRESHOLD 40 /* Greater the value, more the sensitivity */ | ||
#else //ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) */ | ||
#define THRESHOLD 5000 /* Lower the value, more the sensitivity */ | ||
#endif | ||
|
||
RTC_DATA_ATTR int bootCount = 0; | ||
touch_pad_t touchPin; | ||
|
@@ -42,24 +49,31 @@ has been awaken from sleep | |
void print_wakeup_touchpad(){ | ||
touchPin = esp_sleep_get_touchpad_wakeup_status(); | ||
|
||
switch(touchPin) | ||
{ | ||
case 0 : Serial.println("Touch detected on GPIO 4"); break; | ||
case 1 : Serial.println("Touch detected on GPIO 0"); break; | ||
case 2 : Serial.println("Touch detected on GPIO 2"); break; | ||
case 3 : Serial.println("Touch detected on GPIO 15"); break; | ||
case 4 : Serial.println("Touch detected on GPIO 13"); break; | ||
case 5 : Serial.println("Touch detected on GPIO 12"); break; | ||
case 6 : Serial.println("Touch detected on GPIO 14"); break; | ||
case 7 : Serial.println("Touch detected on GPIO 27"); break; | ||
case 8 : Serial.println("Touch detected on GPIO 33"); break; | ||
case 9 : Serial.println("Touch detected on GPIO 32"); break; | ||
default : Serial.println("Wakeup not by touchpad"); break; | ||
} | ||
} | ||
|
||
void callback(){ | ||
//placeholder callback function | ||
#if CONFIG_IDF_TARGET_ESP32 | ||
switch(touchPin) | ||
{ | ||
case 0 : Serial.println("Touch detected on GPIO 4"); break; | ||
case 1 : Serial.println("Touch detected on GPIO 0"); break; | ||
case 2 : Serial.println("Touch detected on GPIO 2"); break; | ||
case 3 : Serial.println("Touch detected on GPIO 15"); break; | ||
case 4 : Serial.println("Touch detected on GPIO 13"); break; | ||
case 5 : Serial.println("Touch detected on GPIO 12"); break; | ||
case 6 : Serial.println("Touch detected on GPIO 14"); break; | ||
case 7 : Serial.println("Touch detected on GPIO 27"); break; | ||
case 8 : Serial.println("Touch detected on GPIO 33"); break; | ||
case 9 : Serial.println("Touch detected on GPIO 32"); break; | ||
default : Serial.println("Wakeup not by touchpad"); break; | ||
} | ||
#else | ||
if(touchPin < TOUCH_PAD_MAX) | ||
{ | ||
Serial.printf("Touch detected on GPIO %d\n", touchPin); | ||
} | ||
else | ||
{ | ||
Serial.println("Wakeup not by touchpad"); | ||
} | ||
#endif | ||
} | ||
|
||
void setup(){ | ||
|
@@ -74,11 +88,16 @@ void setup(){ | |
print_wakeup_reason(); | ||
print_wakeup_touchpad(); | ||
|
||
//Setup interrupt on Touch Pad 3 (GPIO15) | ||
touchAttachInterrupt(T3, callback, Threshold); | ||
#if CONFIG_IDF_TARGET_ESP32 | ||
//Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27) | ||
touchSleepWakeUpEnable(T3,THRESHOLD); | ||
touchSleepWakeUpEnable(T7,THRESHOLD); | ||
|
||
#else //ESP32-S2 + ESP32-S3 | ||
//Setup sleep wakeup on Touch Pad 3 (GPIO3) | ||
touchSleepWakeUpEnable(T3,THRESHOLD); | ||
|
||
//Configure Touchpad as wakeup source | ||
esp_sleep_enable_touchpad_wakeup(); | ||
#endif | ||
|
||
//Go to sleep now | ||
Serial.println("Going to sleep now"); | ||
|
@@ -88,4 +107,4 @@ void setup(){ | |
|
||
void loop(){ | ||
//This will never be reached | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested it and it works better with this setup:
ESP32 -> Threshold = 40
S2/S3 -> Threshold = 1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ESP32 we do have threshold 40.
But for S2/S3 it cannot be that small. Normal reading is higher that this value.
For S2 if the pad is touched, reading from touchRead is above 45k. For S3 its above 95k
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is actually the delta, not the reading value itself.
It worked better (faster when touching the S2/S3 pad) when I changed it to 1,000
You can try it to check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested that a bit now, and managed to change it to 5000. That worked the best for me.
The 1000 was too much sensitive. I have attached the Dupont cable to the pin and it triggered even if I touched the rubber part of the cable, not the wire.
The 5000 triggers immediately I touch the wire :)