@@ -5,13 +5,20 @@ This code displays how to use deep sleep with
5
5
a touch as a wake up source and how to store data in
6
6
RTC memory to use it over reboots
7
7
8
+ ESP32 can have multiple touch pads enabled as wakeup source
9
+ ESP32-S2 and ESP32-S3 supports only 1 touch pad as wakeup source enabled
10
+
8
11
This code is under Public Domain License.
9
12
10
13
Author:
11
14
Pranav Cherukupalli <cherukupallip@gmail.com>
12
15
*/
13
16
14
- #define Threshold 40 /* Greater the value, more the sensitivity */
17
+ #if CONFIG_IDF_TARGET_ESP32
18
+ #define THRESHOLD 40 /* Greater the value, more the sensitivity */
19
+ #else // ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) */
20
+ #define THRESHOLD 5000 /* Lower the value, more the sensitivity */
21
+ #endif
15
22
16
23
RTC_DATA_ATTR int bootCount = 0 ;
17
24
touch_pad_t touchPin;
@@ -42,24 +49,31 @@ has been awaken from sleep
42
49
void print_wakeup_touchpad (){
43
50
touchPin = esp_sleep_get_touchpad_wakeup_status ();
44
51
45
- switch (touchPin)
46
- {
47
- case 0 : Serial.println (" Touch detected on GPIO 4" ); break ;
48
- case 1 : Serial.println (" Touch detected on GPIO 0" ); break ;
49
- case 2 : Serial.println (" Touch detected on GPIO 2" ); break ;
50
- case 3 : Serial.println (" Touch detected on GPIO 15" ); break ;
51
- case 4 : Serial.println (" Touch detected on GPIO 13" ); break ;
52
- case 5 : Serial.println (" Touch detected on GPIO 12" ); break ;
53
- case 6 : Serial.println (" Touch detected on GPIO 14" ); break ;
54
- case 7 : Serial.println (" Touch detected on GPIO 27" ); break ;
55
- case 8 : Serial.println (" Touch detected on GPIO 33" ); break ;
56
- case 9 : Serial.println (" Touch detected on GPIO 32" ); break ;
57
- default : Serial.println (" Wakeup not by touchpad" ); break ;
58
- }
59
- }
60
-
61
- void callback (){
62
- // placeholder callback function
52
+ #if CONFIG_IDF_TARGET_ESP32
53
+ switch (touchPin)
54
+ {
55
+ case 0 : Serial.println (" Touch detected on GPIO 4" ); break ;
56
+ case 1 : Serial.println (" Touch detected on GPIO 0" ); break ;
57
+ case 2 : Serial.println (" Touch detected on GPIO 2" ); break ;
58
+ case 3 : Serial.println (" Touch detected on GPIO 15" ); break ;
59
+ case 4 : Serial.println (" Touch detected on GPIO 13" ); break ;
60
+ case 5 : Serial.println (" Touch detected on GPIO 12" ); break ;
61
+ case 6 : Serial.println (" Touch detected on GPIO 14" ); break ;
62
+ case 7 : Serial.println (" Touch detected on GPIO 27" ); break ;
63
+ case 8 : Serial.println (" Touch detected on GPIO 33" ); break ;
64
+ case 9 : Serial.println (" Touch detected on GPIO 32" ); break ;
65
+ default : Serial.println (" Wakeup not by touchpad" ); break ;
66
+ }
67
+ #else
68
+ if (touchPin < TOUCH_PAD_MAX)
69
+ {
70
+ Serial.printf (" Touch detected on GPIO %d\n " , touchPin);
71
+ }
72
+ else
73
+ {
74
+ Serial.println (" Wakeup not by touchpad" );
75
+ }
76
+ #endif
63
77
}
64
78
65
79
void setup (){
@@ -74,11 +88,16 @@ void setup(){
74
88
print_wakeup_reason ();
75
89
print_wakeup_touchpad ();
76
90
77
- // Setup interrupt on Touch Pad 3 (GPIO15)
78
- touchAttachInterrupt (T3, callback, Threshold);
91
+ #if CONFIG_IDF_TARGET_ESP32
92
+ // Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27)
93
+ touchSleepWakeUpEnable (T3,THRESHOLD);
94
+ touchSleepWakeUpEnable (T7,THRESHOLD);
95
+
96
+ #else // ESP32-S2 + ESP32-S3
97
+ // Setup sleep wakeup on Touch Pad 3 (GPIO3)
98
+ touchSleepWakeUpEnable (T3,THRESHOLD);
79
99
80
- // Configure Touchpad as wakeup source
81
- esp_sleep_enable_touchpad_wakeup ();
100
+ #endif
82
101
83
102
// Go to sleep now
84
103
Serial.println (" Going to sleep now" );
@@ -88,4 +107,4 @@ void setup(){
88
107
89
108
void loop (){
90
109
// This will never be reached
91
- }
110
+ }
0 commit comments