Trying to get an RTC to load at boot. I've enabled i2c, that works fine for other components.

/etc/modules contains:


/etc/rc.local contains:

echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s

i2cdetect -y 1 shows UU in the 68 slot

I can set the date using hwclock with -r, '-w', and -s successfully

if I reboot, I get from hwclock -r

hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).

I can then write, read and sync with it again fine.

Any suggestions?! I've tried replacing the RTC module, but the same thing happens. Same if I remove the battery from the RTC.

If I remove the battery, the first time I boot it will show the date in the year 2000, but after that it'll go back to the error.

  • Solved by following the instruction here: raspberrypi.org/forums/viewtopic.php?t=161133
    – zotty
    Commented Jul 19, 2018 at 12:05
  • 1
    You know self answering is allowed? So if you can expand what is in that link with your own experience that worked for the context you describe, it would be a reasonable answer, no?
    – rene
    Commented Jul 19, 2018 at 15:35

1 Answer 1


The answers involving modprobe and removing fake hwclock are not needed for Stretch era Rasbian and beyond. Here's the steps that work for me as a reference:

  1. Install tools:

    sudo apt-get install -y i2c-tools   
    sudo apt-get install -y python-smbus
  2. Update /boot/config.txt (Note: you can turn I2C 'on' via sudo raspi-config, but you need the overlay too to properly load the driver).

    sudo sh -c "echo dtoverlay=i2c-rtc,ds3231 >> /boot/config.txt"
    sudo sh -c "echo dtparam=i2c_arm=on >> /boot/config.txt"
  3. Update /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines ("comment out" means put a # at the beginning of each of the lines, so they become comments and are ignored by the system). They should like like:

    # if [ -e /run/systemd/system ] ; then
    # exit 0
    # fi
  4. Reboot system

    sudo reboot
  5. Review I2C is working, and get current timestamp from RTC:

    sudo i2cdetect -y 1 # will show 68 if I2C is on, but UU if overlay is actually active.
    sudo hwclock -r
  6. Review and update reading from hw clock.

    sudo hwclock -D -r
    date # Get latest date from internet 
    sudo hwclock -w # write that date to HW clock
    sudo hwclock -r # read the value of hw clock again

References: https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time https://www.raspberrypi.org/forums/viewtopic.php?t=161133

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.