1

The Raspberry Pi doesn't come with a realtime clock; if you want to run a standalone (no network) pi with the proper time automatically set on boot you need a real time clock (rtc).

There are a several rtc chips available, most run on the i2c serial bus and many are made by Dallas Semiconductor (ds1307, ds1339, ds3231).

I've wired up a ds3231 to the pi's i2c bus #1, and I can set the time on it and set the system time from the clock using the hwclock command.

How do I configure raspbian to do this on boot? I have removed the fake-hwclock package, but this only results in the system time being set to January 1969 on boot, which tells me hwclock -s was never run.

In a crude attempt to make this work, I placed the hwclock -s command in /etc/rc.local, but I'd like to use a more proper method.

I see there's an /etc/init.d/hwclock.sh script which is supposed to sync the system time from the rtc, but it bails if udev is configured. This implies udev should handle the sync from rtc->system clock, but it is not configured to do so.

What's the proper way to have the system time set from an rtc at boot on a raspberry pi running raspbian?

Jason
  • 11
  • 1
  • https://www.google.com/search?q=amazon+rapberry+pi+rtc+module is where you can get the DS3231 uits for a great price. – SDsolar Jun 23 '17 at 08:29

1 Answers1

1

Add the following line to /boot/config.txt and re-boot.

dtoverlay=i2c-rtc,ds3231=1

See /boot/overlays/README for details.

If that doesn't work you will need to reverse any misconfiguration you did previously.

joan
  • 67,803
  • 5
  • 67
  • 102
  • `dtoverlay=i2c-rtc,ds3231` has already been added to `/boot/config.txt`, and `hwclock` works as expected. – Jason Jan 20 '17 at 18:23
  • @Jason That is all you need to do. You need to undo anything else you did. – joan Jan 20 '17 at 18:28
  • `dtoverlay=i2c-rtc,ds3231` should work (it is what I use), not sure about the "=1" which is not mentioned in documentation. – Milliways Jan 20 '17 at 23:02
  • OK, that worked fine. @Milliways @Joan the `=1` is not required. Thank you guys. – Jason Jan 20 '17 at 23:33
  • @joan if you'll edit your response to omit the `=1`, then I'll accept it as a solution. – Jason Jan 20 '17 at 23:37
  • @Milliways The documentation I am using is `/boot/overlays/README` which is good but perhaps not rigorous. `dtoverlay=i2c-rtc,=` is perhaps ambiguous. – joan Jan 21 '17 at 09:30
  • @joan You won't get any argument from me on the woeful state of Foundation documentation. If the people responsible were working for me they would be redoing it! I don't think anyone proof reads it. – Milliways Jan 21 '17 at 10:08
  • @Milliways I wouldn't go anywhere near that far. Certainly for my own needs I can find the information I need. My complaints are generally nit-picks in areas with which I am very familiar. – joan Jan 21 '17 at 10:20
  • As long as you're editing files, you might want to take a look at /etc/ntp.conf and set it to get time from a Stratum-1 source instead of the pools that are generally Stratum-16 or so. They come installed in ubuntu and Raspbian and even Windows. Here is how to get the real deal: https://raspberrypi.stackexchange.com/questions/68811/how-do-i-set-raspbian-to-use-the-primary-time-server-time-nist-gov? – SDsolar Jun 23 '17 at 08:31