External wakeup pin detect issue

hellraise007
Posts: 13
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: 249
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: 13
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: 13
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: 3
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.

Who is online

Users browsing this forum: Google [Bot] and 9 guests