• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

RTC resets on esp32 deep sleep

Q&A Forum › Category: ESP32 › RTC resets on esp32 deep sleep
0 Vote Up Vote Down
Jack Douglas asked 3 years ago
Question Tags: RTC
12 Answers
0 Vote Up Vote Down
Jack Douglas answered 3 years ago

I am putting an esp32 to sleep periodically while employing a real time clock per the guide
https://randomnerdtutorials.com/guide-for-real-time-clock-rtc-module-with-arduino-ds1307-and-ds3231/
The clock is keeping time, however, it resets after each sleep period.  How to solve this?

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
Does your RTC have a battery?
Do you have some sort of code to adjust the time? Remember that every time the ESP wakes up, it will run the code from the start. If you have some lines to adjust or reset the timer, they will run every time after the ESP wakes up.
Regards,
Sara

0 Vote Up Vote Down
Jack Douglas answered 3 years ago

Yes, it has a battery which I confirmed to be charged.  I actually have two RTCs that exhibit the same behavior.
I am using the RNT RTC guide code.  The reset/time calibration statement is commented out after it is calibrated.
I am using the RNT deep sleep code from Project 4, modified w/o LoRa and using MQTT.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

When you say the timer resets, what happens exactly? What do you get in the Serial Monitor?

0 Vote Up Vote Down
Jack Douglas answered 3 years ago

It keeps updating the time as expected, but once it sleeps and wakes up, it resets to the reset time.  For example,

Time(s) = 11
9:57:11 25/10/22 Day of week: Tuesday
Connecting to xxxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -65 dB
soilMoisture: 1184
Moisture: 27.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
Time(s) = 14
9:57:14 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -64 dB
soilMoisture: 1191
Moisture: 26.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
Time(s) = 18
9:57:18 25/10/22 Day of week: Tuesday
Connecting to xx

Then after it sleeps –

Time(s) = 44
9:57:44 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -64 dB
soilMoisture: 1178
Moisture: 29.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
DONE! Going to sleep now.
⸮M⸮\⸮bά⸮$g⸮Time(s) = 0
9:57:00 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp

 

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Can you share your code? Or the snippets of code that deal with time and deep sleep?
To share a code use pastebin or github.
Regards,
Sara

0 Vote Up Vote Down
Jack Douglas answered 3 years ago

Ok thanks.  Here it is. The code uses the esp32 Project 4 w/o LoRa, but with RPi broker/subscriber to send MQTT from esp32 with temp/moisture topics.  But I want to additionally and periodically save data to a SD Card, It would sleep then wake at a certain time, open the file and send mqtt to RPi.  The code is not finished yet, so now just trying to sort out the clock part.
https://pastebin.com/r54cBJY6

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi again.
You pasted the code in private. It’s not in the public domain.
Make sure you enable access to the link so that I can check the code.
Regards,
Sara
 

0 Vote Up Vote Down
Jack Douglas answered 3 years ago

Apologies, I thought I had done that.  It should be good now.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
After a quick search, I found this: https://forum.arduino.cc/t/the-ds3231-rtc-module-does-not-retain-the-time-everytime-i-powered-off-or-reset/563465/4
Check if adding those lines solves the issue.
Regards,
Sara

0 Vote Up Vote Down
Jack Douglas answered 3 years ago

Thanks very much.  This solved the issue.
By the way, it came down to adding the following statement, which is missing in the code by J Boxall in the RNT RTC guide.

Wire.write(0b00011100); // write register bitmap, bit 7 is /EOSC
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Great. Thanks.
I’ll fix the tutorial soon.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.