Raspberry Pi hardware real-time-clock?

roger peppe roger.peppe at canonical.com
Thu Dec 29 19:15:39 UTC 2016


On 28 December 2016 at 18:58, Oliver Grawert <ogra at ubuntu.com> wrote:
> hi,
> On Mi, 2016-12-28 at 16:40 +0000, roger peppe wrote:
>> Hi,
>>
>> Not sure if this is the right place to ask this question - apologies
>> if not.
>>
>> I need a hardware RTC on my Raspberry Pi model B and I have
>> acquired one of these https://www.abelectronics.co.uk/p/52/RTC-Pi-Plu
>> s
>>
>> I'm running a reasonably recent version of Ubuntu Core with snappy
>> version 2.18.1.
>>
>> What's the best way of adding this to my Pi so that it gets the time
>> on bootstrap and keeps it in sync? The instructions I've found rely
>> on changing configuration files that are on the read-only filesystem,
>> such as /etc/init.d/hwclock.sh. I'd be happy to make a new snap
>> to do this if that's what's needed.
>>
>> Thanks for any pointers,
>>
>
> i2c is enabled by default, you will likely have to edit
> /boot/uboot/config.txt to additionally enable the i2c-rtc and ds1307
> device trees, like:
>
> dtoverlay=i2c-rtc,ds1307
>
> on reboot i would expect the rtc-ds1307 module to be loaded
> automatically and the hwclock boot job to set/get the hwclock time...
>
> if you run into any issues with this, please make sure to file the
> respective bugs.
>
> i dont think anyone of us has yet used a battery driven rtc module to
> actually verify it works, so your feedback will be very appreciated ...

Thanks very much for your response.

It seems to work well, with one caveat: for about a minute after rebooting,
the time is wrong - it becomes correct eventually:

        rogpeppe at localhost:~$ date
        Thu Dec 29 18:31:12 UTC 2016
        rogpeppe at localhost:~$ sudo shutdown now
        Connection to 192.168.0.5 closed by remote host.
        [power off pi and power back on again]
        %  ssh rogpeppe at 192.168.0.5
        [...]
        Last login: Thu Dec 29 18:31:10 2016 from 192.168.0.69
        rogpeppe at localhost:~$ date
        Mon Dec 26 17:35:08 UTC 2016
        [wait 10 seconds or so]
        rogpeppe at localhost:~$ date
        Thu Dec 29 18:33:19 UTC 2016

I used some of my own code (https://godoc.org/github.com/rogpeppe/misc/ds1307)
to actually set the current time in the RTC. When I use the date command to set
the current time, it doesn't seem to be reflected in the hardware RTC value.
Is there a way of getting that to work?

I'd like to use this device in combination with NTP so that I get
properly synchronised
time when network is available, but fall back to the battery-powered clock when
there's a power-cut/network failure.

Is that possible? In fact NTP seems to be disabled by default - what's
the preferred way to it up?
I found http://madeformakers.org/2016/01/26/how-to-install-snappy-ubuntu-core-in-raspberry-pi-2/
which suggests that I run "sudo timedatectl set-ntp true" but it's not
clear if that's meant to be persistent.

I also found http://askubuntu.com/questions/795139/ntp-synchronisation-in-ubuntu-core
which
suggests "sudo snap install ntpserver" but that snap doesn't seem to
be found currently.

  cheers,
    rog.

PS Have you got a link to the docs that would have allowed me to work
the "dtoverlay" solution
out for myself, please? In general it's not clear to me how one is
supposed to configure a snappy-based
system.




More information about the Snapcraft mailing list