Reply to topic  [ 1 post ] 
DS3231 RTC module for Raspberry Pi (HCRASP0009) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 622
Post DS3231 RTC module for Raspberry Pi (HCRASP0009)

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 rechargeable batter 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.


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 bu
+2.3 V to +5.5 V supply voltage


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:

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:

sudo raspi-config

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


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


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:

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:

sudo i2cdetect -y 0

OR for newer version 2 Pi's:

sudo i2cdetect -y 1

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


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:

sudo modprobe rtc-ds1307

Next switch to a super user with the following command:

sudo bash

Your shell prompt should change to the following:


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

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

OR if you have a newer version 2 Pi issue the following command:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

Exit out of super use by typing:


Reading the current time from the module:

Issue the following command:

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:


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:

sudo hwclock -w

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

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:

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:


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:

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:

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


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:


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

Wed Apr 13, 2016 12:56 pm
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to &
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD