I made a clock with a mini weather station using a Arduino Nano, an DS3231 RTC, a DHT22 and displayed everything on a 20x4 LCD via an I2C interface. Everything worked perfectly when I was prototyping.
I then decided to make it permanent and moved it over to a Pro Mini, soldering everything to stripboard. When I was done, everything worked fine, except the DS3231 no longer kept time after a power loss. I double checked all my connections and obviously the code isn't the problem.
The DS3231 has a battery cell in it, but it should be noted that I didn't remove it while soldering and afterwards the open circuit voltage of the CR2032 was 3.6V, well above the normal spec. So, I replaced the cell with a new one and it still can't keep time after a power loss.
The RTC keeps time without a problem when powered. So I'm wondering if I messed up the battery back up while soldering and if there's no way to fix it.
When you say it no longer kept time, do you mean it reverted back to 1/1/1900, or whatever, or that it lost some time, or that you just couldn't read the time?
Are you using the ZS-042 module for the DS3231? If so, you might try disabling the "charging" circuit - remove either the diode or the resistor.
The battery positive terminal should be connected to pin 14 of the DS3231, and of course the negative terminal to ground.
If the RTC is just losing an amount of time equal to the power outage, it could be that the EOSC bit in the Control register isn't right. If that bit is high, the oscillator will stop when you switch to battery power.
@ShermanP, on power loss, the date and time resets to 00:00:00 01/01/2108, whether there is a battery cell in or not. So I can read the time without a problem, it just resets when there is no external power to the module.
I am not sure what module I am using, it simply says DS3231, but it looks almost exactly like the ZS-042. Here's a link to the product page from where I purchased it. https://www.robotics.org.za/DS3231-MOD It does specify a CR2032, but it could be wrong, because the 3.6V I measured on the cell.
I shall try desoldering the resistor or diode.
Update: I desoldered the diode and it made no difference.
@CrossRoads I have attached a diagram. It's not exactly as I have it in my project, but I did remove the RTC and put it back the breadboard with a Nano for debugging. The time and date is being printed to the serial monitor and it has the same problem of resetting on power loss.
When I prototyping on a breadboard for weeks, it worked without a problem. It didn't give me some weird date, or reset the date and time after a power loss. It just started doing this after I soldered everyhting on to stripboard. I guess I must have inadvertently broke it then.
My code is below.
#include <Wire.h> // Library for I2C communication #include "RTClib.h" // RTC Library from JeebLab
DS3231 rtc; // For DS3231 RTC
DateTime now;
int H, M, S, DD, MM, YY, Day;
void setup() {
// rtc.adjust(DateTime(DATE, TIME));
Serial.begin(9600); //setting the baud rate at 9600
Serial.println("Start");
}
void loop() {
now = rtc.now();
H = now.hour();
M = now.minute();
S = now.second();
DD = now.day();
MM = now.month();
YY = now.year();
Day = now.dayOfWeek();
if (H<10){Serial.print("0");} // Places a 0 in front when a number is less than 2 digits
Serial.print(H);
Serial.print(":");
if (M<10){Serial.print("0");} // Places a 0 in front when a number is less than 2 digits
Serial.print(M);
Serial.print(":");
if (S<10){Serial.print("0");} // Places a 0 in front when a number is less than 2 digits
Serial.print(S);
Serial.print(" ");
if (DD<10){Serial.print("0");} // Places a 0 in front when a number is less than 2 digits
Serial.print(DD);
Serial.print("/");
Serial.print(MM);
Serial.print("/");
Serial.println(YY);