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


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
Adding a hardware clock to Raspberry Pi (DS3231)
Adding a DS3231 Real Time Clock To The Raspberry Pi
Using an I2C Real Time Clock (RTC) with a Raspberry Pi

No comments:

Post a Comment