{"id":4441,"date":"2016-03-01T17:02:04","date_gmt":"2016-03-01T09:02:04","guid":{"rendered":"http:\/\/www.rocketscream.com\/blog\/?post_type=portfolio&#038;p=4441"},"modified":"2017-03-07T15:32:23","modified_gmt":"2017-03-07T07:32:23","slug":"using-real-time-clock-rtc-with-mini-ultra-pro","status":"publish","type":"portfolio","link":"https:\/\/www.rocketscream.com\/blog\/docs-item\/using-real-time-clock-rtc-with-mini-ultra-pro\/","title":{"rendered":"Using Real Time Clock (RTC) with Mini Ultra Pro"},"content":{"rendered":"<div  class='tabcontainer av-av_tab_container-cdfb33d025ccce82e3bec7780d128c1e sidebar_tab sidebar_tab_left  avia-builder-el-0  avia-builder-el-no-sibling  border_tabs'>\n<section class='av_tab_section av_tab_section av-av_tab-21127c225c921997827e1c80d5a962e2'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-1-tab' class='tab active_tab' role='tab' aria-selected=\"true\" tabindex=\"0\" data-fake-id='#tab-id-1' aria-controls='tab-id-1-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue8a5' data-av_iconfont='entypo-fontello' ><\/span>Overview<\/div><div id='tab-id-1-content' class='tab_content active_tab_content' role='tabpanel' aria-labelledby='tab-id-1-tab' aria-hidden=\"false\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p>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 <a href=\"https:\/\/www.maximintegrated.com\/en\/products\/digital\/real-time-clocks\/DS1307.html\" target=\"_blank\">DS1307<\/a>\u00a0and <a href=\"http:\/\/www.nxp.com\/products\/interface-and-connectivity\/interface-and-system-management\/i2c\/i2c-real-time-clocks-rtc\/real-time-clock-calendar:PCF8563\" target=\"_blank\">PCF8563<\/a>. This save you from needing to spare couple of pins for the interface with the RTC chip, an external crystal and some passive components.<\/p>\n<p>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 &#8220;Sketch &gt;&gt; Include Library &gt;&gt; Manage Libraries&#8221;. Search for &#8220;RTCZero&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4442\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero.png\" alt=\"Library Manager - RTCZero Library \" width=\"800\" height=\"450\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero.png 800w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero-600x338.png 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero-300x169.png 300w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero-768x432.png 768w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/LibraryManagerRTCZero-705x397.png 705w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Install the latest revision of the library and perform any update if your installed version is not up to date.<\/p>\n<\/div><\/div><\/section>\n<section class='av_tab_section av_tab_section av-av_tab-d311feddab80cee8c38460394eea476a'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-2-tab' class='tab' role='tab' aria-selected=\"false\" tabindex=\"0\" data-fake-id='#tab-id-2' aria-controls='tab-id-2-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue862' data-av_iconfont='entypo-fontello' ><\/span>Simple RTC<\/div><div id='tab-id-2-content' class='tab_content' role='tabpanel' aria-labelledby='tab-id-2-tab' aria-hidden=\"true\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p>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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-gallery wp-image-4443\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCExample-515x684.png\" alt=\"Simple RTC Example\" width=\"515\" height=\"684\" \/><\/p>\n<p>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&#8217;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.<\/p>\n<p>Simple add the following line of code in the sketch to replace the use of Serial with SerialUSB instead.<\/p>\n<pre>#include &lt;RTCZero.h&gt;\r\n\/* Create an rtc object *\/\r\nRTCZero rtc;\r\n#define Serial SerialUSB  \/\/ ***** Add this line of code *****\r\n<\/pre>\n<p>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.<\/p>\n<pre>void setup()\r\n{\r\n\u00a0 \/\/ Wait until USB connection is up\r\n\u00a0 while(!SerialUSB);  \/\/ ***** Add this line of code *****\r\n\u00a0 Serial.begin(9600);<\/pre>\n<p>Upload the modified sketch to the Mini Ultra Pro. Open the serial monitor at 9600 bps baud rate once the sketch is uploaded.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4444 size-full\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCSerialUSB-e1456819515978.png\" alt=\"Simple RTC - Serial Monitor\" width=\"800\" height=\"457\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCSerialUSB-e1456819515978.png 800w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCSerialUSB-e1456819515978-600x343.png 600w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<\/div><\/div><\/section>\n<section class='av_tab_section av_tab_section av-av_tab-66a01830895d2007b051030c5c738c70'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-3-tab' class='tab' role='tab' aria-selected=\"false\" tabindex=\"0\" data-fake-id='#tab-id-3' aria-controls='tab-id-3-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue83d' data-av_iconfont='entypo-fontello' ><\/span>RTC with Alarm<\/div><div id='tab-id-3-content' class='tab_content' role='tabpanel' aria-labelledby='tab-id-3-tab' aria-hidden=\"true\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p>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.<\/p>\n<pre>\/*\r\n  Simple RTC Alarm for Arduino Zero and MKR1000\r\n\r\n  Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000\r\n\r\n  This example code is in the public domain\r\n\r\n  http:\/\/arduino.cc\/en\/Tutorial\/SimpleRTCAlarm\r\n\r\n  created by Arturo Guadalupi &lt;a.guadalupi@arduino.cc&gt;\r\n  25 Sept 2015\r\n  \r\n  modified\r\n  21 Oct 2015\r\n*\/\r\n\r\n#include &lt;RTCZero.h&gt;\r\n\r\n\/* Create an rtc object *\/\r\nRTCZero rtc;\r\n#define Serial SerialUSB  \/\/ ***** Add this line of code *****\r\n\r\n\/* Change these values to set the current initial time *\/\r\nconst byte seconds = 0;\r\nconst byte minutes = 0;\r\nconst byte hours = 16;\r\n\r\n\/* Change these values to set the current initial date *\/\r\nconst byte day = 25;\r\nconst byte month = 9;\r\nconst byte year = 15;\r\n\r\nvoid setup()\r\n{\r\n  while(!SerialUSB);  \/\/ ***** Add this line of code *****\r\n  Serial.begin(9600);\r\n\r\n  rtc.begin(); \/\/ initialize RTC 24H format\r\n\r\n  rtc.setTime(hours, minutes, seconds);\r\n  rtc.setDate(day, month, year);\r\n\r\n  rtc.setAlarmTime(16, 0, 10);\r\n  rtc.enableAlarm(rtc.MATCH_HHMMSS);\r\n  \r\n  rtc.attachInterrupt(alarmMatch);\r\n}\r\n\r\nvoid loop()\r\n{\r\n\r\n}\r\n\r\nvoid alarmMatch()\r\n{\r\n  Serial.println(\"Alarm Match!\");\r\n}\r\n<\/pre>\n<p>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 &#8220;Alarm Match!&#8221; message on the serial monitor.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4445\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCAlarmMatch.png\" alt=\"Simple RTC - Alarm Match\" width=\"575\" height=\"314\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCAlarmMatch.png 575w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/03\/SimpleRTCAlarmMatch-300x164.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<\/div><\/div><\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":4446,"comment_status":"open","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_forum_subforum_count":0,"footnotes":""},"tags":[],"portfolio_entries":[183,155],"class_list":["post-4441","portfolio","type-portfolio","status-publish","has-post-thumbnail","hentry","portfolio_entries-mini-ultra-pro","portfolio_entries-products"],"_links":{"self":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/4441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio"}],"about":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/types\/portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/comments?post=4441"}],"version-history":[{"count":1,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/4441\/revisions"}],"predecessor-version":[{"id":5279,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/4441\/revisions\/5279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media\/4446"}],"wp:attachment":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media?parent=4441"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/tags?post=4441"},{"taxonomy":"portfolio_entries","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio_entries?post=4441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}