DS3231 does not "remember" its setup.

I implemented RTC (DS3231) in my Arduino project the first time.
RTC is connected to SDA(A4) and SCL(A5) of Arduino Uno R3 board.
RTC library by NeiroN is in use.

The initial Date/Time set of RTC was done by the following code, similar to one from examples:

// Date and time functions using just software, based on millis() & timer

#include <Arduino.h>
#include <Wire.h> // this #include still required because the RTClib depends on it
#include "RTClib.h"

RTC_Millis rtc;

void setup () {
Serial.begin(115200);
// following line sets the RTC to the date & time this sketch was compiled
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
rtc.begin(DateTime(DATE, TIME));
rtc.adjust(DateTime(2018, 11, 12, 21, 03, 0));
}

void loop () {
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();

delay(3000);
}

The output in Serial Monitor was as expected:

2018/11/12 21:03:06
2018/11/12 21:03:09
2018/11/12 21:03:12
...

My next sketch was uploaded to begin some evaluations of RTC.
Its code is the following:

//20Oct2018 - Modification to 16x2 LCD
#include <Arduino.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h> // this #include still required because the RTClib depends on it
#include "RTClib.h"

RTC_Millis rtc;

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.begin(16, 2);

}

void loop() {
// put your main code here, to run repeatedly:
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();
delay(2000);

}

And its results on Serial Monitor were very strange:

2106/2/6 6:28:16
2106/2/6 6:28:18
2106/2/6 6:28:20
2106/2/6 6:28:22
2106/2/6 6:28:24
2106/2/6 6:28:26
2106/2/6 6:28:28
...

Please give me some tip, what may be wrong.
Thanks.

How are you powering the RTC?

econjack:
How are you powering the RTC?

There is standard Lithium CR2032 inside.
Vcc is connected to Arduino's 5v connector.
GND is connected to Arduino's GND connector.

Reuven2018:
There is standard Lithium CR2032 inside.

Cannot see how there is room inside the DS3231 IC to fit a CR2032 Lithium battery.

Do you actually mean you have a PCB module that uses a DS3231 IC and that the PCB has a CR2032 battery on it ?

Reuven2018:
// Date and time functions using just software, based on millis() & timer

RTC_Millis rtc;

Are you sure you're actually using the hardware RTC? Shouldn't you be instantiating an object of the DS3231 class?

I don't see "RTC.begin" in your second code.

outsider:
I don't see "RTC.begin" in your second code.

You are genius! :slight_smile:

It was really forgotten and it was a problem! Now it is working properly.

2018/11/12 23:22:41
2018/11/12 23:22:43
2018/11/12 23:22:45

Thank a lo-o-t! :))

Yep, sometimes the janitor sees things the company president doesn't, 'cause he's looking from a lower level. :slight_smile:

BTW, your code works fine for me on an Uno board WITHOUT an RTC connected. You may be fooling yourself. See Reply #4.