Arduino Real Time Clock - Using the Tiny RTC
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
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.
@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.
Thanks Centari. I thought as much. I'm taking it up with the supplier now.
Fantastic! I was just thinking about RTC with Arduino over the weekend. Definitely a must watch for me. Thanks Bill.
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.
I struggled with this at first before I realised there seems to be two main chips used in RTCs, the DS1307 and the DS3231 (the video was relevant to the DS1307). Perhaps naively I purchased a DS3231, before realising. When I got a "tiny RTC" with a DS1307 all worked well (thanks to the Dronebotworkshop YouTube video). Since I have a DS3231-type RTC I persisted with it but I'm finding it hard to fathom and get working properly.
The Arduino website points to the DS3231 library but I couldn't get this to work with the example sketches provided. I then found another library by searching the Arduino IDE called ds3231FS, which does work with the provided example sketches - although they are tricky to figure out. Confusingly, both libraries are represented by #include <ds3231.h> in the code.
I thought I'd share the experience - even though I'm not that experienced with Arduino. Others with greater knowledge might be able to steer me in a better direction?
Find something that works and stick with it.
I was kidnapped by mimes.
They did unspeakable things to me.
I think those are wise words.