Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

PCF8523 on Adafruit Assembled Data Logging Shield
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PCF8523 on Adafruit Assembled Data Logging Shield

by miaotee on Thu Sep 12, 2019 10:52 pm

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 | TOGGLE FULL SIZE
#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('"');
}

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

Re: PCF8523 on Adafruit Assembled Data Logging Shield

by franklin97355 on Thu Sep 12, 2019 11:28 pm

You need to run this line only to set the time then remove it or comment it out in your code.
Code: Select all | TOGGLE FULL SIZE
  RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));

franklin97355
 
Posts: 21586
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: PCF8523 on Adafruit Assembled Data Logging Shield

by miaotee on Thu Sep 12, 2019 11:39 pm

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 | TOGGLE FULL SIZE
  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!

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

Re: PCF8523 on Adafruit Assembled Data Logging Shield

by franklin97355 on Thu Sep 12, 2019 11:45 pm

As stated above remove the line of code.

franklin97355
 
Posts: 21586
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: PCF8523 on Adafruit Assembled Data Logging Shield

by miaotee on Fri Sep 13, 2019 2:11 am

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

Hi, Franklin

Thanks a lot.

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

Please be positive and constructive with your questions and comments.