Tuesday, July 7, 2015

How to use DS3231 I2C Real Time Clock



Before use DS3231 I2C Real Time Clock. Enable I2C Interface.

On new kernel use Device Tree Overlays.

Edit on /boot/config.txt.

add new line

device_tree_param=i2c1=on
dtoverlay=i2c-rtc,ds3231

Reference : https://github.com/raspberrypi/firmware/tree/master/boot/overlays

Edit on /etc/modprobe.d/raspi-blacklist.conf

add # (comment) on line "blacklist i2c-bcm2708"

#blacklist i2c-bcm2708

Reboot Raspberry PI

sudo shutdown -r now

Re-Check I2C Interface software

$ dmesg | grep i2c
[    5.505513] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
[   11.969815] i2c /dev entries driver

$ lsmod
i2c_bcm2708             6244  0

If you found, software is enabled.


Install DS3231 I2C RTC to Raspberry PI



Test to get time from RTC Module.

$ sudo hwclock -r 
Tue 07 Jul 2015 05:20:09 PM ICT  -0.397656 seconds 

If you want to current time of Raspberry PI to RTC Module.

$ sudo hwclock -w

If you want to set time of RTC Module to Raspberry PI.

$ sudo hwclock -s

You can set time of RTC Module to Raspberry PI on startup.

Edit on file /etc/rc.local
Add line

/sbin/hwclock -s

before line "exit 0"


Reference :
Device Tree overlays of Raspberry PI Firmware
https://github.com/raspberrypi/firmware/tree/master/boot/overlays
Adding a hardware clock to Raspberry Pi (DS3231)
http://www.drewkeller.com/blog/adding-hardware-clock-raspberry-pi-ds3231
Adding a DS3231 Real Time Clock To The Raspberry Pi
http://www.raspberrypi-spy.co.uk/2015/05/adding-a-ds3231-real-time-clock-to-the-raspberry-pi/
Using an I2C Real Time Clock (RTC) with a Raspberry Pi
https://nicegear.co.nz/blog/using-an-i2c-real-time-clock-rtc-with-a-raspberry-pi/

2 comments:

  1. This is most informative and also this post most user friendly and super navigation to all posts. Thank you so much for giving this information to me.
    Time Clock

    ReplyDelete
  2. UNFORTUNATELY: There may be more than one Chinese manufacturer producing these things - there may be thousands...? But beware of this module. All of them I have seen do not have the INT/SQW pin on the DS3231 connected to the header. This means "YOU DO NOT HAVE ACCESS TO THE ALARM FUNCTION" on this module. Some vendors go as far as misrepresenting the device, claiming that the INT/SQW (or MFP) pin on the DS3231 is available on the header. Caveat emptor!

    ReplyDelete