0

PCF8523 Not keeping time.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PCF8523 Not keeping time.

by malzel on Mon Nov 13, 2017 2:49 am

This problem is giving me a bit of a headache. The clock works fine when it's powered, and also after a VERY brief shutdown (about half a second) but anything past that and it resets to roughly the same date each time. I was originally having this issue with another sketch, but it displays the same behaviour with the library example provided in the documentation.

In the first picture, I set the time properly by removing the comment on:
Code: Select all | TOGGLE FULL SIZE
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
Uploading, then adding the comment again, and uploading once more. After powering off for 10 seconds, the clock is always out of sync, sometimes giving impossible values (35 hours in a day? hmm)

The connections for testing this are as follows:

GND -> Ground beside the RST pin on the pro mini
VCC -> VCC on the pro mini
SDA -> A4
SCL -> A5

I also have an RGB led strip connected to the Arduino, but removing that only makes the times even more ridiculous.

Code: Select all | TOGGLE FULL SIZE
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_PCF8523 rtc;

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

void setup () {

  while (!Serial) {
    delay(1);  // for Leonardo/Micro/Zero
  }

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.initialized()) {
    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__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 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(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
   
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
   
    // calculate a date which is 7 days, 12 hours and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));
   
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
   
    Serial.println();
    delay(3000);
}
Attachments
Before turning off.PNG
Before turning off.PNG (18.44 KiB) Viewed 68 times
Last edited by malzel on Mon Nov 13, 2017 2:55 am, edited 1 time in total.

malzel
 
Posts: 10
Joined: Tue Sep 05, 2017 10:32 pm

Re: PCF8523 Not keeping time.

by malzel on Mon Nov 13, 2017 2:50 am

After turning on again:
Attachments
After turning on.PNG
After turning on.PNG (19.01 KiB) Viewed 67 times

malzel
 
Posts: 10
Joined: Tue Sep 05, 2017 10:32 pm

Re: PCF8523 Not keeping time.

by malzel on Mon Nov 13, 2017 2:51 am

This one is the weirdest of all. Disconnected the RGB strip and all peripherals except for the RTC, and was gifted with this beauty.

If this clock is faulty I will just try my DS1307. Any help is appreciated.
Attachments
After turning on (no RGB).PNG
After turning on (no RGB).PNG (18.09 KiB) Viewed 67 times

malzel
 
Posts: 10
Joined: Tue Sep 05, 2017 10:32 pm

Re: PCF8523 Not keeping time.

by malzel on Fri Nov 17, 2017 12:57 am

Just an update - my DS1307 in the exact same setup, just with "PCF8523" swapped to "DS1307" in the code works perfectly. I think the clock is faulty.

malzel
 
Posts: 10
Joined: Tue Sep 05, 2017 10:32 pm

Please be positive and constructive with your questions and comments.