Trouble getting ESP32-C3 to wakeup from deep sleep

Hello! I am trying to implement code for a EXT1 wake-up strategy for the ESP32-C3-MINI-1. I am using the Wokwi simulator to test since I have not yet received the Dev kit. However, I am unable to even get the board to wake-up from EXT0 strategy let alone EXT1. I am not sure what is wrong within the code. Any help is appreciated, thank you!

#define INTERRUPT_PIN 2
RTC_DATA_ATTR int bootCount = 0;

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

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  print_wakeup_reason();

  Serial.println("Starting");
  delay(2000);
  
  for(int i=3; i!=0; i--){
      Serial.println(i);
      delay(1000);
  }

  Serial.println("Going to sleep now");

  esp_deep_sleep_enable_gpio_wakeup(1 << INTERRUPT_PIN,
    ESP_GPIO_WAKEUP_GPIO_HIGH);
  esp_deep_sleep_start();

  Serial.println("This will never be printed");
}

void loop() { }

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;
  }
}

..seems to work if pinmode is changed to input.. before sleep mode..
..found this on another site..

  pinMode(INTERRUPT_PIN, INPUT); // seems necessary

  esp_deep_sleep_enable_gpio_wakeup(1 << INTERRUPT_PIN, ESP_GPIO_WAKEUP_GPIO_HIGH);
  esp_deep_sleep_start();

Thank you! The code does work as intended. The Wokwi simulator that I used just is not able to wake up the esp32-c3 from deep sleep so I have to test it with the physical module when I get a programmer. I just forgot to close this question! But thank you for your reply :slight_smile:

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