Waking ESP32 from deep sleep with 2 pins

Hello I am attempting to wake an esp32 from deep sleep using GPIOs 35 and 36 being pulled low. There is a great tutorial on this, but it requires some understanding of HEX which I don't have.

In the tutorial the author uses GPIO32 and 33 this apparently is a bitmask of 0x300000000 but I am having trouble understanding how to arrive at this conclusion?

The example code given is:

//Pushbuttons connected to GPIO32 & GPIO33
#define BUTTON_PIN_BITMASK 0x300000000

RTC_DATA_ATTR int bootCount = 0;

void setup(){
  Serial.begin(115200);
  delay(1000); 

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32
  print_wakeup_reason();

  //Configure GPIO32 & GPIO33 as ext1 wake up source for HIGH logic level
  esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);

  //Go to sleep now
  esp_deep_sleep_start();
}

void loop(){}

//Function that prints 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 1  : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case 2  : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case 3  : Serial.println("Wakeup caused by timer"); break;
    case 4  : Serial.println("Wakeup caused by touchpad"); break;
    case 5  : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.println("Wakeup was not caused by deep sleep"); break;
  }
}

bits0 - 7 = 00000000
bits8 - 15 = 00000000
bits16 - 23 = 00000000
bits 24 - 31 = 00000000
bits 32, 33 = 11
0x0300000000
plug that into your Windows calculator (Programmer mode)

Man it took me longer than I'll admit to understand this.. But I guess my bin, on the window's programmer calculator, is: 00011000 00000000 00000000 00000000 00000000 for active GPIO35 and 36. Since GPIO 0 is on the right and GPIO 39 is the farthest to the left. Making this hex in the calculator it is: 1800000000.

But where does the x come into play in your example and the tutorial? I don't see this on my calculator... 0x0300000000

Are you kidding me ?

0x in front of the number indicates it is written in hex.

B in front of the number indicates it is written in binary.

so B00000011 = 0x03

Each binary value is represented as 2 hex digits.

B0000 0011 B0000 0000 B0000 0000 B0000 0000 B0000 0000

=

0x03 0x00 0x00 0x00 0x00

In the documentation above the leading zero is omitted.

So

0x300000000

1 Like

@red_car I see thank you so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.