Raspberry PI with Real Time Clock

From Playful Exploration
Jump to navigation Jump to search

DS3231 I2C RTC chip

See https://nicegear.co.nz/blog/using-an-i2c-real-time-clock-rtc-with-a-raspberry-pi/ .

Open the RPI and plugin the clock module. Plug it as shown in the image, into the inner row all the way to the end.

https://nicegear.co.nz/obj/images/raspberry-pi-real-time-clock-rtc-ds3231-3.jpg

Run raspi-config and enable the 'Enable automatic loading of I2C kernel module' option in the advanced settings.

raspi-config

Reboot

sudo reboot
sudo su
# Remove the module blacklist entry so it can be loaded on boot
sed -i 's/blacklist i2c-bcm2708/#blacklist i2c-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
# Add the RTC device on boot
sed -i 's#^exit 0$#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device#' /etc/rc.local
echo hwclock -s | tee -a /etc/rc.local
echo exit 0 | tee -a /etc/rc.local
reboot

These two command should show the current time now

# clock module's time
hwclock
# OS time
date

To force updating the time of OS and clock module simply restart the ntp service:

sudo /etc/init.d/ntp restart