SparkFun gator:RTC Hookup Guide

Pages
Contributors: santaimpersonator, Englandsaurus
Favorited Favorite 1

MakeCode Examples

Now that you have added the gator:particle extension to the Editor, lets start with some example code. Plug the micro:bit into your computer using an USB micro-B cable after you have assembled your hardware with the instructions from the previous section. The micro:bit should appear on your computer as a removable storage device.

USB Drive
The micro:bit showing up as a USB drive on a Windows computer. Click to enlarge.

To upload new code, this is where you will be copying the downloaded .hex file to later.

Block Functions

set time to ___
: ___
: ___
- _____
This block should allows users to set the time stored in the RTC. The time should take the following format: HH:MM:SS in a 12-hour format. This block doesn't prohibit invalid entries (e.g 13:01:53 AM). Double check the time that is being set is valid; otherwise, the RTC may respond improperly when called upon.

  • HH- Integer value for the our in 12-hour format (i.e. The 3rd hour after 12 should be entered as 3). There is also a slider that can be easily used.
    • 0 to 12
  • MM- Minutes in integer format (i.e. The 20th minute past the hour should be entered as 20). There is also a slider that can be easily used.
    • 0 to 59
  • SS- Seconds in integer format (i.e. The 30th second past the minute should be entered as 20). There is also a slider that can be easily used.
    • 0 to 59
  • 12-Hour Period- Drop down menu to select the 12-hour period.
    • AM- Ante meridiem (i.e. before noon).
    • PM- Post meridiem (i.e. after noon).

set date to _____
, _____
- ___
- 20___
This block should allows users to set the date stored in the RTC. The date should take the following format: Weekday, Month - DD - 20YY. This block doesn't prohibit invalid entries (e.g Feb 29th for leap years, Sept. 31st, or YY = 100). Double check the date that is being set is valid; otherwise, the RTC may respond improperly when called upon.

  • Weekday- Drop down menu to select the weekday.
    • Monday
    • Tuesday
    • Wednesday
    • Thursday
    • Friday
    • Saturday
    • Sunday
  • Month- Drop down menu to select the month.
    • January
    • February
    • March
    • April
    • May
    • June
    • July
    • August
    • September
    • October
    • November
    • December
  • DD- Day in integer format (i.e. The 3rd should be entered as 3). There is also a slider that can be easily used.
    • 0 to 31
  • YY- Year in integer format (i.e. The 2019 should be entered as 19). (The calender is only leap-year accurate for the years 2000 to 2099.)
    • 0 to 99

set _____ to ___
This block should allows users to change a specific component of time. This block doesn't prohibit invalid entries. Double check the that the modification is valid; otherwise, the RTC may respond improperly when called upon.

  • Unit of Time- Drop down menu to select the unit of time you want to change.
    • Seconds
    • Minutes
    • Hours
    • Date
    • Month
    • Year
    • Weekday
  • Value- Value in integer format.
    • Seconds- Input an integer:
      • 0 to 59
    • Minutes- Input an integer:
      • 0 to 59
    • Hours- Input an integer:
      • 0 to 12 (if in 12-hour format)
      • 0 to 24 (if in 24-hour format)
    • Date- Input an integer:
      • 0 to 31
    • Month- Input an integer:
      • 0 to 12
    • Year- Input an integer:
      • 0 to 99
    • Weekday- Input an integer:
      • 0- Monday
      • 1- Tuesday
      • 2- Wednesday
      • 3- Thursday
      • 4- Friday
      • 5- Saturday
      • 6- Sunday

value of _____
This is a value block that returns the value for the stored component of time from the RTC.

  • Unit of Time- Drop down menu to select the unit of time you want to retrieve.
    • Seconds- Returns an integer:
      • 0 to 59
    • Minutes- Returns an integer:
      • 0 to 59
    • Hours- Returns an integer:
      • 0 to 12 (if in 12-hour format)
      • 0 to 24 (if in 24-hour format)
    • Date- Returns an integer:
      • 0 to 31
    • Month- Returns an integer:
      • 0 to 12
    • Year- Returns an integer:
      • 0 to 99
    • Weekday- Returns an integer:
      • 0- Monday
      • 1- Tuesday
      • 2- Wednesday
      • 3- Thursday
      • 4- Friday
      • 5- Saturday
      • 6- Sunday

text of weekday
This is a value block that returns a string for the weekday.

time in HH:MM:SS
This is a value block that returns a string for the time stored by the RTC in a HH:MM:SS format.

date in mm-dd-yyyy
This is a value block that returns a string for the date stored by the RTC in a mm-dd-yyyy format.

button timestamp in HH:MM:SS
This is a value block that returns a string for the previous time, marked by the RTC timestamp button in a HH:MM:SS format.

button timestamp in mm-dd-yyyy
This is a value block that returns a string for the previous date, marked by the RTC timestamp button in a mm-dd-yyyy format.

set time to ___:___:___ in 24 hour mode
This block allows users to set the time stored in the RTC. The time should take the following format: HH:MM:SS in a 24-hour format. This block doesn't prohibit invalid entries (e.g 25:01:53). Double check the time that is being set is valid; otherwise, the RTC may respond improperly when called upon.

  • HH- Integer value for the our in 24-hour format (i.e. The 3rd hour after midnight should be entered as 3). There is also a slider that can be easily used.
    • 0 to 24
  • MM- Minutes in integer format (i.e. The 20th minute past the hour should be entered as 20). There is also a slider that can be easily used.
    • 0 to 59
  • SS- Seconds in integer format (i.e. The 30th second past the minute should be entered as 20). There is also a slider that can be easily used.
    • 0 to 59

time in yyyy-mm-ddThh:mm:ss
This is a value block returns a string for the time stored by the RTC in ISO8601 format.

date in dd-mm-yyyy
This is a value block that returns a string for the date stored in the RTC in dd-mm-yyyy format.

button timestamp in yyyy-mm-ddThh:mm:ss
This is a value block returns a string for the previous time, marked by the RTC timestamp button in ISO8601 format.

button timestamp in dd-mm-yyyy
This is a value block returns a string for the previous time, marked by the RTC timestamp button in dd-mm-yyyy format.

value of button timestamp in _____
This is a value block that returns a specific component of timestamp stored by the RTC.

  • Unit of Time- Drop down menu to select the unit of time you want to retrieve from timestamp.
    • Seconds- Returns an integer:
      • 0 to 59
    • Minutes- Returns an integer:
      • 0 to 59
    • Hours- Returns an integer:
      • 0 to 24 (in 24-hour format)
    • Date- Returns an integer:
      • 0 to 31
    • Month- Returns an integer:
      • 0 to 12
    • Year- Returns an integer:
      • 0 to 99

set to _____ time
This block allows users to change the time format between a 12-hour and 24-hour.

  • Standard- Changes the time to a 12-hour format.
  • Military- Changes the time to a 24-hour format.

Basic Setup and Time Retrieval

Below, is a simple example of how to take simple readings from the RTC. To use this example, there are multiple options for accessing the .hex file:

  • Replicate the block functions from the display below to copy the example project. Then download the .hex file.
  • Expand the display widow to pull up the example project. Then download the .hex file.
  • Use this link to pull up the example project. Then download the .hex file.
  • Download the .hex file from the button below or the link on the bottom of the display.

The output is redirected over the serial port to avoid conflicts on pins P0 and P1, which are also used for serial communication. To read the sensor values, pull up your favorite serial terminal emulator. Then, connect to the serial port that the micro:bit is on; the default baud rate is 115200 bps. Below, is an example of an output of the time stored by the gator:RTC using the example code.

Sample Readings
Example of readings from the RTC.

In the read out from the RTC, you can see with the 1.5 and 0.8 second delays that the resolution of the RTC is limited to one second intervals. (Between the change from a 1.5 to a 0.8 delay, the seconds value was reset back to 0 seconds.) Additionally, you should note the various subtleties in timing formats for the functions used.

Pressing Timestamp Button
Pressing timestamp button to change RTC output.

If you are confused to how the timestamp button works, the read out in the forever loop prints out both the current time and the timestamp of the last button press. In the example readings, you can see the timestamp change from a few button presses.