RTC Incorrect day, date and time ?

Hi,

Here is my rtc display in the monitor screen. Wed 26/6/19 at 14:28. As you can see its not accurate. Im using an Arduino mega 2560 and XC4536, (its a data logger shield from Jaycar using RTC_DS1307 and SD card reader).

I have jumped the pins a4 & a5 to the mega 20 & 21. Thats all I have connected at the moment.

The clock is counting the seconds, but day, date and time are incorrect.

Tuesday 19/15/2099 45:3:21
Tuesday 19/15/2099 45:3:22
Tuesday 19/15/2099 45:3:23
Tuesday 19/15/2099 45:3:24
Tuesday 19/15/2099 45:3:25
Tuesday 19/15/2099 45:3:26
Tuesday 19/15/2099 45:3:27
Tuesday 19/15/2099 45:3:28
Tuesday 19/15/2099 45:3:29
Tuesday 19/15/2099 45:3:30
Tuesday 19/15/2099 45:3:31
Tuesday 19/15/2099 45:3:32
Tuesday 19/15/2099 45:3:33

Here’s the code I was using:-

// libraries
#include <Wire.h>
#include <RTClib.h>

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”};

void setup () {

Serial.begin(57600);
if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}

if (! rtc.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));
}
}

void loop () {
DateTime now = rtc.now();
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(’\t’);
Serial.print(now.day(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.year(), DEC);
Serial.print(’\t’);
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
Serial.println();

delay(1000);
}

Could anyone provide any assistance please. Im using a Mac, and have checked the clock. My PC time and date is not Tuesday the 19/15/2099, 45:3:33.

I’ve also bent the pins open the shield a4 a5 so they don’t connect to the mega and I get the same result on the monitor if they are connected or not with the jumper wire in to 20 & 21.

When a rtc chip leaves the factory, it usually does not have correct date and time. You need to set it once.

Did you initially run a sketch that did set the date and time?

Hi thanks for the reply.

I thought this line of code set the date and time:-

rtc.adjust(DateTime(F(DATE), F(TIME)));

I'll do some more research around setting date and time, later this afternoon.

Thanks.

Sorry, I missed that line. That date and time are the time that the sketch was compiled. Resetting the Arduino will result in the rtc being set to that date and time again.

But that does not explain what you see and at this time I don't have an explanation.

The first time you ran the sketch, did you get the "RTC is NOT running!" message on the serial monitor? The sketch only sets the time if it detects the RTC had been stopped (unpowered) at some point.

Simple test would be to remove power to the arduino, remove the battery from the RTC, then reinsert the battery and power up the arduino and see if it will set the correct time.

Hi all,

Thanks for the assistance.

I removed the power and then the battery for 10 seconds.

While battery removed I put a fluke meter across it & measured 3 Volts.

I reinserted the battery and received the same nonsense as before.

It got the better of me and I bought a rtc expansion board on its own, and reran the code and hey presto, it works, so the data logger shield must of been faulty??? I am assuming...?

Here's what I got tonight at 8.44 PM:-

Wednesday 26/6/2019 20:44:54 Wednesday 26/6/2019 20:44:55 Wednesday 26/6/2019 20:44:56 Wednesday 26/6/2019 20:44:57 Wednesday 26/6/2019 20:44:57 Wednesday 26/6/2019 20:44:58 Wednesday 26/6/2019 20:44:59 Wednesday 26/6/2019 20:45:0 Wednesday 26/6/2019 20:45:1 Wednesday 26/6/2019 20:45:2 Wednesday 26/6/2019 20:45:3 Wednesday 26/6/2019 20:45:4 Wednesday 26/6/2019 20:45:5 Wednesday 26/6/2019 20:45:6