Qwiic Real Time Clock Module (RV-1805) Hookup Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t747

Contents

Introduction

The Qwiic Real Time Clock (RTC) module is a Qwiic-enabled breakout board for the RV-1805 module! The RTC is ultra-low power (running at about 22 nA in its lowest power setting) so it can use a supercapacitor for backup power instead of a normal battery. This means infinite charge and discharge cycles without any degradation to the "battery" (in this case, a supercapacitor). The breakout board is also a part of SparkFun's Qwiic system, so you won't have to do any soldering to figure out what time it is.

SparkFun Real Time Clock Module - RV-1805 (Qwiic)

SparkFun Real Time Clock Module - RV-1805 (Qwiic)

BOB-14558
$18.50 $8.33
4

In this hookup guide, we'll take advantage of the Arduino IDE to automatically set the time of the RTC to the compiler time. Once we have the time set, we'll set the alarm to a time of our choice and have it generate a signal on the interrupt pin. We'll also look at how charged the RTC is so we know when to unplug the RTC from power (when it's full of course). Finally, we'll look at how to store other data into the RTC so we can keep important variables safe when our system loses power. We'll also go over how to extend the battery life of your RTC by adding an external battery.

Required Materials

To get started, you'll need a microcontroller to control everything in your project.

SparkFun RedBoard - Programmed with Arduino

SparkFun RedBoard - Programmed with Arduino

DEV-13975
$21.50
49
SparkFun ESP32 Thing

SparkFun ESP32 Thing

DEV-13907
$23.50
69

Particle Photon (Headers)

WRL-13774
32 Retired

Raspberry Pi 3

DEV-13825
92 Retired

Now to get your microcontroller into the Qwiic ecosystem, the key will be one of the following Qwiic shields to match your preference of microcontroller:

SparkFun Qwiic HAT for Raspberry Pi

SparkFun Qwiic HAT for Raspberry Pi

DEV-14459
$6.50
5
SparkFun Qwiic Shield for Arduino

SparkFun Qwiic Shield for Arduino

DEV-14352
$7.50
9

SparkFun Qwiic Shield for Photon

DEV-14477
Retired

You will also need a Qwiic cable to connect the shield to your RTC, choose a length that suits your needs.

Qwiic Cable - 50mm

Qwiic Cable - 50mm

PRT-14426
$0.95
Qwiic Cable - 100mm

Qwiic Cable - 100mm

PRT-14427
$1.50

Qwiic Cable - 500mm

PRT-14429
1 Retired

Qwiic Cable - 200mm

PRT-14428
Retired

Finally, if your application requires that your RTC be without power for over a month, we'd recommend using the optional battery and battery holder to extend the time that the RTC will remain active without power.

Coin Cell Battery - 12mm (CR1225)

Coin Cell Battery - 12mm (CR1225)

PRT-00337
$2.10
2
Coin Cell Battery Holder - 12mm (PTH)

Coin Cell Battery Holder - 12mm (PTH)

PRT-07948
$1.60

Suggested Reading

If you aren't familiar with the Qwiic system, we recommend reading here for an overview.

Qwiic Connect System
Qwiic Connect System

We would also recommend taking a look at the hookup guide for the Qwiic Shield if you haven't already. Brushing up on your skills in I2C is also recommended, as all Qwiic sensors are I2C.

How to Solder: Through-Hole Soldering

This tutorial covers everything you need to know about through-hole soldering.

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Qwiic Shield for Arduino & Photon Hookup Guide

Get started with our Qwiic ecosystem with the Qwiic shield for Arduino or Photon.

Hardware Overview

Let's look over a few characteristics of the RV-1805 RTC so we know a bit more about how it behaves.

CharacteristicRange
Operating Voltage (Startup)1.6V - 3.6V
Operating Voltage (Timekeeping)1.5V - 3.6V
Operating Temperature-40°C - 85°C
Time Accuracy±2.0 ppm
Current Consumption22 nA (Typ.)
I2C Address0x69

Pins

The characteristics of the available pins on the RTC are outlined in the table below.

Pin LabelPin FunctionInput/OutputNotes
3.3VPower SupplyInputShould be between 1.95 - 3.6V
GNDGroundInput0V/common voltage.
SDAI2C Data SignalBi-directionalBi-directional data line. Voltage should not exceed power supply (e.g. 3.3V).
SCLI2C Clock SignalInputMaster-controlled clock signal. Voltage should not exceed power supply (e.g. 3.3V).
PSWPower SwitchOutputPower Switch pin, digital output. Capable of switching power on an external microcontroller.
INTInterruptOutputInterrupt pin, active low, digital output. Also configurable as a square wave up to 32.768 kHz
RSTResetOutputReset pin, active low, digital output


Optional Features

The Qwiic RTC has onboard I2C pull-up resistors; if multiple sensors are connected to the bus with the pull-up resistors enabled, the parallel equivalent resistance will create too strong of a pull-up for the bus to operate correctly. As a general rule of thumb, disable all but one pair of pull-up resistors if multiple devices are connected to the bus. If you need to disconnect the pull up resistors they can be removed by removing the solder on the corresponding jumpers highlighted below.

I2C Pullup

There is also the option to add a battery to the board if the supercapacitor just isn't gonna keep your project powered long enough (keep in mind, the supercap can hypothetically make the board keep time for around 35 days) you can solder on an external battery. Keep in mind that if doing so, you'll need to cut the trace connecting power to the capacitor, and add solder to the side of the jumper that connects power to the battery labeled as BAT.

Power Jumper

Hardware Assembly

If you haven't yet assembled your Qwiic Shield, now would be the time to head on over to that tutorial.

With the shield assembled, Sparkfun's new Qwiic environment means that connecting the sensor could not be easier. Just plug one end of the Qwiic cable into the RTC breakout, the other into the Qwiic Shield of your choice. You'll be ready to upload a sketch and start keeping track of the time. It seems like it's too easy too use, but that's why we made it that way!

RTC Plugged In

External Coin Cell Battery

Now if you've decided that you'd like to power the RTC from a battery instead of a supercapacitor, you'll need to cut the trace jumper on the back of the board to disconnect power from the supercapacitor. Add solder to the other side of the jumper to connect power to the battery. Once you've done this, add a little bit of solder on the circular pad for contact, solder the battery holder legs to the board, insert the battery, and you're good to go!

Battery

Library Overview

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

Before we get into programming our RTC, let's download and check out the available functions in our library. SparkFun has written a library to control the Qwiic RTC. You can obtain these libraries through the Arduino Library Manager. Search for SparkFun Qwiic RTC RV1805 Arduino Library to install the latest version. If you prefer downloading the libraries from the GitHub repository and manually installing it, you can grab them here:

Download the SparkFun Qwiic RTC RV1805 Library (ZIP)

Let's get started by looking at the functions that set up the RTC.

Setup and Settings

Interrupt Functionality

VoltageEdgeTrigger = trueEdgeTrigger = false
03.0V2.5V
12.5V2.1V
22.2V1.8V
31.6V1.4V

Reading the RTC

Example Code

Example 1 - Set Time

Once you've installed the SparkFun Qwiic RTC RV-1805 Arduino library go to File > Examples > SparkFun Qwiic RTC RV-1805 Arduino Library > Example1-Set_Time to open the example sketch. We will use this first sketch to set up our RTC's internal clock. Take note of the following lines of code, which use the compiler time to set the RTC's clock.

language:c
if (rtc.setToCompilerTime() == false) {
  Serial.println("Something went wrong setting the time");
}

Note that this doesn't reset every time we upload code into our Arduino, so make sure you restart the IDE before uploading to get the most current time to upload into your RTC.

Example 2 - Print Time

Now that we've set the time on the RTC, let's read it out. Open the next example by heading to File > Examples > SparkFun Qwiic RTC RV-1805 Arduino Library > Example2-Print_Time to open the example sketch. After initializing the RTC object, we attempt to update the time variables in our microcontroller with the values from the RTC using some of the code below. If this is successful, we print them out.

language:c
if (rtc.updateTime() == false) //Updates the time variables from RTC
  {
    Serial.print("RTC failed to update");
  }

Also, in its need to feel special, the United States formats its dates differently than the rest of the world (We do MM/DD/YYYY format while everybody else does DD/MM/YYYY format). So if you don't live in the U.S. or you just like how the rest of the world formats their dates, you'll need to uncomment the following line of code (line 50) in your sketch.

language:c
//String currentDate = rtc.stringDate());

Once you upload this code to your microcontroller, go ahead and open the serial monitor with a baud rate of 9600. You should see the current date and time go streaming past, looking something like the image below.

Print Time

If your output is showing the incorrect time, you may need to recompile your sketch to get the latest compiler time using the code from the first example. If this doesn't work, try restarting the Arduino IDE to get a new compiler time.

Example 3 - Trickle Charging

To pull up the next example, go to File > Examples > SparkFun Qwiic RTC RV-1805 Arduino Library > Example3-Trickle_Charging. This example will show us how to fiddle with the RTC's trickle charging circuit to configure it for different charge rates as well as disable it if we want to use a coin cell battery.

The trickle charge circuit consists of a diode (0.3v or 0.6v drop) in series with a resistor (3kOhm, 6kOhm, or 11kOhm) These are available to pass into the function as DIODE_0_3V, DIODE_0_6V, ROUT_3K, ROUT_6K, ROUT_11K. The fastest possible rate, with a 0.3V diode and 3kOhm resistor is enabled by default. Note that the trickle charger should only be used for charging the supercapacitor. Disable the trickle charger simply by calling disableTrickleCharge() if you've connected the optional battery.

Example 4 - Alarm Interrupt

To pull up the next example, go to File > Examples > SparkFun Qwiic RTC RV-1805 Arduino Library > Example4-Alarm_Interrupt. This example shows how to enable and use the alarm interrupt to generate an interrupt every time some or all of the alarm registers match the time register. First, we need to set up what time we want the alarm to go off. To do this, we set the variables in the preamble to the time we would like. They default to the values below as these are the default alarm values.

language:c
byte secondsAlarm = 0;
byte minuteAlarm = 0;
byte hourAlarm = 0;
byte dateAlarm = 0;
byte monthAlarm = 0;

Next, we need to set which parts of the time must match in order for the alarm to be triggered. to do this, we use the setAlarmMode(uint8_t mode); where mode is a number between 0 and 7. Go to line 60 (in the setup loop) if you'd like to change how often the alarm is triggered. The values corresponding to which registers much match are listed below.

Once you've set the alarm to your liking, go ahead and upload the code to your microcontroller. The interrupt pin will now drop low every time the alarm is triggered. If you don't want to physically check the status of the interrupt pin, you can uncomment the section of code in the void loop that reads the status register of the RTC. This will alert you when the alarm has been triggered.

Example 5 - Battery Interrupt

To pull up the next example, go to File > Examples > SparkFun Qwiic RTC RV-1805 Arduino Library > Example5-Battery_Interrupt to open the example sketch. This example checks the charge level of the supercapacitor and alerts the user when it has reached 2.5V. You can change the voltage level at which the user is alerted by changing the values passed into checkBattery(voltage, edgeTrigger);. Follow the chart on the Library Overview page to select the proper voltage. Once you've uploaded the example code to your microcontroller, go ahead and open the serial monitor to 9600 baud. The output should look something like the image below once the RTC is charged to the selected voltage.

Battery Checker

Resources and Going Further

Now that you've successfully got your Qwiic RTC (RV-1805) module up and running, it's time to incorporate it into your own project!

For more information about the Qwiic RTC (RV-1805) module, check out the resources below:

Need some inspiration for your next project? Check out some of these related tutorials:

Reaction Timer

Demonstrate mental chronometry with this simple reaction timer!

SparkFun Inventor's Kit for Photon Experiment Guide

Dive into the world of the Internet of Things with the SparkFun Inventor's Kit for Photon.

SparkFun Qwiic Micro (SAMD21E) Hookup Guide

An introduction to the Qwiic Micro SAMD21E. Level up your Arduino-skills with the powerful SAMD21 ARM Cortex M0+ processor!

Qwiic GPS Clock

What time is it? Time for you to... Qwiic-ly build a GPS clock and output it to a display! This project provides you with the current date and time using GPS satellites. Read the date and time as a digital or analog clock. Or even configure the clock for military, your time zone, or automatically adjust the time for daylight savings time!

Or check out some of these blog posts for ideas:

Enginursday: Battle of the RTC

October 6, 2016

Hardware Hump Day: Earth Day Hacking

April 19, 2017

DIY Sunrise Alarm

March 26, 2018

Nixie LED Clock

May 8, 2018

learn.sparkfun.com | CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado