External wakeup pin detect issue

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

External wakeup pin detect issue

Postby hellraise007 » Tue Aug 06, 2019 6:33 am

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.
  1. void wake_up_pin()
  2. {
  3.   esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
  4.   int GPIO_reason = esp_sleep_get_ext1_wakeup_status();
  5.   if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1)
  6.   {
  7.     Serial.println("Waked up ext1");
  8.     int k=(int)(log(GPIO_reason)/log(2));
  9.     switch (k)
  10.     {
  11.     case 2:
  12.       button[0].numberKeyPresses++;
  13.       Serial.printf("Button 1 has been pressed %u times\n", button[0].numberKeyPresses);
  14.       break;
  15.     case 15:
  16.       button[1].numberKeyPresses++;
  17.       Serial.printf("Button 2 has been pressed %u times\n", button[1].numberKeyPresses);
  18.       break;
  19.     case 25:
  20.       button[2].numberKeyPresses++;
  21.       Serial.printf("Button 3 has been pressed %u times\n", button[2].numberKeyPresses);
  22.       break;
  23.     case 26:
  24.       button[3].numberKeyPresses++;
  25.       Serial.printf("Button 4 has been pressed %u times\n", button[3].numberKeyPresses);
  26.       break;
  27.     case 27:
  28.       button[4].numberKeyPresses++;
  29.       Serial.printf("Button 5 has been pressed %u times\n", button[4].numberKeyPresses);
  30.       break;
  31.     default:
  32.       Serial.println(k);
  33.       break;
  34.     }
  35.   }
  36. }
  37.  
  38. setup()
  39. {
  40.   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);
  41. esp_deep_sleep_start();
  42. }

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: External wakeup pin detect issue

Postby boarchuz » 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.

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

Re: External wakeup pin detect issue

Postby hellraise007 » Wed Aug 07, 2019 6:46 am

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
  1.  
  2.  
  3. RTC_DATA_ATTR int bootCount = 0;
  4.  
  5. /*
  6. Method to print the reason by which ESP32
  7. has been awaken from sleep
  8. */
  9. void print_wakeup_reason(){
  10.   esp_sleep_wakeup_cause_t wakeup_reason;
  11.  
  12.   wakeup_reason = esp_sleep_get_wakeup_cause();
  13.  
  14.   switch(wakeup_reason)
  15.   {
  16.     case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
  17.     case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
  18.     case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
  19.     case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
  20.     case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
  21.     default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
  22.   }
  23. }
  24.  
  25. void print_GPIO_wake_up(){
  26.   int GPIO_reason = esp_sleep_get_ext1_wakeup_status();
  27.   Serial.print("GPIO that triggered the wake up: GPIO ");
  28.   Serial.println((log(GPIO_reason))/log(2), 0);
  29. }
  30. void setup(){
  31.   Serial.begin(115200);
  32.   delay(1000); //Take some time to open up the Serial Monitor
  33.  
  34.   //Increment boot number and print it every reboot
  35.   ++bootCount;
  36.   Serial.println("Boot number: " + String(bootCount));
  37.  
  38.   //Print the wakeup reason for ESP32
  39.   print_wakeup_reason();
  40.   print_GPIO_wake_up()
  41.   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);
  42.  
  43.  
  44.  
  45.   //Go to sleep now
  46.   Serial.println("Going to sleep now");
  47.   delay(1000);
  48.   esp_deep_sleep_start();
  49.   Serial.println("This will never be printed");
  50. }
  51.  
  52. void loop(){
  53.   //This is not going to be called
  54. }
  55.  
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.

hellraise007
Posts: 16
Joined: Tue Aug 06, 2019 6:18 am

Re: External wakeup pin detect issue

Postby hellraise007 » Mon Aug 26, 2019 11:05 am

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.

Rudy12
Posts: 4
Joined: Wed May 08, 2019 2:00 am

Re: External wakeup pin detect issue

Postby Rudy12 » Tue Sep 03, 2019 5:42 pm

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.

mattpellegrini
Posts: 4
Joined: Fri Jan 08, 2021 6:01 pm

Re: External wakeup pin detect issue

Postby mattpellegrini » Fri Jan 08, 2021 6:45 pm

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.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: External wakeup pin detect issue

Postby chegewara » Sat Jan 09, 2021 7:40 am

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.

mattpellegrini
Posts: 4
Joined: Fri Jan 08, 2021 6:01 pm

Re: External wakeup pin detect issue

Postby mattpellegrini » Sat Jan 09, 2021 4:57 pm

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

Code: Select all

esp_sleep_get_ext1_wakeup_status
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..

mattpellegrini
Posts: 4
Joined: Fri Jan 08, 2021 6:01 pm

Re: External wakeup pin detect issue

Postby mattpellegrini » Sun Jan 10, 2021 9:36 am

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.

mattpellegrini
Posts: 4
Joined: Fri Jan 08, 2021 6:01 pm

Re: External wakeup pin detect issue

Postby mattpellegrini » Sun Jan 10, 2021 3:42 pm

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.

Who is online

Users browsing this forum: No registered users and 118 guests