Keeping the Raspberry Pi 3 clock up to date

June 27th, 2016

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.



Automatic Kinetic Watch Winder

June 11th, 2013

I had some spare time a while back and so rather than buying an automatic watch winder for a watch that I rarely wear, I decided to build a USB powered one myself. Certain types of watches require movement through wear to keep them ticking. If you wear the watch daily, this shouldn’t be a problem but missing a day or two will cause the watch to stop – annoying if you don’t wear it regularly.

Watch Automatic Kinetic Winder

Watch Automatic Kinetic Winder

The project was a relatively simple hack, I have an arduino chip connected up with a bare minimum circuit. I have two mini motors attached to off-center drilled metal coins causing them to vibrate when active. The arduino simply sets pin 13 high for 1.5 seconds and then low for an hour. The pin output opens and closes a transistor which provides necessary amplification to drive the two mini motors.

The code as follows:

int pin = 13;
int vibrate = 1500; //1.5s*1000
int sleep = 3600; //60s * 60m
int sleep_loop = 1000;
int sleep_ctr = 0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(pin, OUTPUT);

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(pin, HIGH);   // turn the pin on (HIGH is the voltage level)
  delay(vibrate);               // wait for a second
  digitalWrite(pin, LOW);    // turn the pin off by making the voltage LOW
  for (sleep_ctr = 0; sleep_ctr < sleep_loop; sleep_ctr++)
    delay(sleep);               // wait for 3.6s * 1000 (1h)
Watch Automatic Kinetic Winder

Watch Automatic Kinetic Winder