Seeed arduino RTC examples do not compile in Arduino IDE

Hi, I recently downloaded and installed the Seeed Arduino RTC library for use with the arduino MKR gsm 1400 board in the Arduino IDE. However the examples for this Library do not compile. Specifically, in the rtc_samd21 example i get the error:

rtc_samd21:4:1: error: ‘RTC_SAMD21’ does not name a type;

#include "RTC_SAMD21.h"
#include "DateTime.h"

RTC_SAMD21 rtc;

I do not know why i am getting this error since it is an example and should work so maybe an installation issue? I installed the library using the Arduino IDE itself and the Version is 2.0.0 (latest).

The Arduino version is 1.8.19 (latest version i think).

Any help is much appreciated.

Cheers.

The Seeed_Arduino_RTC library example compiles (and works) for the Seeed XIAO, but, as you have observed, doesn’t compile for the Arduino MKR GSM 1400 board. (It also doesn’t compile for an Arduino Zero, which is another SAMD21 board.)

On the other hand the Arduino RTCZero library example compiles OK for both the XIAO and the Arduino MKR GSM 1400 boards. (Also compiles and works for my Arduino Zero board.)

Bottom line: Much of the code in the Seeed_Arduino_RTC library appears to be copied from the Arduino RTCZero library, but the Seeed guys seem to have screwed the pooch for some SAMD21 boards. (There is an #ifdef directive at the beginning of RTC_SAMD21.cpp that may be the root of the problem, but I don’t have the time, stamina, or inspiration to investigate. Don’t really care, since there is an alternative that works for me.)

Use the Arduino Libraries Manager to install the RTCZero library and try its example(s). Let us know how it works.

Regards,

Dave

Hi, and thanks for the reply. Much appreciated.

Yes i have been using the RTCZero library for a while now and it works fine however i found that when using this library with the MKR GSM 1400 specifically while also using the ArduinoLowPower library for SAMD boards, which also uses the RTCZero library, i was getting some sort of conflict that i have not yet been able to resolve.

An example of the odd behavior is from a logger project using the MKR GSM 1400 board where i wanted to implement some sleep modes with the ArduinoLowPower library. I use the RTCZero library to set time and date functions however when i use the LOWPOwerLibrary (also uses RTCZero lib) with timed wakeup, the date (for example) gets reset to 0-1-1, time is similarly affected. This indicates some type of conflict between the usage methods. I tried to get around this by renaming the RTCZero object as _RTC:

/* Create an rtc object */
RTCZero  _RTC;

whereas in the ArduinoLowPower lib it is:

RTCZero rtc;

But this failed to fix the problem so i thought i would try a different RTC library which looks like it is not going to work.

If you have any thoughts on this they would be much appreciated.

Cheers.

I’m not sure I can help you, but let me see if I can understand your problem.

There is a hardware RTC. One and only one. You have created an RTCzero object somewhere in the project. You initialize the Date/Time, somehow, and use that in your logger.

Now, when you go into deep sleep, the only thing running is the hardware RTC, and the low-power library resets the hardware RTC date/time to zero before sleeping.

That means that the time-of-day information in the hardware RTC will have to be re-initialized when it wakes up.

I can’t see where having another, different (software) RTC object can possibly help.

Don’t know whether the following could meet your requirements, but, maybe, if the low-power mode has the ability to maintain some RAM contents while powered down, then…

Store Date/Time from the RTCzero object just before going into sleep. Upon awakening, set the hardware RTC and the RTCzero object with a new date and time obtained by adding the sleep time to the previously stored values.

If you can’t do this, then you have to re-initialize the RTC, somehow, with current Date/Time every time upon re-awakening. Probably not practical, but I don’t know exactly what you are expecting.

Regards,

Dave

Update: I ran a test on my Arduino Zero board using the ArduinoLowPower.h library.

This initializes the hardware RTC but does not rewrite the hardware RTC during sleep functions (or anywhere else).

You simply have to re-initialize the RTCZero object in setup() and set date and time to make it go. (At least it works for me.)

The only problem is that the RTCZero object is in the private: section of the LowPower object definition.

From a comment in my test program:

*  This requires the following modification of
 *      Arduino_Low_Power\src\ArduinoLowPower.h
 *      
 *  In the ArduinoLowPowerClass definition, move the declaration
 *  of the RTCZero object from the private: section to the public: section.
 *  Something like this, starting at line 87

    #ifdef ARDUINO_ARCH_SAMD
    void attachAdcInterrupt(uint32_t pin, voidFuncPtr callback, adc_interrupt mode, uint16_t lo, uint16_t hi);
    void detachAdcInterrupt();
    RTCZero rtc; // davekw7x: Moved from private: to public:
    #endif

  private:
    void setAlarmIn(uint32_t millis);
    #ifdef ARDUINO_ARCH_SAMD
    //RTCZero rtc; // davekw7x: Moved from private: to public:
    voidFuncPtr adc_cb;
    friend void ADC_Handler();
    #endif

I have attached the project and some output. This little program makes an LED blink briefly then goes to sleep for a couple of seconds and wakes up again. Each time through the loop it prints out a loop count value and the current RTC Date/Time values.

Regards,

Dave

Daves_TimedWakeup.zip (2.2 KB)

Hi,
And thanks for the reply and the code example. Much appreciated.

I tested your code on an MKR GSM 1400 board (i dont have an Arduino Zero board).

I got the following output:

DeepSleep Test compiled on Jun  7 2022 by davekw7x

In setup(): After setDate, setTime
2022-06-06  12:34:56
Leaving setup() at 3186 ms

1: 2022-06-06  12:34:56
2022-06-06  12:35:22
2022-06-06  12:35:58
2022-06-06  12:36:34
2022-06-06  12:37:10
2022-06-06  12:37:46
2022-06-06  12:38:22
2022-06-06  12:39:00
2022-06-06  12:39:38
2022-06-06  12:40:16
2022-06-06  12:40:54
2022-06-06  12:41:32
202: 2022-06-06  12:41:38
2022-06-06  12:42:16
2022-06-06  12:42:54

Which is not quite right. The LED is blinking at the correct frequency but the serial output is definitely not every 2s. So something is not quite right on the board i am using.

I have just tried the program on an old Arduino M0 Pro and is giving the correct output.

Any Ideas?

Any help is much appreciated.

Cheers.

Sorry; don’t have a MKR GSM1400. According to schematics it uses the exact same CPU, so I thought it was worth a shot.

Regards,

Dave