Arduino RTCZero and M4 boards

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Arduino RTCZero and M4 boards

Post by jfleischer »

Would it be possible to either have a pull request done for the Arduino RTCZero library to support the metro m4? Alternatively, could a port be done for it? Or, is there a library available that will allow you to manage the M4 onboard RTC? I wanted to use it in my project using a WiFi shield to get ntp updates and such. Thanks!

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Arduino RTCZero and M4 boards

Post by User_UMjT7KxnxP8YN8 »

It isn't a full-blown Arduino library, but I wrote functions to provide access to the ATSAMD51 RTC. You can find my code at https://github.com/SapientHetero/Real-t ... r-ATSAMD51. The example shows how to use it.

User avatar
jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Re: Arduino RTCZero and M4 boards

Post by jfleischer »

Excellent! I will take a look after work. Thank you.

However, I hope the option of creating a formal library or updating RTCZero is still on the table. I spent days looking for a solution before I posted here.

User avatar
jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Re: Arduino RTCZero and M4 boards

Post by jfleischer »

As a side note, after dinking around in platformio trying to figure out how to get this compiled in, it works beautifully. Thank you.

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Arduino RTCZero and M4 boards

Post by User_UMjT7KxnxP8YN8 »

Glad to hear it, and thanks for the feedback.

User avatar
Jeremy97469
 
Posts: 18
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

Post by Jeremy97469 »

I have 3 examples of the M4 and would like to know about using the built-in RTC. Any suggestions for a more friendly way to use it? Currently using the Arduino IDE.

User avatar
moonie223
 
Posts: 49
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

Post by moonie223 »

What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.

Trying to get the M4 to retain it's backup memory and keep the RTC running full time is more tedious but still possible. Some boards physically can't due to hardware errors, not without forcing the power domain to the main one, check the errata for versions.

The UF2 Bootloader BOD33 fixes to the flash corruption overwrite the BOD33 registers and fuse settings, you just need to disable BOD33 and reconfigure it from the sketch, or you can modify the UF2 bootloader. From there I've been able to get automatic RTC backup working on PB3. Not much of an RTC if it doesn't retain time, at least in my opinion...

User avatar
Jeremy97469
 
Posts: 18
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

Post by Jeremy97469 »

moonie223 wrote:What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.

Trying to get the M4 to retain it's backup memory and keep the RTC running full time is more tedious but still possible. Some boards physically can't due to hardware errors, not without forcing the power domain to the main one, check the errata for versions.

The UF2 Bootloader BOD33 fixes to the flash corruption overwrite the BOD33 registers and fuse settings, you just need to disable BOD33 and reconfigure it from the sketch, or you can modify the UF2 bootloader. From there I've been able to get automatic RTC backup working on PB3. Not much of an RTC if it doesn't retain time, at least in my opinion...
Thank you for the information. I was hoping to avoid needing a separate RTC.

User avatar
Jeremy97469
 
Posts: 18
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

Post by Jeremy97469 »

moonie223 wrote:What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.
Thank you for suggesting the RTC_E51. Finally got a chance to look it over and found that it will work nicely.

User avatar
moonie223
 
Posts: 49
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

Post by moonie223 »

Glad it's working for you!

User avatar
Jeremy97469
 
Posts: 18
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

Post by Jeremy97469 »

The example program for "RTC_E51" will not compile for me.

Code: Select all

SimpleRTC:4:9: error: no matching function for call to 'RTC_E51::RTC_E51()'
    4 | RTC_E51 rtc;
      |         ^~~
In file included from /var/folders/l3/3ttpb5fx1k1f1c9lh5sp3fjc0000gn/T/arduino_modified_sketch_618601/SimpleRTC.ino:1:
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:38:3: note: candidate: 'RTC_E51::RTC_E51(uint8_t)'
   38 |   RTC_E51(uint8_t calib);
      |   ^~~~~~~
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:38:3: note:   candidate expects 1 argument, 0 provided
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note: candidate: 'constexpr RTC_E51::RTC_E51(const RTC_E51&)'
   24 | class RTC_E51 {
      |       ^~~~~~~
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note:   candidate expects 1 argument, 0 provided
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note: candidate: 'constexpr RTC_E51::RTC_E51(RTC_E51&&)'
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note:   candidate expects 1 argument, 0 provided
exit status 1
no matching function for call to 'RTC_E51::RTC_E51()'
From the following program:

Code: Select all

#include <RTC_E51.h>

/* Create an rtc object */
RTC_E51 rtc;

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;

/* Change these values to set the current initial date */
const byte day = 15;
const byte month = 6;
const byte year = 15;

void setup()
{
  Serial.begin(115200);

  rtc.begin(); // initialize RTC

  // Set the time
  rtc.setHours(hours);
  rtc.setMinutes(minutes);
  rtc.setSeconds(seconds);

  // Set the date
  rtc.setDay(day);
  rtc.setMonth(month);
  rtc.setYear(year);

  // you can use also
  //rtc.setTime(hours, minutes, seconds);
  //rtc.setDate(day, month, year);
}

void loop()
{
  // Print date...
  print2digits(rtc.getDay());
  Serial.print("/");
  print2digits(rtc.getMonth());
  Serial.print("/");
  print2digits(rtc.getYear());
  Serial.print(" ");

  // ...and time
  print2digits(rtc.getHours());
  Serial.print(":");
  print2digits(rtc.getMinutes());
  Serial.print(":");
  print2digits(rtc.getSeconds());

  Serial.println();

  delay(1000);
}

void print2digits(int number) {
  if (number < 10) {
    Serial.print("0"); // print a 0 before if the number is < than 10
  }
  Serial.print(number);
}

User avatar
moonie223
 
Posts: 49
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

Post by moonie223 »

In RTC_E51.h around line 38...

Change "RTC_E51(uint8_t calib);" to just "RTC_E51();"

I used to compensate the RTC by using the oscillator compensation, some datasheets detail changing it and others don't. I guess I forgot to update the .h file.

I'll try and remember to update github later, RTC mode allows a more traditional, cleaner PPM RTC compensation method.

User avatar
Jeremy97469
 
Posts: 18
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

Post by Jeremy97469 »

moonie223 wrote:In RTC_E51.h around line 38...

Change "RTC_E51(uint8_t calib);" to just "RTC_E51();"

I used to compensate the RTC by using the oscillator compensation, some datasheets detail changing it and others don't. I guess I forgot to update the .h file.

I'll try and remember to update github later, RTC mode allows a more traditional, cleaner PPM RTC compensation method.
Thank you. I have the example program running on a Grand Central.

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”