PCF8523 on Adafruit Assembled Data Logging Shield

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
miaotee
 
Posts: 12
Joined: Mon Aug 12, 2019 7:00 am

PCF8523 on Adafruit Assembled Data Logging Shield

Post by miaotee »

Hi,

Recently, I purchased an Adafruit Assembled Data Logging shield and METRO 328 for my project. And the programming for its own RTC (PCF8523) is following the guidance:

https://learn.adafruit.com/adafruit-dat ... time-clock
https://learn.adafruit.com/adafruit-pcf ... th-arduino

It works well when I upload my codes on the device, and takes the Date and Time according to the computer I am using.

However, when I disconnect it with my computer and run it using a battery, the start time is consistent with the time when I upload my code. For example, the time I upload my code to the device is 08:34:23, next time I use the device, the start time is still 08:34:23, even the exact time is 12:22:00.

Technically, the RTC should run with a coin cell even Arduino battery dies or is reprogrammed.

Could you please help me with this program?

Code: Select all

#include "RTClib.h"
#include <Wire.h>
 
RTC_PCF8523 RTC;

void setup(void)
{ 
  RTC.begin();
  RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));  
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
  }
}

void loop(void)
{
  DateTime now;
  now = RTC.now();
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
}

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: PCF8523 on Adafruit Assembled Data Logging Shield

Post by Franklin97355 »

You need to run this line only to set the time then remove it or comment it out in your code.

Code: Select all

  RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));

User avatar
miaotee
 
Posts: 12
Joined: Mon Aug 12, 2019 7:00 am

Re: PCF8523 on Adafruit Assembled Data Logging Shield

Post by miaotee »

franklin97355 wrote:You need to run this line only to set the time then remove it or comment it out in your code.

Code: Select all

  RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
Hi, Franklin

Thanks a lot for your reply.

I am still confused that once the code is uploaded and the device is disconnected with my computer, no matter how many times I run my device portablely, the start time is always constant.

Any comment from you? Thanks

Best wishes!

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: PCF8523 on Adafruit Assembled Data Logging Shield

Post by Franklin97355 »

As stated above remove the line of code.

User avatar
miaotee
 
Posts: 12
Joined: Mon Aug 12, 2019 7:00 am

Re: PCF8523 on Adafruit Assembled Data Logging Shield

Post by miaotee »

franklin97355 wrote:As stated above remove the line of code.
Hi, Franklin

Thanks a lot.

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

Return to “Clock Kits (discontinued)”