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

RTC clock counts minutes instead of days
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RTC clock counts minutes instead of days

by jefflawr on Mon Feb 17, 2020 5:20 pm

Hi,
I'm trying to use the real-time clock on an Adafruit Data Logger shield to generate data files named after the current date, like:
20_2_16.txt
The attached code reports a correct year, but month, day, hour and minute numbers are wrong. Oddly, day numbers increment every minute, resetting to zero after 59, and month numbers increment every hour.
The RTClib library is Adafruit's Version 1.3.3.
Please advise how I can get real days and months out of my DateTime objects.
Thanks,
Jeff
Jeff Lawrence


Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup() {
   Serial.begin(57600);
   rtc.begin();
}
void loop() {
    DateTime rtcNow = rtc.now();
    String nameString = "";
  /* shows problems with all details but year from rtc DateTimeobject */
    Serial.print(" rtcNow.year() = ");
    Serial.println(rtcNow.year(), DEC);
    Serial.print(" rtcNow.month() = ");
    Serial.println(rtcNow.month(), DEC);
    Serial.print(" rtcNow.day() = ");
    Serial.println(rtcNow.day(), DEC);
    Serial.print(" rtcNow.hour() = ");
    Serial.println(rtcNow.hour(), DEC);
    Serial.print(" rtcNow.minute() = ");
    Serial.println(rtcNow.minute(), DEC);
/* statement from 'timestamp' example sketch that shows the same problem with day and month numbering */
    Serial.println(String("DateTime::TIMESTAMP_DATE:\t")+rtcNow.timestamp(DateTime::TIMESTAMP_DATE));

   delay(5000);
}
}
jefflawr
 
Posts: 25
Joined: Thu Aug 01, 2013 2:24 pm

Re: RTC clock counts minutes instead of days

by adafruit_support_carter on Mon Feb 17, 2020 6:53 pm

Can you post some of the actual Serial Monitor output showing this.

adafruit_support_carter
 
Posts: 17179
Joined: Tue Nov 29, 2016 2:45 pm

Re: RTC clock counts minutes instead of days

by kcl1s on Mon Feb 17, 2020 7:34 pm

According to this page there are 2 versions of this shield. https://learn.adafruit.com/adafruit-data-logger-shield/using-the-real-time-clock Have you confirmed you have the one with the DS1307?

Fellow hobbyist
Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: RTC clock counts minutes instead of days

by jefflawr on Wed Feb 19, 2020 7:21 pm

Thanks for the comments. I'm using the newest shield and attach the output below. Are there rogue versions of the library where month/day are switched with hour/minute?
pretty baffling!
Jeff
(
Code: Select all | TOGGLE FULL SIZE
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
 rtcNow.year() = 2022
 rtcNow.month() = 10
 rtcNow.day() = 2
 rtcNow.hour() = 31
 rtcNow.minute() = 1
DateTime::TIMESTAMP_DATE:   2022-10-02
jefflawr
 
Posts: 25
Joined: Thu Aug 01, 2013 2:24 pm

Re: RTC clock counts minutes instead of days

by adafruit_support_carter on Wed Feb 19, 2020 7:56 pm

Did you follow the link above to verify which RTC you have? That's actually not a bad idea since there are different versions of the shield.

adafruit_support_carter
 
Posts: 17179
Joined: Tue Nov 29, 2016 2:45 pm

Re: RTC clock counts minutes instead of days

by jefflawr on Wed Feb 19, 2020 8:29 pm

As an aside, I bought this on Amazon, since Adafruit.com was out of stock. It is labeled Adafruit and looks like the description of the newer board and has the 2x3 SPI connections. Are there bogus or sketchy (sorry) boards on Amazon I should be watching out for?
jefflawr
 
Posts: 25
Joined: Thu Aug 01, 2013 2:24 pm

Re: RTC clock counts minutes instead of days

by kcl1s on Wed Feb 19, 2020 10:47 pm

If it is from Adafruit the link I posted shows what to look for to determine which version you have. It says the newer version rtc chip is more accurate. Post a photo of your board if you are unsure.

Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: RTC clock counts minutes instead of days

by jefflawr on Thu Feb 20, 2020 12:52 pm

Thanks Carter and Keith -
As you both guessed, I was using 1307 library with a PCF8523 rtc.
Once I started using the right object, the clouds parted and all was well!
I appreciate the help.
Jeff
jefflawr
 
Posts: 25
Joined: Thu Aug 01, 2013 2:24 pm

Re: RTC clock counts minutes instead of days

by adafruit_support_carter on Thu Feb 20, 2020 12:58 pm

Cool. Glad that fixed it. It might be that the Amazon link is selling newer boards but has older documentation? But that link to the Adafruit guide has the good info. Also good if maybe someone is still selling back stock of the older rev model.

Good eye, Keith!

adafruit_support_carter
 
Posts: 17179
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.