Real Time Clock RTC

From HiveTool
Jump to: navigation, search

Adding a RTC to the Hive Interface board.

DS3231

Hardware

alt Modified H2

This module almost plugs in to H2 (the I2C bus) on the Hive Interface board. A minor modification is required. As +5 VDC is not used and the ground must be shifted down a pin:

  1. The ground on C? must be moved.
  2. To be safe, the 4th pin of a 1x5 male header should be removed.
  3. Solder the 1x5 header in H2 BUT SHIFT IT DOWN ONE PIN.


Old H2 I2C Bus New H2 for RTC
Pin Signal New Pin
1 +5 No connect
2 +3.3 Pin 1 of H2
3 I2C Pin 2 of H2
4 I2C Pin 3 of H2
5 Ground No connect
Ground for C Ground Pin 5 of H2

Software

These instructions have recently been updated and work well:

https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/overview

The hwclock is read on boot. When the ntp servers are available, the system time is synced to them and the system time is written to the hwclock every 11 minutes. From the hwclock man page:

Automatic Hardware Clock Synchronization By the Kernel 
 You  should be aware of another way that the Hardware Clock is kept synchronized in some systems.  The Linux kernel has a mode wherein it copies the System Time to the Hardware Clock every 11 minutes.  This is a good mode to use when you are using something sophisticated like ntp to keep your System Time  synchronized.  (ntp is a way to keep your System Time synchronized either to a time server somewhere on the network or to a radio clock hooked up to your system.  See RFC 1305).

 This mode (we'll call it "11 minute mode") is off until something turns it on.  The ntp daemon xntpd is one thing that turns it on.  You can turn it off by running anything, including hwclock --hctosys, that sets the System Time the old fashioned way.

Turn on I2C

Command Line
sudo raspi-config 

Select

5 Interfacing Options 

Select

P5 I2C

and enable it.

Desktop

Install software

sudo apt-get update
sudo apt-get install python-smbus i2c-tools

This wasn't necessary as they were both already installed and the latest version in the 0.7.4 image.

Edit /boot/config.txt. Add:

#enable RTC DS3231 module
dtoverlay=i2c-rtc,ds3231


Edit /lib/udev/hwclock-set and comment out these three lines:

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi