Arduino Real Time C...
 
Notifications
Clear all

Arduino Real Time Clock - Using the Tiny RTC  


DroneBot Workshop
(@dronebot-workshop)
Workshop Guru Admin
Joined: 2 years ago
Posts: 992
Topic starter  

Today we will add a Real-Time Clock to an Arduino. I’ll show you how the Tiny RTC is hooked up and how to use two ways, including with interrupts. We will also construct a temperature and humidity clock.

Full article at https://dbws/tinyrtc

The Arduino is a very versatile platform with many features, however, one thing it cannot do is tell the time. In order to do that you will need a real-time clock module.

A real-time clock is essentially a digital clock that you can interface with a computer or microcontroller. The module we are going to use is the popular Tiny RTC, which interfaces with the Arduino using the I2C bus.

The Tiny RTC is based upon the DS1307 real-time clock chip. This chip provides readings of the second, minute, hour, day, day of the week, month, and year. It adjusts for leap years and has a battery backup. And its available from several sources and it is very inexpensive.

I’ll show you how to hook up the Tiny RTC and how to set and read the time. We will then look at a more advanced method of using the Tiny RTC, using interrupts.

Here is the Table of Contents for today's video:

00:00 - Introduction
02:19 - Tiny RTC Module
05:15 - Hooking it up
06:03 - Setting the Time
09:43 - Reading the Time
12:30 - Creating Interrupts
19:58 - RTC with Temperature and Humidity

As always there is an article on the DroneBot Workshop website with all of the code you’ll need to duplicate these experiments. You’ll find it at https://dbws/tinyrtc

"Never trust a computer you can’t throw out a window." — Steve Wozniak


Quote
davidmcsweeney
(@davidmcsweeney)
Eminent Member
Joined: 7 months ago
Posts: 34
 

@dronebot-workshop

Hi Bill and others,

I've purchased a Tiny RTC and successfully ran the first two functions (Set and Read Time).

I came across a problem with the Square Wave interrupt demonstration. The LED blinks only once, not continuously as in the tutorial. I've followed the instructions exactly so not sure what to do. One thing I noticed that might be an indicator is that the SQ pin on the module is directly connected to the GND pin (checked with my DVM). Not sure if this is meant to be the case or not.

This is important to me as I would like to use this approach in my Water Distillation project with a temp/humidity/pressure sensor.

Cheers,

David


ReplyQuote
Centari
(@centari)
Eminent Member
Joined: 2 years ago
Posts: 45
 

@davidmcsweeney, I don't have the module yet,(it's on my list) but the datasheet shows a typical circuit which does not have the SQ connection going to ground.

image

ReplyQuote
davidmcsweeney
(@davidmcsweeney)
Eminent Member
Joined: 7 months ago
Posts: 34
 

@centari

Thanks Centari. I thought as much. I'm taking it up with the supplier now.


Centari liked
ReplyQuote
YurkshireLad
(@yurkshirelad)
Estimable Member
Joined: 7 months ago
Posts: 240
 

Fantastic! I was just thinking about RTC with Arduino over the weekend. Definitely a must watch for me. Thanks Bill.


ReplyQuote
noweare
(@noweare)
Estimable Member
Joined: 1 year ago
Posts: 108
 

I had a lot of trouble understanding the Wire library and how it worked.  I found that the functions did not correspond to how the reference manual described how TWI worked. I ended up using the low level files twi.h and twi.c that the wire library uses but even then I had use my logic analyzer to figure out how to use the functions before I could talk to the RTC.

When I first started using avr chips I found a i2c library written by Peter Fleury and it is written in C.

The functions closely follow the reference manual as far as using functions like start, repeated start, stop and adding acknowledge. Anyways I learned how to talk to any device with using Peter Fleurys library.

I guess the reason I am posting is that the TinyRTC is a simple i2c device with only about 9 registers to talk to. I like to know how things work and using a RTC library on top of the Wire library seems to make understanding how a simple i2c device work confusing.

 

 


ReplyQuote