Coder Social home page Coder Social logo

makuna / rtc Goto Github PK

View Code? Open in Web Editor NEW
363.0 363.0 127.0 312 KB

Arduino Library for RTCs, Ds1302, Ds1307, Ds3231, Ds3232, Ds3234 and Pcf8563/BM8563 with deep support. Please refer to the Wiki for more details. Please use the Github Discussions to ask questions as the GitHub Issues feature is used for bug tracking.

License: GNU Lesser General Public License v3.0

C++ 98.13% C 1.87%
arduino-library bm8563 ds1302 ds1307 ds3231 ds3234 pcf8563 rtc

rtc's People

Contributors

adrianotiger avatar dstoiko avatar gijsn avatar haberturdeur avatar ivankravets avatar makuna avatar mrwgx3 avatar retsifp avatar sardashti avatar seth-- avatar techi602 avatar thijstriemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtc's Issues

DateTime persistent in RTC?

Hi,
I have a tiny RTC with a DS3231(with battery), using on RaspPi3 works fine, after restarting the Pi, RTC clock shows correct current datetime.
But its different when i use it with a NodeMCU v2 with the following code:

#include <Wire.h>       //I2C library
#include <RtcDS3231.h>  //RTC library

RtcDS3231<TwoWire> rtcObject(Wire);
volatile int setRtc = 0;
const int interruptPin = 0; //GPIO 0 (Flash Button)

void handleInterrupt() {
  detachInterrupt(interruptPin);
  setRtc = 1;
}

void setup() {
  Serial.begin(115200);
  rtcObject.Begin();
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
}
 
void loop() {
  if (setRtc == 1) {
    rtcObject.SetDateTime(RtcDateTime(18, 02, 05, 18, 0, 0));
    setRtc = 0;
    Serial.println("rtc was set");
  }
  RtcDateTime currentTime = rtcObject.GetDateTime();
  char str[19];
  sprintf(str, "%04d-%02d-%02d %02d:%02d:%02d",
          currentTime.Year(), currentTime.Month(), currentTime.Day(),
          currentTime.Hour(), currentTime.Minute(), currentTime.Second()
         );
  Serial.println(str);
  delay(1000);
}

After a pause of around 20sec (unplug from power) when I restart the Esp8266 again, then the RTC clock starts with a delay of 20sec.
Maybe I have overseen sth. Whats is needed that the RTC shows current dateitime also when the ESP is not powered in the meantime? Any help is appreciated.
Best regards,
Nic

Interrupt on uneven time events, e.g. after 5 minutes, 5 hours, etc.

Dear Makuna,

Thank you for providing us with such a great library. I have been using it nicely on my ATMega328P to call an interrupt service routine each minute using following code:
[code] DS3231AlarmTwo alarm2(
0,
0,
0,
DS3231AlarmTwoControl_OncePerMinute);
Rtc2.SetAlarmTwo(alarm2);[/code]

To reduce the power consumption further, I'd like to go for an interrupt each 5 minutes. Is that possible to realize with your library?
In that example, it works:
https://forum.arduino.cc/index.php?topic=460850.0

Best and thank you. Please tell me if it is better to post it on gitter.
Marco

Class 'RtcTemperature' / RtcDS3231::GetTemperature() Rework Needed

Hi Makuna

Enjoyed studying your RtcDS3231 library; I found your use of classes and templates most instructive. While studying the temperature processing code, however, I became most puzzled on how raw temperature was converted to a float. A side-by-side comparison of the D3231 datasheet and your code lead me to realize that the rather ambiguous description of the temperature register function admits (2) plausible interpretations:

Temperature Registers (11h–12h)
Temperature is represented as a 10-bit code with a resolution of 0.25°C and is accessible at
location 11h and 12h. The temperature is encoded in two’s complement format. The upper 8 bits,
the integer portion, are at location 11h and the lower 2 bits, the fractional portion, are
in the upper nibble at location 12h. For example, 00011001 01b = +25.25°C.

The 1st interpretation is that the upper and lower registers reflect a 16-bit wide 2's complement number, which reflects the temperature scaled by a factor of 256.

The 2nd case would be that the upper byte is an 8-bit 2's complement number representing a signed integer temperature of range -128 to 127, and the lower byte is an 8-bit unsigned integer holding a scaled fractional portion, 256 * { 0.00, 0.25, 0.50, 0.75 } = {0x00, 0x40, 0x80, 0xC0 }.

The bit diagrams accompanying the register description support the former, and the example within the description, the latter (too bad the example wasn't signed).

In order the resolve the issue, both interpretations were coded, and a dusty can of freeze spray was dug out of the closet. After cooling the RTC to some negative temperature, the correct interptation should show a monotonically increasing sequence of numbers as the part warms up. The 1st interpretation, the scaled 16-bit 2's complement temperature, won the day. The test code which generated the table below is included at the end of this post.

Column     Interpretion / Description                      Function
------------------------------------------------------------------------------
  A        original library code                           AsFloat()
  B        test code,  8-bit int/uint interpretation       AsFloatTestA()
  C        test code, 16-bit 2's complement word           AsFloatTestB()
  D        tweaked library code, added after initial test  AsFloat(), modified 

-12 degC  through -10 degC
--------------------------
   A        B           C        D
-12.00   -12.00      -12.00   -12.00    degC
-12.25   -12.25      -11.75   -11.75    degC
-12.50   -12.50      -11.50   -11.50    degC
-12.75   -12.75      -11.25   -11.25    degC
-11.00   -11.00      -11.00   -11.00    degC
-11.25   -11.25      -10.75   -10.75    degC
-11.50   -11.50      -10.50   -10.50    degC
-11.75   -11.75      -10.25   -10.25    degC
-10.00   -10.00      -10.00   -10.00    degC

Transition through 0 degC
-------------------------
  A       B          C        D
-1.00   -1.00      -1.00   -1.00    degC
-1.25   -1.25      -0.75   -0.75    degC
-1.50   -1.50      -0.50   -0.50    degC
-1.75   -1.75      -0.25   -0.25    degC

0.00   0.00      0.00   0.00    degC      Above 0 degC, all cases the same
0.25   0.25      0.25   0.25    degC
0.50   0.50      0.50   0.50    degC
0.75   0.75      0.75   0.75    degC
1.00   1.00      1.00   1.00    degC

Interestingly enough, the library code only requires a minor tweak to function correctly:

// Corrected 'AsFloat()' routine
   float AsFloatTestC ( RtcTemperature& rtmp )
   {
      float degrees = (float)rtmp.AsWholeDegrees();;
      degrees += (float)rtmp.GetFractional() / 100.0f ;
      return( degrees );
   
   } //AsFloatTestC

versus

   float AsFloat()
   {
      float degrees = (float)integerDegrees;
      degrees += (float)decimalFraction / ((degrees < 0) ? -100.0f : 100.0f) ;
      return degrees;
   }

It would probably make more sense, however, to change GetTemperature() to return raw register values and rewrite class RtcTemperature to support those changes.

In closing, Lakuna, thanks again for your fine work!

PS: Mention @smz

Test Sketch

// CONNECTIONS:
// DS3231 SDA --> SDA
// DS3231 SCL --> SCL
// DS3231 VCC --> 3.3v or 5v
// DS3231 GND --> GND

#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif

/* for software wire use below
#include <SoftwareWire.h>  // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>

SoftwareWire myWire(SDA, SCL);
RtcDS3231<SoftwareWire> Rtc(myWire);
 for software wire use above */

/* for normal hardware wire use below */
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
RtcDS3231<TwoWire> Rtc(Wire);
/* for normal hardware wire use above */

void setup () 
{
  Serial.begin(115200);
  while (!Serial) delay(250);      // Wait until Arduino Serial Monitor opens
  Serial.println( " " );
  Serial.println(F("DS3231_Simple Temperature Test"));

    Serial.print("compiled: ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);

    //--------RTC SETUP ------------
    Rtc.Begin();

    // if you are using ESP-01 then uncomment the line below to reset the pins to
    // the available pins for SDA, SCL
    // Wire.begin(0, 2); // due to limited pins, use pin 0 and 2 for SDA, SCL

    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
    printDateTime(compiled);
    Serial.println();

    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) first time you ran and the device wasn't running yet
        //    2) the battery on the device is low or even missing

        Serial.println("RTC lost confidence in the DateTime!");

        // following line sets the RTC to the date & time this sketch was compiled
        // it will also reset the valid flag internally unless the Rtc device is
        // having an issue

        Rtc.SetDateTime(compiled);
    }

    if (!Rtc.GetIsRunning())
    {
        Serial.println("RTC was not actively running, starting now");
        Rtc.SetIsRunning(true);
    }

    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled) 
    {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
    else if (now > compiled) 
    {
        Serial.println("RTC is newer than compile time. (this is expected)");
    }
    else if (now == compiled) 
    {
        Serial.println("RTC is the same as compile time! (not expected but all is fine)");
    }

    // never assume the Rtc was last configured by you, so
    // just clear them to your needed state
    Rtc.Enable32kHzPin(false);
    Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); 
} //setup

// Temperature test loop
void loop () 
{
    if (!Rtc.IsDateTimeValid()) 
    {
        // Common Cuases:
        //    1) the battery on the device is low or even missing and the power line was disconnected
        Serial.println("RTC lost confidence in the DateTime!");
    }

//  Force a temperature A/D read
    Rtc.ForceTemperatureCompensationUpdate( true );

//  Get the temperature data    
    RtcTemperature temp = Rtc.GetTemperature();

    Serial.print (temp.AsFloat() );         // Column A: Original library code
    Serial.print( "   " );

    Serial.print( AsFloatTestA( temp ) );   // Column B: Int/frac Temp. calc.       
    Serial.print( "      " );

    Serial.print( AsFloatTestB( temp ) );   // Column C: 2's comp. temp. calc.
    Serial.print( "   " );
    
    Serial.print( AsFloatTestC( temp ) );   // Column D: Corrected original code
    Serial.print( "    " );
    
    Serial.print( "degC" );
    Serial.println();

    delay(50);
        
} //loop

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
    char datestring[20];

    snprintf_P(datestring, 
            countof(datestring),
            PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
            dt.Month(),
            dt.Day(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
    Serial.print(datestring);
} //printDateTime

// Calculate temperature as if:
//
//  a) The upper temperature byte represents a signed single-byte integer
//     of range -128 to +127
//  b) The lower temperature byte represents an un-signed fractional part
//     representing  0, 1/4, 1/2 and 3/4 degrees.
//  
//     The number of right-shifts required to register the lower byte with
//     the upper one is 8, corresponding to a scale factor of 256.
//
//    bit:  7  6  5  4  3  2  1  0 -1 -2      7  6  5  4  3  2  1  0 -1 -2
//          b  b  0  0  0  0  0  0  0  0  ->  0  0  0  0  0  0  0  0  b  b
//
//     It easier to right-shift the upper-byte 8 times and leave the lower-byte as is.
//
float AsFloatTestA ( RtcTemperature& rtmp )
{
// Retrieve 'signed' integer temp. value
   int8_t   deg = rtmp.AsWholeDegrees();

// Reverse libary scaling to recover 'unsigned' fractional temp. value   
   uint8_t frac = ( (rtmp.GetFractional() / 25) << 6 );

// Scale integer portion to match fractional term  
   int16_t  sgnT = ( (uint8_t)deg << 8 );

// Take absolute value of integer degC & add 'unsigned' fractional term
   bool  negT = false;
   if ( sgnT < 0 )
      { sgnT = -sgnT; negT = true; }
   sgnT += frac;

// Restore sign of combined result, unscale and return as float
   if ( negT ) sgnT = -sgnT;
   return( (float)sgnT / 256.0 );

} //AsFloatTestA


// Calculate temperature as if...
//
// The upper and lower bytes represent the MS and LS bytes of a
// 16-bit, 2's complement WORD.
//
// The number of right-shifts needed to scale this signed 16-bit integer
// to float degrees is 8, or 256
//
//  15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 -1 -2
//   S  d  d  d  d  d  d  d  d  d  0  0  0  0  0  0  0  0   before shift
//   S  S  S  S  S  S  S  S  S  d  d  d  d  d  d  d  d  d   after  shift
//
//  It easier to right-shift the upper-byte 8 times and leave the lower-byte as is.
//
float AsFloatTestB ( RtcTemperature& rtmp )
{
// Retrieve MS portion of 2's comp. temperature
   int8_t   msbyte = rtmp.AsWholeDegrees();

// Reverse libary scaling to recover LS portion
   uint8_t lsbyte = ( (rtmp.GetFractional() / 25) << 6 );

   int16_t  itemp  = ( (uint8_t)msbyte << 8 ); // Scale upper byte, now 16-bit integer
            itemp += lsbyte;                   // Concant the lower byte
   return( (float)itemp / 256.0 );             // Un-scale and return
   
} //AsFloatTestB

// Corrected 'AsFloat()' routine
float AsFloatTestC ( RtcTemperature& rtmp )
{
   float degrees = (float)rtmp.AsWholeDegrees();;
   degrees += (float)rtmp.GetFractional() / 100.0f ;
   return( degrees );
   
} //AsFloatTestC

dayOf Sunday

Hi,

thanks for the library - i have a question about the dayOf

RtcDateTime dt = rtc.GetDateTime();
dt.DayOfWeek() // returns 0 on sunday and 6 on saturday

When i create a alarm with dayOf=0 for sunday the alarm is never triggered. If i instead use dayOf=7 for sunday the alarm is triggers.

DS3231AlarmOne alarm1(
    dayOf,       // day 0-6 > Sunday=0
    alarmHour,   // hour 0-23
    alarmMinute, // minute 0-59
    0,           // second 0-59
    DS3231AlarmOneControl_HoursMinutesSecondsDayOfWeekMatch);

So for alarms the following values are correct - but the dt.DayOfWeek() methods returns the value in the comments.

const byte Monday    = 1; //1
const byte Tuesday   = 2; //2
const byte Wednesday = 3; //3
const byte Thursday  = 4; //4
const byte Friday    = 5; //5
const byte Saturday  = 6; //6
const byte Sunday    = 7; //0 <-- diffrent

Bug, feature - or my mistake?

Control byte type casting

Type casting errors when calling Rtc.GetAlarmOne() or Rtc.GetAlarmTwo()

  • Win 10
  • Arduino IDE 1.8.7
  • ESP8266 Generic board
  • RTC library 2.3.2
src/RtcDS3231.h:477:48: error: invalid conversion from 'int' to 'DS3231AlarmOneControl' [-fpermissive]

             return DS3231AlarmOne(0, 0, 0, 0, 0);
src/RtcDS3231.h:513:45: error: invalid conversion from 'int' to 'DS3231AlarmTwoControl' [-fpermissive]

             return DS3231AlarmTwo(0, 0, 0, 0);

Need to add typecasting for control byte

        if (_lastError != 0)
        {
            return DS3231AlarmTwo(0, 0, 0, (DS3231AlarmTwoControl)0);
        }
        if (_lastError != 0)
        {
            return DS3231AlarmOne(0, 0, 0, 0, (DS3231AlarmOneControl)0);
        }

Issue in AsFloat() method

Hi,

I've detected an issue when calling the AsFloat() method to get the temperature from a RtcTemperature object.

The sum of the decimal and integer parts are being performed as if they are two integers. For example, if the integer part is 22 and the decimal 0.25, the output of the AsFloat() is 47.00.

If I call the AsWholeDegrees() and GetFractional() methods and perform the sum myself, it works fine.

I'm using a NodeMCU v2 for testing.

Best regards,
Nuno Santos
Blog: https://techtutorialsx.wordpress.com/

Problem setting time in DS3231 with NodeMCU

I am using Nodemcu with ds3231. While i use the Storeint program, the output in the serial monitor is given below.

E�ªiYªP�‚,jHRRY–¡VÕY¬µ�JW¥¡Õ¥Õš•YJªTE�uEZB\ÊH
!H�Yµ…I‹)VeWU ÖA…ðZ¬eA¬TYUeZ�!\“
Š*jU!\K
EKŠZ¬Õ±WT_¥�compiled: Jun 26 201809:57:54
06/26/2018 09:57:54
RTC lost confidence in the DateTime!
RTC was not actively running, starting now
85/165/2009 37:165:
Rtc ready for storage <<<

This is the result from the serial monitor. the date and time is set differently. When i used the same module with arduino mega, it was perfect but with using Nodemcu it is not perfect. But the ds3231 simple program is working fine (That is showing the date and time stored in ds3231). But adjusting the time is not fine with nodemcu.

RTC lost confidence in the DateTime! -165/165/2165 37:165

hi..
in 4 different boards, this error exists.
there was no problem a few months ago.

it may be because we are in 1504080845 timestamp? (the calculations are wrong)

i got confused.

esp8266-07
ds1307
SDA gpio4 (or 2)
SCL gpio5 (or 14)

DS1307_Simple.ino

photo_2017-08-30_12-36-14

…compiled: Aug 30 201712:16:59
08/30/2017 12:16:59
RTC lost confidence in the DateTime!
RTC was not actively running, starting now
RTC is older than compile time!  (Updating DateTime)
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!
165/165/2165 37:165
RTC lost confidence in the DateTime!

SDA pin:
gps00002

SCL pin:
gps00003

Can not change date and time

Hello!

Maybe I'm spupid, but I can not change the time and date in the chip. The current date value is read normally (seconds change), but attempts to write to the microcircuit do not change date and time. Tell me please what I'm doing wrong.

Thank you!

I'm use NodeMCU.

Code:
Init part:
#include <Wire.h>
#include <RtcDS3231.h>
RtcDS3231 Rtc(Wire);

setup(){
Wire.begin(3,1);
Rtc.Begin();
Rtc.Enable32kHzPin(false);
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
RtcDateTime setVal;
setVal = RtcDateTime(18, 4, 30, 11, 54, 0);
Rtc.SetDateTime(setVal);
}

loop(){
RtcDateTime now = Rtc.GetDateTime();
String retvalstr = printDateTime(now);
....... and another code........
}

I see date and time 01.01.2000 08:07:55 and time changes, ie the chip works

Impossible values in RtcDateTime. Month = 0 from RTC

Describe the bug
The library accepts all 0s in:
RtcDateTime(uint16_t year, uint8_t month, uint8_t dayOfMonth, uint8_t hour, uint8_t minute, uint8_t second)

RtcDateTime(uint16_t year,

... which is interpreted as the following date and time:
00/00/2000 00:00:00
with clear wrong day-of-month 0 of month 0.
The problem goes further as:
uint32_t RtcDateTime::TotalSeconds() const

returns: 1367256704 (which is greater than current century seconds)
Where does this number come from?
uint16_t days = DaysSinceFirstOfYear2000<uint16_t>(_yearFrom2000, _month, _dayOfMonth);

with arguments uint16_t 0,0, and 0 overflows when -1 (as int16_t) appears in:
return days + 365 * year + (year + 3) / 4 - 1;

and then it returns the value (uint16_t) 65535.
When it is further processed in:
return SecondsIn<uint32_t>(days, _hour, _minute, _second);

The value is casted to uint32_t and then multiplied in:
return ((days * 24L + hours) * 60 + minutes) * 60 + seconds;

which results in a value of 65535×24×60×60=5662224000, which overflows, again, the uint32_t that this function returns 5662224000 & 0xFFFFFFFF = 1367256704.

To Reproduce
This happened with the example DS1302_Simple.ino with the un-initialized DS1302 chip. When new (or after removing the back-up battery) this chip actually provides impossible day and month (0) values.
The script never updates the correct time because the comparison in:

if (now < compiled)

is never true.

Expected behavior
Although the main script could program what to do in this case, it seems natural that the library would be able to deal with and recover from these impossible values (which appear in the real-world scenario of removing-replacing the back-up battery).
I am unsure which approach would be best. Some options:

  • Probably the best: raise/return some error. Not easy, however, because the values are provided in the constructor. Afterwards, let the script deal with the error. Although it should be actively used, maybe just a member function that checks whether day or month are 0 would be enough, or (why not) a member function that checks that all values are in their sensible range. Something like:
    uint8_t Valid() const {return _dayOfMonth!=0 && month!=0;}
    or
uint8_t Valid() const {return month>=1 && month<=12 &&
_dayOfMonth>=1 && _dayOfMonth<=31 && // this could be more detailed
_hour<=23 && _minute<=59 && _second<=59;}

  • I do not know how the RTC adder will increment the month after 24h, or when the month will change. Assuming that both will increase to 1 after 24h and 31 days, then it would be sensible to interpret the date as 30th November 1999. After 24h it would be day 1 of month 0 of 2000 (1st December 1999). Not easy either, as the library can not hold dates before the year 2000, and also probably not worth working in this direction, as this date is never going to be used.
  • May be the most feasible thing. Also the most transparent, but certainly obscure behaviour, would be to automatically "correct" wrong values of 0 to 1 for day and month. Writing them back to the RTC. There could be a bool setting in the RTC constructor called "autocorrect", to always allow more conservative reads.

Development environment (please complete the following information):

  • OS: Linux
  • Build Environment: Arduino IDE v.1.8.3
  • Board target: ESP8266
  • Library version: v2.3.2

Minimal Sketch that reproduced the problem:
I checked the overflow problems with a c++ program:

#include <iostream>
const uint8_t c_daysInMonth[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
template <typename T> T DaysSinceFirstOfYear2000(uint16_t year, uint8_t month, uint8_t dayOfMonth)
{
    T days = dayOfMonth;
    for (uint8_t indexMonth = 1; indexMonth < month; ++indexMonth)
    {
        days += c_daysInMonth[indexMonth - 1];
    }
    if (month > 2 && year % 4 == 0)
    {
        days++;
    }
    return days + 365 * year + (year + 3) / 4 - 1;
}
template <typename T> T SecondsIn(T days, uint8_t hours, uint8_t minutes, uint8_t seconds)
{
    return ((days * 24L + hours) * 60 + minutes) * 60 + seconds;
}
uint32_t TotalSeconds(uint8_t _yearFrom2000, uint8_t _month, uint8_t _dayOfMonth,uint8_t _hour, uint8_t _minute, uint8_t _second)
{
    uint16_t days = DaysSinceFirstOfYear2000<uint16_t>(_yearFrom2000, _month, _dayOfMonth);
    return SecondsIn<uint32_t>(days, _hour, _minute, _second);
}
int main() {
  std::cout << TotalSeconds(0,0,0,0,0,0);
}

Additional context
Thank you for all your work.
Probably related to the last line of the OP in #60.

AsFloat won't compile

I have a sketch for Reading the temperature of an DS3231. It consists of the following lines:

#inlude <RtcDS3231.h>
//Create new RTC module object
RtcDS3231 rtcModule;
void UpdateTemp() {
// Read temperature
RtcTemperature rtcTemp = rtcModule.Get.Temperature();
temp = rtcTemp.AsFloat();
}

The compilation halts with the following remark:

exit status 1
'class RtcTemperature' has no member named 'AsFloat'

Help is highly appreciated
tuvebosse

GetIsRunning() returns 0 after SetDateTime from NTP event

Hi,

I'm periodically calling RTCDS3231.SetDateTime(RtcDateTime(year(), month(), day(), hour(), minute(), second())); in NTP time sync event handler to update RTC time from internet.
The problem is after such operation RTCDS3231.GetIsRunning() and 'RTCDS3231.IsDateTimeValid()' functions are starting to return FALSE status.
I've even tried to call RTCDS3231.SetIsRunning(true) after that but without any result.
RTC seems to initialize succesfully and returns right time just after boot.
What can be wrong?

Greetings,
robert

ESP8266 ESP-12F / Arduino IDE 1.6.12

Using memory at RTC3231

Makuna,

I am using nodemcu 1.0 with RTC3231 that has much greater precision than RTC1307.
I spent all the day trying to find out why my nodemcu 1.0 eeprom start to have problem to save some bytes. I just find out that the 10000 cycles it is supposed to hold on can be hold all together. I tried to program in a way that I save only one byte at time to save cycles, but it doesn't matter because it save it all together every time you do EEPROM.commit() or EEPROM.end(). I am telling you that because I just find out that the RTC3231 I am using with your lib RTC have one memory chip called AT24C32 that is a EEPROM with more than 1 million cycles.
I found that description for that chip:

The AT24C32/64 provides 32,768/65,536 bits of serial electrically erasable and programmable
read only memory (EEPROM) organized as 4096/8192 words of 8 bits
each. The device’s cascadable feature allows up to 8 devices to share a common 2-
wire bus. The device is optimized for use in many industrial and commercial applications
where low power and low voltage operation are essential. The AT24C32/64 is
available in space saving 8-pin JEDEC PDIP, 8-pin JEDEC SOIC, 8-pin EIAJ SOIC,
and 8-pin TSSOP (AT24C64) packages and is accessed via a 2-wire serial interface.
In addition, the entire family is available in 2.7V (2.7V to 5.5V) and 1.8V (1.8V to 5.5V)
versions.

I check your lib and I didn't find anything regarding the memory at your lib. Do you have it? If not, do you plan to do it? It would be great to have it since you did a great job with your lib that works very well with the esp8266. I checked your lib info when you look for lib at arduino IDE and you say: Includes deep support of modules features, including temperature, alarms and memory storage if present. Tested on esp8266. I think its the only thing missing!

That library can save at memory, if you need some reference it may help https://github.com/Naguissa/uRTCLib
Anyway, thank you for the collaboration

Rtc.SetDateTime(buf); gives error in compiling phase with Arduino ide

snprintf_P(datestring,

Hello, I'm not so expert, with few months of trial.
I'm tring to updated RTC 3231 with date get from UTC (ntp server) from here:

unsigned long epochTime = timeClient.getEpochTime();
utc = epochTime;
TimeChangeRule CEST = { "CEST", Last, Sun, Mar, 2, 60 }; //Central European Summer Time
TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 0 }; //Central European Standard Time
Timezone CE(CEST, CET);
local = CE.toLocal(utc);

then I convert it to format compatible to DS3231 RTC and try to store inside it:

char buf[20];
snprintf_P(buf, countof(buf), PSTR("%02u/%02u/%04u %02u:%02u:%02u"), month(local),
day(local),year(local), hour(local), minute(local), second(local));
Serial.println(buf);
Rtc.SetDateTime(buf);

unfortunately I got an error compling it with Arduino ide

exit status 1
'countof' was not declared in this scope

I tried also this way:
..
snprintf(buf, sizeof(buf),....

but I got this error:

exit status 1
invalid user-defined conversion from 'char [20]' to 'const RtcDateTime&' [-fpermissive]

So, what I forget or I do wrong ?
THANKS

Error compiling after Update

Hi !
Use your library on an ESP8266 and get now following error:
invalid use of template-name 'RtcDS3231' without an argument list
When generating the object with:
RtcDS3231 Rtc;
thx
Rainer

RtcDateTime Epoch32Time method doesn't appear to work

I'm trying to retrieve the current time as an Epoch value using the following code snippet:
RtcDateTime now; currEpoch = now.Epoch32Time();

All this seems to return is the value 946684800 (SeventyYears?). Attached is a sketch that shows the problem comparing the RTC date time from the example sketch with the value I'm getting.

I'm running this on an ESP8266-12F board.

I adapted the sketch for the Uno and got even more bizarre results (see screenshot)
uno_test

As I'm new to this, I probably have made some simple mistake, but I really can't see what the problem might be.

test_RTC.zip

Errores compilacion

Arduino:1.8.0 (Windows 10), Tarjeta:"Arduino Due (Programming Port)"

In file included from C:\Users\JuanJo\Documents\Arduino\DS3231_Simple\DS3231_Simple.ino\DS3231_Simple.ino.ino:24:0:

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:43:48: error: '_BV' was not declared in this scope

const uint8_t DS3231_AIEMASK = (_BV(DS3231_A1IE) | _BV(DS3231_A2IE));

                                            ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:43:67: error: '_BV' was not declared in this scope

const uint8_t DS3231_AIEMASK = (_BV(DS3231_A1IE) | _BV(DS3231_A2IE));

                                                               ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:44:46: error: '_BV' was not declared in this scope

const uint8_t DS3231_RSMASK = (_BV(DS3231_RS1) | _BV(DS3231_RS2));

                                          ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:44:64: error: '_BV' was not declared in this scope

const uint8_t DS3231_RSMASK = (_BV(DS3231_RS1) | _BV(DS3231_RS2));

                                                            ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:52:47: error: '_BV' was not declared in this scope

const uint8_t DS3231_AIFMASK = (_BV(DS3231_A1F) | _BV(DS3231_A2F));

                                           ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:52:65: error: '_BV' was not declared in this scope

const uint8_t DS3231_AIFMASK = (_BV(DS3231_A1F) | _BV(DS3231_A2F));

                                                             ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'bool RtcDS3231<T_WIRE_METHOD>::IsDateTimeValid()':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:239:41: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     return !(status & _BV(DS3231_OSF));

                                     ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:239:41: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'bool RtcDS3231<T_WIRE_METHOD>::GetIsRunning()':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:245:40: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     return !(creg & _BV(DS3231_EOSC));

                                    ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'void RtcDS3231<T_WIRE_METHOD>::SetIsRunning(bool)':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:252:37: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg &= ~_BV(DS3231_EOSC);

                                 ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:256:36: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_EOSC);

                                ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'void RtcDS3231<T_WIRE_METHOD>::SetDateTime(const RtcDateTime&)':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:265:34: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     status &= ~_BV(DS3231_OSF); // clear the flag

                              ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:282:32: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         centuryFlag = _BV(7);

                            ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'RtcDateTime RtcDS3231<T_WIRE_METHOD>::GetDateTime()':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:309:29: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     if (monthRaw & _BV(7)) // century wrap flag

                         ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'void RtcDS3231<T_WIRE_METHOD>::Enable32kHzPin(bool)':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:340:39: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         sreg |= _BV(DS3231_EN32KHZ);

                                   ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:344:40: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         sreg &= ~_BV(DS3231_EN32KHZ);

                                    ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'void RtcDS3231<T_WIRE_METHOD>::SetSquareWavePin(DS3231SquareWavePinMode)':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:354:52: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     creg &= ~(DS3231_AIEMASK | _BV(DS3231_BBSQW));

                                                ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:355:33: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     creg |= _BV(DS3231_INTCN);  // set INTCN to disables SQW

                             ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:363:37: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_BBSQW); // set battery backup flag

                                 ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:364:38: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg &= ~_BV(DS3231_INTCN); // clear INTCN to enable SQW 

                                  ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:368:38: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg &= ~_BV(DS3231_INTCN); // clear INTCN to enable SQW 

                                  ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:372:36: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_A1IE);

                                ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:376:36: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_A2IE);

                                ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:380:36: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_A1IE) | _BV(DS3231_A2IE);

                                ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:380:55: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

         creg |= _BV(DS3231_A1IE) | _BV(DS3231_A2IE);

                                                   ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h: In member function 'void RtcDS3231<T_WIRE_METHOD>::ForceTemperatureCompensationUpdate(bool)':

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:485:32: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     creg |= _BV(DS3231_CONV); // Write CONV bit

                            ^

C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna\src/RtcDS3231.h:488:48: error: there are no arguments to '_BV' that depend on a template parameter, so a declaration of '_BV' must be available [-fpermissive]

     while (block && (creg & _BV(DS3231_CONV)) != 0)

                                            ^

C:\Users\JuanJo\Documents\Arduino\DS3231_Simple\DS3231_Simple.ino\DS3231_Simple.ino.ino: At global scope:

DS3231_Simple.ino:25: error: 'RtcDS3231 Rtc' redeclared as different kind of symbol

RtcDS3231 Rtc(Wire);

                        ^

In file included from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:288:0,

             from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/CMSIS/Device/ATMEL/sam3xa/include/sam3xa.h:44,

             from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/CMSIS/Device/ATMEL/sam3.h:59,

             from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/CMSIS/Device/ATMEL/sam.h:198,

             from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/libsam/chip.h:25,

             from C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:42,

             from sketch\DS3231_Simple.ino.ino.cpp:1:

C:\Users\JuanJo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\system/CMSIS/Device/ATMEL/sam3xa/include/component/component_rtc.h:56:3: error: previous declaration of 'typedef struct Rtc Rtc'

} Rtc;

^

C:\Users\JuanJo\Documents\Arduino\DS3231_Simple\DS3231_Simple.ino\DS3231_Simple.ino.ino: In function 'void setup()':

DS3231_Simple.ino:38: error: expected unqualified-id before '.' token

 Rtc.Begin();

    ^

DS3231_Simple.ino:48: error: expected primary-expression before '.' token

 if (!Rtc.IsDateTimeValid()) 

         ^

DS3231_Simple.ino:60: error: expected unqualified-id before '.' token

     Rtc.SetDateTime(compiled);

        ^

DS3231_Simple.ino:63: error: expected primary-expression before '.' token

 if (!Rtc.GetIsRunning())

         ^

DS3231_Simple.ino:66: error: expected unqualified-id before '.' token

     Rtc.SetIsRunning(true);

        ^

DS3231_Simple.ino:69: error: expected primary-expression before '.' token

 RtcDateTime now = Rtc.GetDateTime();

                      ^

DS3231_Simple.ino:73: error: expected unqualified-id before '.' token

     Rtc.SetDateTime(compiled);

        ^

DS3231_Simple.ino:86: error: expected unqualified-id before '.' token

 Rtc.Enable32kHzPin(false);

    ^

DS3231_Simple.ino:87: error: expected unqualified-id before '.' token

 Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); 

    ^

C:\Users\JuanJo\Documents\Arduino\DS3231_Simple\DS3231_Simple.ino\DS3231_Simple.ino.ino: In function 'void loop()':

DS3231_Simple.ino:92: error: expected primary-expression before '.' token

 if (!Rtc.IsDateTimeValid()) 

         ^

DS3231_Simple.ino:99: error: expected primary-expression before '.' token

 RtcDateTime now = Rtc.GetDateTime();

                      ^

DS3231_Simple.ino:103: error: expected primary-expression before '.' token

 RtcTemperature temp = Rtc.GetTemperature();

                          ^

Se encontraron múltiples librerías para "RtcDS3231.h"
Usado: C:\Users\JuanJo\Documents\Arduino\libraries\Rtc_by_Makuna
No usado: C:\Users\JuanJo\Documents\Arduino\libraries\RTCtime
No usado: C:\Users\JuanJo\Documents\Arduino\libraries\RTCtime
No usado: C:\Users\JuanJo\Documents\Arduino\libraries\RTCtime
No usado: C:\Users\JuanJo\Documents\Arduino\libraries\RTCtime
exit status 1
'RtcDS3231 Rtc' redeclared as different kind of symbol

Este reporte podría tener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.

Can not get alarms triggered

HI,

thanks for sharing this - - have some issues getting the alarm example working. I'm pretty sure all is correct - wiring etc. - but still can not see any log about alarm triggered. If I understand the example correct it should trigger every minute for alarm2, right. All I see is this...

01/27/2017 20:17:20
01/27/2017 20:17:30
01/27/2017 20:17:40
01/27/2017 20:17:50
01/27/2017 20:18:00
01/27/2017 20:18:10
01/27/2017 20:18:20
01/27/2017 20:18:30
01/27/2017 20:18:40
01/27/2017 20:18:50
01/27/2017 20:19:00
01/27/2017 20:19:10
01/27/2017 20:19:21
01/27/2017 20:19:31
01/27/2017 20:19:41
01/27/2017 20:19:51
01/27/2017 20:20:01
01/27/2017 20:20:11
01/27/2017 20:20:21
01/27/2017 20:20:31
01/27/2017 20:20:41
01/27/2017 20:20:51
01/27/2017 20:21:01
01/27/2017 20:21:11
01/27/2017 20:21:21
01/27/2017 20:21:31
01/27/2017 20:21:42
...

Any idea what can be wrong?

#define RtcSquareWavePin 2 // Uno
#define RtcSquareWaveInterrupt 3 // Uno

I changed those value for the Uno - still no log about any alarm...
???

RtcDateTime.Year return 2115 instead 2015.

   String message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n\r<time>\n\r";
   message += "<sec>" + String(now.Second()) + "</sec>\n";
   message += "<min>" + String(now.Minute()) + "</min>\n";
   message += "<hour>" + String(now.Hour()) + "</hour>\n";
   message += "<day>" + String(now.Day()) + "</day>\n";
   message += "<month>" + String(now.Month()) + "</month>\n";
   message += "<year>" + String(now.Year()) + "</year>\n";
   message += "<timestamp>" + String(now.TotalSeconds())+ "</timestamp>\n";
   message += "</time> \n\r";

return
....
2115
.....

Democode with Timezone Lib?

Do you have Democode that use your RTC + Timezone Lib from Christianson?

I have try to combine them but arduino crash after
setSyncProvider(Rtc.GetDateTime());

(RTCDemo from timezone + yourds3231simple)

I ask Mr. Timezone but he only wrote nothing salvation.

If Timezone is incompatible, ok then itisinkompatible

Arduino IDE

Hello,
the Arduino IDE say

there is a update for Makuna RTC Version 2.0.1

after Update it say there is still a update. Do i install 2.0.0 no update found but next start it say again 2.0.1 found and when i install this it go into cyrcle....

GetIsRunning() - problem

                              // IDE 1.8.2 (and 1.6.13)
#include <Wire.h>
/*#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);*/
#include <RtcDS3231.h>
RtcDS3231<TwoWire> Rtc(Wire); // DS3231 AT24C32 IIC module

void setup() {
  Serial.begin(115200);
  Serial.println(__func__);
  Rtc.Begin();}

void loop() {
  if (!Rtc.GetIsRunning()) {Serial.println("R");}
  if (!Rtc.IsDateTimeValid()) {Serial.println("V");}
  Serial.println(Rtc.GetDateTime());
  delay(1000);}

It works, if SDA, SCL and/or GND are interrupted und always on ESP-12x.
If on Arduino (I checked UNO, MEGA and ProMini) only VCC is disconnected, GetIsRunning(), DateTimeValid(), GetDateTime() etc. don't give back the controll to the program.

Wire.endTransmission errors are lost and not exposed

Wire class may have transmission errors, and these are returned on the endTransmission() call.

The exposed methods of the RTC classes does not make it easy to expose a return error value in some cases.

Esp32 already exposes a Wire.lastError()but this is not available on all platform versions of the library.

Current proposal is to expose a new method "lastError()" that will return the last return value from the 'endTransmission()` call.

Creating interface for decoupling from T_WIRE_METHOD

Use case that I am referring to is like this. I have a Task which is using RtcDS1307 class. In my particular case I am using TwoWire class as a low level implementation. When I am passing RtcDS1307 instance in constructor I have to write something like this:

class Task {
public:
  Task(RtcDS1307<TwoWire>& rtc) {}
}

It causes leak between abstraction layers. Since RtcDS1307 interface is independent from T_WIRE_METHOD I would like to have some parent class with virtual methods. Having such I would be able to use:

class Task {
public:
  Task(RtcAccessible& rtc) {}
}

which decouples from TwoWire class.
Simple implementation coule be like this:

class RtcAccessible {
public:
  virtual ~RtcAccessible() {}
  virtual bool IsDateTimeValid() = 0;
  ...
};

template<class T_WIRE_METHOD> class RtcDS1307: public RtcAccessible
{
public:
  bool IsDateTimeValid() override {
    return GetIsRunning();
  }
  ...

If you are willing to add such feature I can create a pull request for you.

Using memory at RTC1307

I see what you did regarding the memory of the RTC1307 and I have some doubts that I didn't find at the lib or at the wiki.

  1. What is the max quantity of address I can save using Rtc.SetMemory(0, 13);?
  2. What is the limit of recording cycles we can have at the memory? Does this number count for one single address or for the memory all together?
  3. DS1307_REG_RAMSTART = 0x08 you used in the lib is the address for anything we want to store at DS1307 EEPROM or it is the memory for part of it and it is possible to use other addresses to reach a bigger EEPROM size?
  4. It we can use multiple addresses for multiple EEPROM parts at DS1307, can the life cycles quantity be applied for each address/part of EEPROM in a separate way?
    Thank you for the lib!

Not working when compile for Raspberry2+, please help, thank you

Hi, I'm compinig with Arduino IDE directly to bin file for my Raspberry3. I have no issues with other I2C libraries, ADC, I/O, etc work fine, but I can't find an RTC lbrary compatible with Raspberry,
exit status 1, "Errore durante la compilazione per la scheda RaspberryPI B+/2."

I just need to read the clock and store new values.. I;m very sad I can;t find nothing.. strange, I guess it's only a couple of I2C requests tothe device and read the answer, I'm thinking to lead datasheet DS3231 and send I2C commnds manually.
Kindly help me, thank you!

Not a real issue (I hope): I forked and modified your library

Hello @Makuna, I just want you to know that I just uploaded in my GitHub an Arduino library that essentially is a fork of your work (see: https://github.com/smz/Arduino-RTCtime).

My need was using the classic time.h structures/methods instead of your RtcDateTime class, so I did the relevant changes, found it working good and decided to contribute back to the community with my version.

I hope this is not a problem for you.

Please note that in my README.md I recognized the origin of my work and also suggested donating to your project.

Regards,

Sergio Manzi

Doubts

Hi! Congratulations for the excellent work!
Only two questions:

  1. In the examples, when you use the comparison operators (= or>), the comparison takes into account the date types (date or String?)
  2. Any predictions to include methods for EEPROM storage in the ds3231 library?

Thanks!

Wemos D1 mini losing time

I am losing time after unplugging Wemos D1 mini cable.

No problem when i set time and restart esp (ESP.restart();) until unplugging cable...

I used same ds3231 device on nodemcu 2.0 amica and unplugged the cable - this works fine no problem!

Any idea?

Outputs gibberish

Here's the output after uploading: ⸮ ⸮A⸮C⸮⸮⸮⸮⸮�⸮�1S�⸮_�⸮RA�6⸮�W#⸮⸮a⸮⸮8⸮٣⸮⸮<⸮⸮⸮É⸮⸮

It continues adding more and more random characters.

Esp8266 Support

I've been trying your library but i'm not able to read time from my DS1307. Could you share the module or the circuit that you have used for the tests, please?

Problem reading from EEPROM

I'm using version 2.1.0 to work with my DS1307 module and I have the following code:

    Wire.begin(D2, D1);
    RtcDS1307<TwoWire> *rtc = new RtcDS1307<TwoWire>(Wire);
    char aux[1024];
    uint8_t c[1];

    for (int i = 0; i < 2000; i++) {
        c[0] = 'A' + (i % 26);
        rtc->SetMemory(i, c, 1);
    }

    for (int i = 0; i < 2000; i++) {
        sprintf(aux, "%d - (%d)", i, rtc->GetMemory(i));
        Serial.println(aux);
    }

It looks like it is able to write some bytes but not others. I have usually get the output on this gist https://gist.github.com/dmelo/1488da2c0f66c61e3569e111a20ef700 . I don't think there is anything wrong with my DS1307, because I have tried with two different modules.

If I increase from 2000 to 4096, it eventually get a soft wdt reset around i = 2060:

Soft WDT reset

              ctx: cont 
                        sp: 3ffefa20 end: 3fff00c0 offset: 01b0

>>>stack>>>
           3ffefbd0:  3ffefc70 7fffffff feefeffe 40216f64  
3ffefbe0:  61766163 61636f6c fe006173 00000001  
3ffefbf0:  3ffeedbe 00000000 00000000 40201555  
3ffefc00:  3ffeedbe 00000068 00000004 4020170a  
3ffefc10:  00000001 00000009 3ffefc79 3fff0bd4  
3ffefc20:  00000301 0000000a 3ffef060 3fff0bd4  
3ffefc30:  00000302 0000000a 00000001 40203214  
3ffefc40:  3ffefc70 3ffef060 3fff0bd4 40203240  
3ffefc50:  000002b2 3ffeed9b 3ffef060 40202ba1  
3ffefc60:  3fffdad0 3ffef060 0000003f 40202d20  
3ffefc70:  20393637 3928202d fe002930 feefeffe  
3ffefc80:  feefeffe feefeffe feefeffe feefeffe  
3ffefc90:  feefeffe feefeffe feefeffe feefeffe  
3ffefca0:  feefeffe feefeffe feefeffe feefeffe  
3ffefcb0:  feefeffe feefeffe feefeffe feefeffe  
3ffefcc0:  feefeffe feefeffe feefeffe feefeffe  

Any clue about what might be wrong or the next steps to troubleshoot?

Issue on docs for alarmTwo

It's just a minor issue, but the docs for AlarmTwo constructor shows seconds and the real constructor doesn't uses it.
Thanks!

RtcDateTime vs year below 2000

Why all these new modern libraries use new format 'since 2000 year'? Most of all old hardware still uses unix-time format 'since 1970..'.

test code that fails:
RtcDateTime test = RtcDateTime(1970, 1, 1, 1, 1, 1);

in RtcDateTime.h:

RtcDateTime(uint16_t year,
uint8_t month,
uint8_t dayOfMonth,
uint8_t hour,
uint8_t minute,
uint8_t second) :
_yearFrom2000((year >= c_OriginYear) ? year - c_OriginYear : year),

how it can convert here
_yearFrom2000((year >= c_OriginYear) ? year - c_OriginYear : year),
1970 for ex, to uint8_t type?
And how can this library at all work correct with data until 2000?
My DS3231 battery is down, when time is readed it correctly returns 1970... zero unix-time, but this RtcDateTime library can't correctly give it to me.
And code in 'DS3231_Simple.ino' fails too in this case:
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)

remove the use of Arduino min and max macros for better compatibility

Due to min and max being macros, they will replace any single word statement that matches them; so if I had a class with a member method named min, it would get replaced with the statements in the macro and then compiled. NASTY!

Since so many libraries now work around this by undefining them, this may cause novice developers to run into compile problems if they are used latter in the code.

To simplify the life of so many Arduino developers, removing the use of them will reduce problems overall.

Use hour minute in variable

Hi,

how can I use the time and store hour and minute in variables?
In the DS3231 Simple - Example is only a Serial print

Thanks

DS3231 i2c ESP32

I need to change the i2c pins to others since another device uses pin 22 to work, how can I change the pins of the ESP2 i2c to work with the DS3231?
I am using the example "DS3231 Simple" that is included with the library
I used this "Wire.begin (16, 17);" in the SETUP as you recommended for the ESP-01, but it does not work and returns erroneous information. This is what it returns:

RTC lost confidence in the DateTime!
85/165/2009 37:165:
-0.25C

Thank you

Make DaysSinceFirstOfYear2000 public

Days calculation may benefit using totalDays as in DaysSinceFirstOfYear2000, instead of having to divide totalSeconds by 3600*24, that has been just multiplied by inside the function.
Hope do not have memory footprint impact.

Thanks for very good job.

Which RTC.H are you using ?

include <avr/pgmspace.h>

include <Wire.h> // must be incuded here so that Arduino library object file references work

include <RtcDS3231.h>

In file included from DS3231_Alarms.ino:9:0:
C:\Users\Sonia\Documents\Arduino\libraries\Rtc-master/RtcDS3231.h:12:17: fatal error: RTC.h: No such file or directory
#include <RTC.h>

Alarm and SQW Pin output

Hello, I'm using the library together with NodeMCU - Esp8266E.

Set date, time and alarm easily. And when the alarm goes off the SQW goes from HIGH to LOW - okay.

I need the SQW to trigger when the alarm is triggered - press HIGH to LOW and HIGH again.

I'm looking in the library for the method responsible for the alarm action, but I can not find it.

I also tried SetSquareWavePinClockFrequency set to 1Hz but it did not work as I expected.

What do you recommend?

ESP32 - Undefine uint8, uint16 ... Error

I tried this module with ESP32 and got some error,

Undefine uint8, uint16 ... errors

found a problem with sequence of include file in RtcDateTime.CPP.

#include "RtcDateTime.h"
#include <Arduino.h>

Then I change my local copy to

#include <Arduino.h>
#include "RtcDateTime.h"

It works.

Leave this info comment and advise that my resolution is correct or not. I am new to Git.

RtcDS3234.h - line 307 _spi.write => _spi.transfer (?)

Describe the bug
Compiling examples for DS3234 with arduino 1.8.8 fails with reference to missing "write" ('class SPIClass' has no member named 'write')

Development environment (please complete the following information):

  • OS: [Win10]
  • Build Environment [Arduino IDE v.1.8..8]
  • Board target [Nano]
  • Library version [v2.3.0]

Minimal Sketch that reproduced the problem:
examples that come with library

Additional context
I changed line 307 to _spi.transfer(...) and it seems to work. (alarm example compiles und runs as expected)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.