DS3231 Real Time Clock installation guide for RPi / /LE8

  • Hi everyone,


    There have been some questions in these forums about RTC support in LE, and there's various info on the web, some of which is confusing because it applies to Raspbian or to older versions of OE, so I thought it might not be a bad idea if I simply documented my procedure for installing a Real Time Clock in my Raspberry Pi with LibreElec 8. This worked for me, right off the bat.


    These instructions are for the DS3231 RTC modules that can be ordered for next to nothing from a variety of sources.


    1. Unplug your Pi and Install the RTC module onto the GPIO connector pins 1-4 as follows:


    DS3231.jpg


    2. Switch your RPi back on and SSH into it.


    3. Enable kernel support:

    3a. Remount LE system partition r/w: mount -o remount,rw /flash

    3b. Edit /flash/config.txt and add (somewhere near the end): dtoverlay=i2c-rtc,ds3231

    3c. Remount LE system partition r/o: mount -o remount,ro /flash

    3d. Reboot.


    4. Adjust the RTC's time:

    4a. Verify local system time with the 'date' command. If local time is off, either adjust it manually or connect your Pi to the Internet and wait for it to the the correct time from an NNTP server.

    4b. Transfer local time to RTC: hwclock -w

    4c. Verify RTC time: hwclock -r


    That's it. You're done. Your LibreElec RPi will now have the correct time every time it powers up. Don't worry about loading kernel modules, disabling fake clocks or other configuration changes. In LE8 you don't need them; whatever instructions you may have found referring to that sort of thing applies to other operating systems or older versions.


    Note: edits to /flash/config.txt should survive LE upgrades; edits to /flash/distroconfig.txt won't. Should you end up having to reinstall LE, don't forget to restore your edits to /flash/config.txt.

  • Very nice "How To" - confirmed to work on LE9.


    If you feel confident, this could be added to our Wiki pages Here

    I'm happy to add it to the Wiki, but not sure where; none of the current categories seems to fit. The "RPi" categories seems the closest one but that only lists Pi specs at the moment. Suggestions welcome!!

  • I guess this never got added to the wiki :( This line needs to be changed for other chips:


    3b. Edit /flash/config.txt and add (somewhere near the end): dtoverlay=i2c-rtc,ds3231

    with


    Code
    dtoverlay=i2c-rtc,ds1307

    or

    Code
    dtoverlay=i2c-rtc,pcf8523

    Also, I'm not sure if this step is necessary:

    4. Adjust the RTC's time:

    4a. Verify local system time with the 'date' command. If local time is off, either adjust it manually or connect your Pi to the Internet and wait for it to the the correct time from an NNTP server.

    4b. Transfer local time to RTC: hwclock -w

    4c. Verify RTC time: hwclock -r


    I've just added a used ds1307 rtc and the date from hwclock -r was UTC, I'm on GMT, so an hour behind. Doing hwclock -w and then rebooting with no network resulted in it being an hour ahead for some reason! It's now sorted itself out though and keeps the correct time after losing power and no network.


    Now I just need to figure out a script to keep trying to reconnect the wifi if it's unavailable after power loss. Then my pi might just get itself back ship shape after a rare power cut!