DS3231 RTC module for Raspberry Pi (HCRASP0009)

Raspberry Pi compatible accessories
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by admin » Wed Apr 13, 2016 12:56 pm

Image

DS3231 Clock Module 3.3V / 5V High Accuracy For Raspberry Pi




A very compact real time clock (RTC) module is based on the high accuracy DS3231 IC and includes a battery backup. The (HCRASP0009) module also has a header with a pinout specifically designed so that it can be plugged directly into the IO header of your Raspberry Pi without any need for additional wires or soldering. The module makes use of the Raspberry Pi's I2C hardware interface. Using our configuration guide available on our support forum it will allow your Raspberry Pi to accurately keep the current time and date without an internet connection making it great for remote data logging application where not internet connection is available.

Although specifically designed for the Raspberry Pi, its ability to with with both 3.3V and 5V logic levels means it can also be used with most types of microcontroller development boards such as the Arduino.


Features:

Item number: HCRASP0009
Accuracy: ± 5ppm (± 0.432 sec / day) within -40oC to +85oC temperature range.
Battery backup allowing accurate time keep without a power supply
Low power operation
DS3231 controller.
Clock functions include seconds, minutes, hours, day, date, month and year timing.
Timing valid up to year 2100
Two calendar alarm
High-speed (400kHz) I2C serial bus
+2.3 V to +5.5 V supply voltage

Image


Image


Raspberry Pi Setup Guide:

Please note: To follow this guide your Raspberry Pi should be connected to a monitor, mouse, and keyboard and will need a working internet connection. This guide has been tested on the Raspbery Pi version 2. Before following this guide we strongly recommend that you backup your data and/or SD card image. We cannot accept responsibility for any loss or damaged caused by not following this advice.


Firstly we need to determine that your Pi can see the RTC module. To do this we need to install the I2C utilities. In a terminal window on your Pi issue the following two commands:

Code: Select all

sudo apt-get install python-smbus
sudo apt-get install i2c-tools
Answer yes (y) to any questions.


Next we need to add support to the Raspian kernal for I2C devices. Issue the following command:

Code: Select all

sudo raspi-config

In the menu that opens up use your arrow keys to select the 'Advanced Options' as shown:

Image

Hit enter and then in the next screen select 'I2C'

Image

Answer yes to confirm that you wish to enable I2C support

Select OK on the next prompt and finally when asked if you would like the I2C kernel module loaded by default answer YES. Click OK one final time to confirm.

Once back in the config screen select finish to get back to the command prompt. You should be prompted if you wish to reboot. Select yes. If you're not asked to reboot then just issue the following command at the command prompt:

Code: Select all

sudo reboot

Wait until your Raspberry Pi has rebooted.

Once it has rebooted we can now check that everythign is working. Open up another terminal windows and issue the following command:

For old version 1 Pi's:

Code: Select all

sudo i2cdetect -y 0
OR for newer version 2 Pi's:

Code: Select all

sudo i2cdetect -y 1
The command will return a list of all connected I2C devices. You should see something similar to this:

Image

If the RTC module is installed correctly is should be reported as device 68



Configuring the module:


We first need to load the RTC module. Issue the following command:

Code: Select all

sudo modprobe rtc-ds1307

Next switch to a super user with the following command:

Code: Select all

sudo bash
Your shell prompt should change to the following:

Code: Select all

root@raspberrypi:/home/pi#

If you have an older version 1 Pi issue the following command:

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
OR if you have a newer version 2 Pi issue the following command:

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
Exit out of super use by typing:

Code: Select all

exit


Reading the current time from the module:

Issue the following command:

Code: Select all

sudo hwclock -r
The command should report back a time and date. However this will be incorrect as the RTC module has not yet been configured to the correct date and time and will probably report a date of Thu 27 Jan 2000.


Setting the correct time and date:

Make sure your Pi is connected to the internet and issue the following command:

Code: Select all

date
If your Pi has internet access it should report the correct time and date.


You can simply write this correct time and date to the RTC module with the following command:

Code: Select all

sudo hwclock -w
Confirm that it has been written connrectly by reading the time out of the RTC module again:

Code: Select all

sudo hwclock -r
The module should now report the correct time and date.


Configuring your Raspberry Pi to read the RTC module at reboot.

You will now need to configure your Pi so that it reads the current time from the RTC module each time it reboots.

The RTC module will need to be added to the modules list so that it is loaded everytime your Pi boots. Issue the following command:

Code: Select all

sudo nano /etc/modules
A text editor will open with the module list. Add the RTC module to is as shown in the image below:

Image

Press CTRL-X, then y, then enter to save and exit the editor.


Next we need to edit the rc.local file which will create the RTC module as a new device when your Pi is booted. Issue the following command to edit the rc.local file:

Code: Select all

sudo nano /etc/rc.local
In the text edit add the follwing lines to the bottom of the file, but before the 'exit 0' line:

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s
date
Image

Exit the editor by pressing CTRL-X, then y, then enter.


We now need to test everything is working by powering down your Pi. Issue the following command

sudo shutdown


Wait for your Pi to shutdown and then remove the power for a few seconds.

Connect the power back to your Pi so that it reboots but this time make sure there is no internet connection.

Once rebooted, open up a terminal window and issue the following command:

Code: Select all

date
If everything is installed and configured correctly it should report back the correct time and date despite not having an internet connection.

antoan
Posts: 1
Joined: Sun Aug 25, 2019 5:48 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by antoan » Sun Aug 25, 2019 5:51 pm

Please, provide a labeled pinout of the device, I will not be using it with a raspberry pi.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by andrew » Mon Aug 26, 2019 10:51 am

I've attached a quick drawing to show the pinout:


HCRASP0009_800_600.jpg
You do not have the required permissions to view the files attached to this post.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

andyjacobsuk
Posts: 1
Joined: Sat Sep 07, 2019 7:39 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by andyjacobsuk » Sat Sep 07, 2019 7:41 pm

Perfect! Thanks for this.

Mike_sendrove
Posts: 1
Joined: Sat May 16, 2020 12:37 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by Mike_sendrove » Sat May 16, 2020 3:51 pm

Hi. I've connected the module to an arduino successfully, and I'm switching the power to the rtc with the arduino. I wonder if the battery has sufficient capacity to work with very little to no charge for say a month? Any thoughts on this?
I'm trying to make an arduino based system which runs on lipo battery. Alternatively I'll power the rtc up full time, assuming the current draw is not a lot.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by andrew » Sun May 17, 2020 7:43 am

That's not something we've actually tested and obviously testing one would not be an option as it would take a month just to get the answer! I can do a rough guess though. According to the datasheet for the DS3231 when powered from Vbatt, with an inactive serial interface, battery current is 3.5uA. Unfortunately I don't know what the battery part number is but my best guess is it's a LIR2450 which has a capacity of 100mAh. So if you do that maths on that its >3 years.

This is of course a guess and when talking about tiny amounts of current like this there will be other things to take into consideration. For instance the battery will have it's own internal leakage (according to the LIR2450 datasheet capacity is >85% after one month) and there could be some leaching of current via IO pins but even then I would say it's very likely you'll get at least a months worth of backup out of it.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

jfirth8187
Posts: 1
Joined: Mon Jul 27, 2020 12:36 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by jfirth8187 » Mon Jul 27, 2020 12:45 pm

Hi could you please advise? I have connected the RTC to a Raspberry Pi Model A+ (40 pin GPIO) on pins 1-9 and followed the guide above up until the point where I need to scan for the device. Currently the RTC is not detected on

Code: Select all

sudo i2cdetect -y 0
or

Code: Select all

sudo i2cdetect -y 1
I get the following output on both

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --
Many thanks for your advice.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by andrew » Mon Jul 27, 2020 4:16 pm

If you've followed the guide exactly up to that point i2cdetect should defiantly be able to detect the module. The only thing I can suggest (if you haven't done this already) is to leave it plugged into the pi for a little while in case the battery is discharged. If that doesn't work then there may be something wrong with it. If you still have no luck can you send an email to sales (at) hobbycomponents.com referencing this forum post and an order number and we'll sort it out from there.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

wemosHobby
Posts: 7
Joined: Sat Aug 08, 2020 11:09 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by wemosHobby » Tue Oct 13, 2020 2:01 pm

Can this be used with Arduino ? If yes, how to get SQW ? I need SQW to wake up arduino from sleep. please advice

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: DS3231 RTC module for Raspberry Pi (HCRASP0009)

Post by andrew » Wed Oct 14, 2020 8:45 am

Can this be used with Arduino ?
Yes it can.

If yes, how to get SQW ?
I'm afraid the SQW pin is not brought out to the header on this module. If you need easy access to the SWQ pin then I would suggest this version of the module which has it brought out to the header:

https://hobbycomponents.com/rtc/699-hig ... rtc-eeprom
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Raspberry Pi”