Page 1 of 2
External wakeup pin detect issue
Posted: Tue Aug 06, 2019 6:33 am
by hellraise007
I have 5 switches connected to RTC pins on my ESP32 Devkit V1 in ext1 mode. i used
Code: Select all
esp_sleep_get_ext1_wakeup_status();
to get the pin number that was used to wake up the module. What happens is this function returns the correct value while using small tactile switches (PCB mountable one's) . My requirement is to use KW8-XILIE switches for this project, but when i use them the function always returns 0.
I would like to know if there is any design consideration while using these big switches, or if there is any hardware bug in older devkit modules that can cause this.
The code is pretty straight forward.
void wake_up_pin()
{
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
int GPIO_reason = esp_sleep_get_ext1_wakeup_status();
if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1)
{
Serial.println("Waked up ext1");
int k=(int)(log(GPIO_reason)/log(2));
switch (k)
{
case 2:
button[0].numberKeyPresses++;
Serial.printf("Button 1 has been pressed %u times\n", button[0].numberKeyPresses);
break;
case 15:
button[1].numberKeyPresses++;
Serial.printf("Button 2 has been pressed %u times\n", button[1].numberKeyPresses);
break;
case 25:
button[2].numberKeyPresses++;
Serial.printf("Button 3 has been pressed %u times\n", button[2].numberKeyPresses);
break;
case 26:
button[3].numberKeyPresses++;
Serial.printf("Button 4 has been pressed %u times\n", button[3].numberKeyPresses);
break;
case 27:
button[4].numberKeyPresses++;
Serial.printf("Button 5 has been pressed %u times\n", button[4].numberKeyPresses);
break;
default:
Serial.println(k);
break;
}
}
}
setup()
{
esp_sleep_enable_ext1_wakeup(GPIO_SEL_2 | GPIO_SEL_15 | GPIO_SEL_25 | GPIO_SEL_26 | GPIO_SEL_27, ESP_EXT1_WAKEUP_ANY_HIGH);
esp_deep_sleep_start();
}
Re: External wakeup pin detect issue
Posted: Tue Aug 06, 2019 4:16 pm
by boarchuz
I don't see where wake_up_pin() is called. Check you copied your full sketch here.
Add a couple printouts for wakeup_reason and GPIO_reason, then post the full output here.
Re: External wakeup pin detect issue
Posted: Wed Aug 07, 2019 6:46 am
by hellraise007
boarchuz wrote: ↑Tue Aug 06, 2019 4:16 pm
I don't see where wake_up_pin() is called. Check you copied your full sketch here.
Add a couple printouts for wakeup_reason and GPIO_reason, then post the full output here.
Thank you for your reply. The code is pretty much trivial. For the sake of testing I am using the example code for ext1 wakeup
RTC_DATA_ATTR int bootCount = 0;
/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
void print_GPIO_wake_up(){
int GPIO_reason = esp_sleep_get_ext1_wakeup_status();
Serial.print("GPIO that triggered the wake up: GPIO ");
Serial.println((log(GPIO_reason))/log(2), 0);
}
void setup(){
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
print_GPIO_wake_up()
esp_sleep_enable_ext1_wakeup(GPIO_SEL_2 | GPIO_SEL_15 | GPIO_SEL_25 | GPIO_SEL_26 | GPIO_SEL_27, ESP_EXT1_WAKEUP_ANY_HIGH);
//Go to sleep now
Serial.println("Going to sleep now");
delay(1000);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop(){
//This is not going to be called
}
I believe this is not a code issue as i get the correct pin number while using small tactile switches like these :
https://www.digikey.com/product-detail/ ... ND/1632536 but not while using KW8-XILIE switches. I am searching for any hardware design considerations that might affect its usage.
Serial Output:
Using normal switches
Code: Select all
Boot number: 3
Wakeup caused by external signal using RTC_CNTL
GPIO that triggered the wake up: GPIO 15
Going to sleep now
Using KW8-XILIE
Code: Select all
Boot number: 4
Wakeup caused by external signal using RTC_CNTL
GPIO that triggered the wake up: GPIO inf
Going to sleep now
I have verified that esp_sleep_get_ext1_wakeup_status(); returns 0 not 15 while using the big switches.
Re: External wakeup pin detect issue
Posted: Mon Aug 26, 2019 11:05 am
by hellraise007
What are all the conditions that can cause esp_sleep_get_ext1_wakeup_status() to return 0, other than woken up by another source. I have only ext1 wakeup enabled.
Re: External wakeup pin detect issue
Posted: Tue Sep 03, 2019 5:42 pm
by Rudy12
Hi power switches can fail to provide a contact closure if the switched voltage and current is too low. I tend to use a lower pull up resistance. Sometimes I have used 12 volts for the switching voltage, and then add parts to protect the CPU input.
Some switches have a gold plating option for the contacts. This is the preferred option when switching signal levels.
Re: External wakeup pin detect issue
Posted: Fri Jan 08, 2021 6:45 pm
by mattpellegrini
I have hit this exact issue. It took me a while to find a thread on the subject, albeit an old one.
I'm wondering if someone can explain a little more. @Rudy12 suggests there may in insufficient voltage or current, which sounds plausible, but the esp32 does wake with both buttons. However, esp_sleep_get_ext1_wakeup_status returns 0 with a larger push-button and 2^32 (in my case, as the button is on pin 32) with a smaller pcb-mounted push button.
The only change to the circuit is the push button used. I've even put both in parallel and every press of the small button wake the esp to print 2^32 and every press of the larger button wakes and prints 0. I have tried other GPIO pins.
I'm curious how it's possible to wake but not be able to determine the pin that triggered the wake. More importantly, I'm wondering if anyone can suggest a solution to get this working on 3.3v.
Software developer here, with a fairly basic understanding of electronics and microcontrollers, but feel free to link anything related, I'll happily read up if someone can point me somewhere to better understand this.
Re: External wakeup pin detect issue
Posted: Sat Jan 09, 2021 7:40 am
by chegewara
This is only theory, but:
- esp_sleep_get_ext1_wakeup_status is reading latched register,
- that latched register stores values for all pins being high during wakeup and being setup as wakeup pins,
- since it is big button with some bigger debounce it is possible that button during reading and latching its state is in debounce state 0.
Re: External wakeup pin detect issue
Posted: Sat Jan 09, 2021 4:57 pm
by mattpellegrini
Had to read up on debouce, but it doesn't seem so complicated.
https://www.arduino.cc/en/Tutorial/Buil ... s/Debounce explains it well.
I guess the theory here is that the larger button causes spurious open/close transitions when pressed, for a longer period compared to the smaller button, so although it causes the transition to wake the board, at time of checking high pins it reads low. Have I understood what you're saying correctly?
Is there any way to modify the debounce behaviour of the chipset? Or is this unavoidable. (e.g that demo link above is writing it's own debounce method, but I suppose the debounce (if any) implemented on wake is not modifiable? I am very out of my depth here
The theory sounds very plausible, although it is 100% reproducible, that is, I never once get the correct pin (or anything other than 0) returned from
with the large button and always get pin 32 with the small button.
I have a project that sends a different mqtt message for different button presses and would very much like to not resort to using 1 ESP32 per button..
Re: External wakeup pin detect issue
Posted: Sun Jan 10, 2021 9:36 am
by mattpellegrini
https://circuitdigest.com/electronic-ci ... ce-circuit this was also good and suggests hardware solutions to bouncing. I may try to find such components to try it out. Unfortunately I'm just a software developer, so don't have an oscilloscope to check if the switch is bouncing. I am using exactly the switch the OP was too KW8-XILIE in case anyone wants to measure.
Re: External wakeup pin detect issue
Posted: Sun Jan 10, 2021 3:42 pm
by mattpellegrini
Finally,
https://www.allaboutcircuits.com/techni ... l-with-it/ gave some clear examples on hardware debouncing using just a capacitor and led to my solution. With a 104 100nF capacitor as shown on the link above, I was able to correctly determine the wake pin from the larger switches.