Getting intervals through RTC

I’m constructing a test circuit for checking the drift of the internal oscillator of an ATtiny10. I hooked up an NodeMCU to an DS3231RTC module and an SD module. I’m using the SD library and the RTC by Makuna library.

The ATtiny fires of a pulse every 24th hour, triggering an interrupt on the NodeMCU, which then logs the time from the RTC to the SD card. The list of times are also displayed on a website.

Now, I would much rather have the interval between the pulses displayed. I would need something like

thisTime = Rtc.getDateTime();
interval = thisTime - lastTime;
thisTime = lastTime;

But I just can’t figure out how the RTC library returns time from the getDateTime() function, and how I can get a response that works for doing the math I want.
Anyone familiar with the RTC library that has any tips?

But I just can't figure out how the RTC library returns time from the getDateTime() function

Nor were you able, apparently, to figure out that we have no idea which RTC library you are using or where you got it.

Anyone familiar with the RTC library that has any tips?

You are looking for an RTC library that has tips? I don't understand.

Sorry, but I did actually put the library I'm using in BOLD in the post above. It's one of the most used RTC libraries around. If you need a link all you have to do is ask:

LINK TO RTC BY MAKUNA

And I'm looking for anyone FAMILIAR WITH THAT RTC LIBRARY that can give me HELP.

I did actually put the library I'm using in BOLD in the post above.

But, you did not tell us what the actually class name was, or where you actually got the library.

The library that you linked to this time contains a GetDateTime() method in the RtcDS3231 class that returns a RtcDateTime, which is a class with methods like Year(), Month(), etc.

It also has a TotalSeconds64() method that returns the number of seconds since 1/1/2000.

So:

   RtcDateTime then = someInstance.GetDateTime();

   // Do whatever that takes a really long time

   RtcDateTime now = someInstance.GetDateTime();

   uint64_t interval = now.TotalSeconds64() - then.TotalSeconds64();

Ahaaa... so that's the way you get the "second since 2001"- return. Thank you so much, I got lost in the different classes and methods and couldn't find my way out.
I still don't quite get how the actual return from the GetDateTime()- funktion is formatted. When I print it it's a collection of numbers that doesn't really make sense to me.

I still don't quite get how the actual return from the GetDateTime()- funktion is formatted. When I print it it's a collection of numbers that doesn't really make sense to me.

The actual return value is the address of an instance of the RtcDateTime class. Printing that address will be pretty useless.

So if I print it with a dereference operator, would that give me something valuable?

So if I print it with a dereference operator, would that give me something valuable?

No, you have to call methods on the return instance, like I showed.

Great, thank you. I'm sure I will get it eventually. Now I know how to do this particular thing at least :slight_smile:

I suggest you look at the example sketches that came with the library. If it doesn't have examples, it's a poor library, try another one.

Oh, I looked at the example sketches all right. But they made it even more confusing. The problem is that I still haven't fully understood the concept of classes, and when you get a library that has a class wrapped up in a class, that becomes a bit complicated if you're still struggling with the basics.

Mixe:
Oh, I looked at the example sketches all right. But they made it even more confusing. The problem is that I still haven't fully understood the concept of classes, and when you get a library that has a class wrapped up in a class, that becomes a bit complicated if you're still struggling with the basics.

You shouldn't have to understand classes to use a library. Many of the fundamental Arduino features are class based, and are routinely used by rank beginners.

If the examples are confusing, it's a sign that you have a poor library. There are many of those out there.

The library that you have is OK. It would help, though, to know what you want to do with the RtcDateTime instance, and what problems you are having doing that.

If you want to print the time and date, you can do that:

   RtcDateTime now = someInstance.GetDateTime();

   Serial.print("It is now ");
   Serial.print(now.Hour())
   Serial.print(":");
   Serial.println(now.Minute());

   Serial.print("Today is ");
   Serial.print(now.Month());
   Serial.print("/");
   Serial.print(now.Day());
   Serial.print("/");
   Serial.println(now.Year());

There may be easier ways.