Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wake up from deep sleep zeroes RTC memory and will NOT report GPIO as a wake up #2

Open
bricomp opened this issue Jun 25, 2023 · 0 comments

Comments

@bricomp
Copy link

bricomp commented Jun 25, 2023

RTC variables are reset to zero when waking up from deep sleep, also esp_sleep_get_wakeup_cause() always returns zero.
The Teensy (3.1 or LC) is providing the reset signal.

Sketch

#define LED 8  // or use LED_BUILTIN for on-board LED
#define INTERRUPT_PIN 4
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("Going to blink the LED 10 times");
    blink(10);
    Serial.println("Going to sleep now");
    Serial.flush();  delay(50);
    esp_deep_sleep_enable_gpio_wakeup(1 << INTERRUPT_PIN,
        ESP_GPIO_WAKEUP_GPIO_LOW);
    esp_deep_sleep_start();

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

void loop() { }

void blink(int times) {
    for (int i = 0; i < times; i++) {
        digitalWrite(LED, HIGH);
        delay(1000);

        digitalWrite(LED, LOW);
        delay(1000);
        Serial.print("Blink ");
        Serial.println(i + 1);
    }
}

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

Debug Message

Port open
Boot number: 1
Wakeup was not caused by deep sleep: 0
Going to blink the LED 10 times
Blink 1
Blink 2
Blink 3
Blink 4
Blink 5
Blink 6
Blink 7
Blink 8
Blink 9
Blink 10
Going to sleep now
Port open
Boot number: 1
Wakeup was not caused by deep sleep: 0
Going to blink the LED 10 times
Blink 1
Blink 2
Blink 3
Blink 4
Blink 5
Blink 6
Blink 7
Blink 8
Blink 9
Blink 10
Going to sleep now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant