PCF8523 Not keeping time.

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
malzel
 
Posts: 10
Joined: Tue Sep 05, 2017 10:32 pm

PCF8523 Not keeping time.

Post by malzel »

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

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

// 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 1429 times
Last edited by malzel on Mon Nov 13, 2017 2:55 am, edited 1 time in total.

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

Re: PCF8523 Not keeping time.

Post by malzel »

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

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

Re: PCF8523 Not keeping time.

Post by malzel »

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 1428 times

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

Re: PCF8523 Not keeping time.

Post by malzel »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”