Deep sleep rtc

terumi
Posts: 6
Joined: Mon Sep 07, 2020 12:01 am

Deep sleep rtc

Postby terumi » Sun Oct 04, 2020 12:34 pm

Hello people,
Im trying to make a device that falls into deep sleep after a button press.
That device will wake up after another press of the same button, so I attach and detach an gpio interrupt to the wakeup and sleep function of the esp.
What I want to achieve is to have a variable that gets incremented every one second so I can know how much time has elapsed since the device first was powered.
Now, I think that I could make a wakeup timer to wake up the esp every second, increment a variable, and put the esp to sleep again, but I think that this is not a good solution.
Does anybody know another method?

Thank you

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: Deep sleep rtc

Postby lbernstone » Sun Oct 04, 2020 2:06 pm

The esp32 includes an RTC that can work during deep sleep. Why not use that? It will not be enabled by default if you use just a gpio wakeup, but it is easy to add a deep sleep wakeup timer in addition to your button. You probably need to ensure it wakes up once a day to sync the time anyhow.
https://github.com/lbernstone/NTP_sleep
https://docs.espressif.com/projects/esp ... modes.html

terumi
Posts: 6
Joined: Mon Sep 07, 2020 12:01 am

Re: Deep sleep rtc

Postby terumi » Tue Oct 06, 2020 6:54 pm

Hello again,
I tried to use RTC during sleeP and what it does is that it starts be getting the computer time and after a sleep-wake up cycle it starts counting time from the time esp32 was flashed.

On setup I have this piece of code

Code: Select all

 
 if (!powered)
    {
        Serial.println("initialized the clock!");
        rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
    }
    powered = true;
 
That takes my computer time and "flashes" it to the esp rtc only if the esp32 came from a reset (the powered variable gets initialized in the rtc (persistent) memory as false, and then it is toggled to true and thus does not allow the rtc.begin(DateTime(F(__DATE__), F(__TIME__))); to run again.

After that, I'm calling this function to print the time:

Code: Select all

    DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
I put to sleep my esp with this code:

Code: Select all

 esp_sleep_enable_ext0_wakeup(GPIO_NUM_32, 0);            
esp_deep_sleep_start();
Has anyone encountered this problem?

Who is online

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