Keeping the Raspberry Pi 3 clock up to date

Raspberry Pi 3The Raspberry Pi 3 is an excellent piece of hardware. With 4 ARM A53 cores, 1Gb RAM and integrated 802.11bgn wifi, at only $35, they’re giving them away!

One of the biggest pain points when using the Pi for data acquisition is a lack of a battery backed clock. Each time the Pi boots up, it reverts to it’s manufacture date. Sure, with a working network connection we can synchronise with NTP easily enough, but what happens when we don’t have network access?

The Pi foundation deliberately avoided including a battery backed clock – it’s changes the size, adds extra circuitry and a battery, and increases the price.

How do we know when our clock is wrong? When the Pi boots up, until we’ve made a successful NTP call, our clock is wrong.

How can we prevent our clock going backwards? Use fake-hwclock. The system time is logged, and then restored on next boot to whatever it was previously. The clock will be wrong, but at least it won’t have gone backwards. This can save us from a number of code related issues.

ARPI600The other option, is to get an addon clock. After much research, I settled on the ARPI600.

First – it obviously includes the needed RTC over an I2C interface. The PDF setup guide is pretty simple and just works.

Second – it includes XBee support – a whole range of radio modules.

Third – it gives you the Arduino headers and opens up the Pi to the full Arduino ecosystem.

Fourth – it provides a USB interface for both power, and the serial UART interface, saving on that 4 wire debug cable.

The case? A bit of a problem – if anyone knows of one that will take a Pi3, ARPI600 hat and any Arduino hats, I’m all ears – until then, I’ll need to print my own.

Anyway, back to time keeping. After an initial time set with NTP, we can set our accurate time to the ARPI600 with hwclock -w

Later on after a fresh boot, we can set our clock to match that of the ARPI600 with hwclock -s. Lastly, to print out the clock on the ARPI600, it’s hwclock -r.

 

 

Tags: , , ,

Leave a Reply