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
Deep sleep rtc
-
- Posts: 831
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Deep sleep rtc
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
https://github.com/lbernstone/NTP_sleep
https://docs.espressif.com/projects/esp ... modes.html
Re: Deep sleep rtc
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
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:
I put to sleep my esp with this code:
Has anyone encountered this problem?
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;
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();
Code: Select all
esp_sleep_enable_ext0_wakeup(GPIO_NUM_32, 0);
esp_deep_sleep_start();
Who is online
Users browsing this forum: No registered users and 32 guests