Thursday, December 31, 2015

Setting clock on DS3231 using RPi

The problem

When using the DS3231 module with for example Arduino-based project there is no easy way to properly set the actual time on that device. There is a way using Linux. Since we'll be using the I2C to hook up the clock module you are going to need either the i2c-tiny-usb interface or for example Raspberry Pi which has the bus with gold pins ready to use.

The solution

Connect the module to the I2C bus, load the appropriate kernel module, initialize the device letting the system know there is a hardware clock attached, synchronize the system clock and finally store that system clock value

pi@raspberrypi:~ $ sudo modprobe rtc_ds1307
pi@raspberrypi:~ $ echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
pi@raspberrypi:~ $ sudo ntpd -gq
pi@raspberrypi:~ $ sudo hwclock -w --local

That's it! Happy hacking!

No comments: