2

I followed all instructions from Adafruit website but the system clock is still not set after I turn off the internet.

**The clock resets to 2000-01-01 00:00:00 when I turn off internet, shutdown, wait for 5 mins, and reopen rpi. I've been trying to fix this for a week now. Any help will be greatly appreciated. **

cat /etc/os-release

PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

sudo apt-get update

sudo apt-get upgrade

sudo nano /boot/config.txt

dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=i2c-rtc,ds3231

sudo i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   

sudo apt-get -y remove fake-hwclock

sudo update-rc.d -f fake-hwclock remove

sudo systemctl disable fake-hwclock

sudo nano /lib/udev/hwclock-set

#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.

dev=$1

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

#/sbin/hwclock --rtc=$dev --systz
/sbin/hwclock --rtc=$dev --hctosys

(WITH INTERNET)

date

Saturday, 18 March, 2023 01:48:29 AM PST

sudo hwclock -w

sudo hwclock -r

2023-03-18 01:48:33.448713+08:00

timedatectl

               Local time: Sat 2023-03-18 01:50:16 PST
           Universal time: Fri 2023-03-17 17:50:16 UTC
                 RTC time: Fri 2023-03-17 17:50:16
                Time zone: Asia/Manila (PST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

dmesg | grep rtc

[    9.395322] vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.398153] vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.398838] vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.400108] vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.400820] vc4-drm gpu: bound fec12000.pixelvalve (ops vc4_crtc_ops [vc4])
[   10.793556] rtc-ds1307 1-0068: registered as rtc0
[   10.797266] rtc-ds1307 1-0068: setting system clock to 2000-01-01T00:13:09 UTC (946685589)

(WITHOUT INTERNET)

pi@raspberrypi:~ $ date
Saturday, 01 January, 2000 08:00:49 AM PST
pi@raspberrypi:~ $ sudo hwclock -r
2000-01-01 08:00:56.567891+08:00
pi@raspberrypi:~ $ timedatectl
               Local time: Sat 2000-01-01 08:01:04 PST
           Universal time: Sat 2000-01-01 00:01:04 UTC
                 RTC time: Sat 2000-01-01 00:01:04
                Time zone: Asia/Manila (PST, +0800)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
pi@raspberrypi:~ $ dmesg | grep rtc
[    8.691900] rtc-ds1307 1-0068: SET TIME!
[    8.717235] rtc-ds1307 1-0068: registered as rtc0
[    8.723796] rtc-ds1307 1-0068: setting system clock to 2000-01-01T00:00:21 UTC (946684821)
[    9.111707] vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.112320] vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.112883] vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.113234] vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops [vc4])
[    9.113702] vc4-drm gpu: bound fec12000.pixelvalve (ops vc4_crtc_ops [vc4])
pi@raspberrypi:~ $ 
1
  • Have you checked that the battery installed on your RTC module is a) present and b) good?
    – Dougie
    Mar 17 at 23:58

1 Answer 1

1

Your fundamental problem is turning off fake-hwclock . If the RTC is working it does no harm. Turn it back on.

See https://raspberrypi.stackexchange.com/a/104139/8697

It is unclear if you added any other code but the ONLY thing you need is the appropriate dtoverlay dtoverlay=i2c-rtc,ds3231
(which you can also enable on the fly with sudo dtoverlay i2c-rtc ds3231)

You may need to initially set RTC but normally this happens automatically.


sudo hwclock -rv will display details of your RTC; the current time & when last synchronised.

You need to ensure that the RTC is working and the battery is OK. Some RTC use a supercapacitor for backup which are less reliable.

sudo systemctl status fake-hwclock will tell you its status.

4
  • Can you tell me how to revert removal of fake-hwclock? sudo apt-get instal fake-hwclock doesn't work
    – curiousIya
    Mar 23 at 7:31
  • First NEVER use apt-get use apt (which is designed for interactive use). "Doesn't work" is meaningless. What error did you get?
    – Milliways
    Mar 23 at 7:58
  • I used my cloned sd before I messed with fake-hwclock. After adding this (dtoverlay=i2c-rtc,ds3231) the rtc still doesn't retain the date and time
    – curiousIya
    Mar 27 at 11:36
  • I bought a new rtc now it works fine and retain values. However my other i2c devices stopped working.
    – curiousIya
    Mar 29 at 0:21

Your Answer

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

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