• Twitter
  • Youtube
Rocket Scream
  • Blog
  • Shop
    • Arduino and Compatibles
      • Mini Ultra Series
      • osPID
    • Component
      • Connector
      • Interconnect & Cables
      • Wires
      • Sensors
        • Temperature
    • Wireless
      • Antenna
      • Module
  • Forums
  • Docs
  • Contact
  • About
  • My Account
  • Search
  • Menu Menu
  • 0Shopping Cart

Using Real Time Clock (RTC) with Mini Ultra Pro

You are here: Home1 / Docs2 / Using Real Time Clock (RTC) with Mini Ultra Pro
Overview

The Mini Ultra Pro comes with a built-in Real Time Clock (RTC) peripheral on the ATSAMD21G18A-AU microcontroller. It supports full calendar capability with alarm function. By having the RTC built-in, you can avoid from using an external RTC chip like DS1307 and PCF8563. This save you from needing to spare couple of pins for the interface with the RTC chip, an external crystal and some passive components.

The Arduino team has written a RTC library specifically for the Arduino Zero which Mini Ultra Pro is compatible with. You can download the latest revision of the library from the Arduino IDE through “Sketch >> Include Library >> Manage Libraries”. Search for “RTCZero”.

Library Manager - RTCZero Library

Install the latest revision of the library and perform any update if your installed version is not up to date.

Simple RTC

The installed RTCZero library comes with several examples to get you started on using the RTC. Open the SimpleRTC example and connect your Mini Ultra Pro to the PC using the USB connection.

Simple RTC Example

The example sketch uses the default Serial (used on other non-native USB Serial port like Arduino Uno, Mega2560) and if we were to upload the sketch without modifying them, we won’t be able to see any debug messages on the serial monitor when the USB on the Mini Ultra Pro is used. We need to make some small changes to the code in the SimpleRTC to use the SerialUSB instead.

Simple add the following line of code in the sketch to replace the use of Serial with SerialUSB instead.

#include <RTCZero.h>
/* Create an rtc object */
RTCZero rtc;
#define Serial SerialUSB  // ***** Add this line of code *****

On top of that, we would need to wait for the USB connection to be up before sending any debug messages. Add the following line of code.

void setup()
{
  // Wait until USB connection is up
  while(!SerialUSB);  // ***** Add this line of code *****
  Serial.begin(9600);

Upload the modified sketch to the Mini Ultra Pro. Open the serial monitor at 9600 bps baud rate once the sketch is uploaded.

Simple RTC - Serial Monitor

RTC with Alarm

One of the most important feature of the RTC is the capability to set alarm. This allow the scheduling of a specific process or task when a predefined time and date that has been set earlier is reached. The RTCZero library has included an example of using the alarm feature. Open up the example SimpleRTCAlarm and make the similar changes to the code like in the previous SimpleRTC example.

/*
  Simple RTC Alarm for Arduino Zero and MKR1000

  Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000

  This example code is in the public domain

  http://arduino.cc/en/Tutorial/SimpleRTCAlarm

  created by Arturo Guadalupi <a.guadalupi@arduino.cc>
  25 Sept 2015
  
  modified
  21 Oct 2015
*/

#include <RTCZero.h>

/* Create an rtc object */
RTCZero rtc;
#define Serial SerialUSB  // ***** Add this line of code *****

/* 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 = 25;
const byte month = 9;
const byte year = 15;

void setup()
{
  while(!SerialUSB);  // ***** Add this line of code *****
  Serial.begin(9600);

  rtc.begin(); // initialize RTC 24H format

  rtc.setTime(hours, minutes, seconds);
  rtc.setDate(day, month, year);

  rtc.setAlarmTime(16, 0, 10);
  rtc.enableAlarm(rtc.MATCH_HHMMSS);
  
  rtc.attachInterrupt(alarmMatch);
}

void loop()
{

}

void alarmMatch()
{
  Serial.println("Alarm Match!");
}

In this example, the alarm is set 10 seconds after start up. Once the alarm time is reached, you should be able to see the “Alarm Match!” message on the serial monitor.

Simple RTC - Alarm Match

Follow us on Twitter

Tweets by rocketscream

Subscribe to our newsletter

Information

  • About
  • Contact
  • Covid-19 Shipment Update
  • Ordering Info
  • Returns
  • Shipping Info
© Copyright - Rocket Scream Electronics
  • Twitter
  • Youtube
Using Digital Analog Converter (DAC) on Mini Ultra ProUsing RTC in Low Power Mode on Mini Ultra Pro
Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OK

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only