DietPi OS unbootable on a Pi1 after attempting to implement a ds3231 RTC

Update made some progress: When following this guide and some pointers in this Forum post I THINK I’m booting with the hwclock/ds3231 RTC Module, I’m gonna outline my steps here and it would be extremely appreciated if one of you could comment on your thoughts for optimizations and or things I should change.

|LInks|

This is the forum post in question: [SOLVED] How do I use the DS3231 RTC on NanoPi NEO3 with DietPi 7.0.2?

This is the guide used for reference “Heads up both of these resources seem dated”: Set RTC Time | Adding a Real Time Clock to Raspberry Pi | Adafruit Learning System

Okay so I didn’t bother with enabling I2C in the dietpi-config as @MichaIng suggested, I did notice that the errors previously mentioned in my last post are triggered if I2C is enabled, could you please explain what those are referring too?

this also means you won’t be able to use the i2cdetect commands to check the circuit via the python and I2C tools.

the first file I modify is the /boot/config.txt I’ve appended the following line to the end of the file, make sure to adjust it if you have a different chip.

#-------RTC-------
dtoverlay=i2c-rtc,ds3231

now that I’ve defined my overlay I’m gonna modify the configuration file for the system clock located here, /lib/udev/hwclock-set the following is my configuration taken from both the guide and vmiceli’s post.

#!/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

if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi

HCTOSYS_DEVICE=rtc1

Now will have to remove the fake hwclock package from the system using the following commands…

sudo apt -y remove fake-hwclock

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

now you can reboot the Pi via sudo reboot now

after the pi reboots use the following command to read the hardware clocks date and time.

sudo hwclock -r

If the time and date is incorrect make sure your Pi is connected to the internet and use the date command to check the current system clock time.

If the time is correct you can pass that on to the Hardware clock via sudo hwclock -w then again check the hardware clocks time and date via sudo hwclock -r

I’m assuming it’s working, I’m now able to pull the system up and down, without issues, however I am curious about a few things.

what does this line do in the /lib/udev/hwclock-set file, is it necessary? HCTOSYS_DEVICE=rtc1 and what about these lines, what are they doing exactly?

dev=$1
/sbin/hwclock --rtc=$dev --hctosys
 
 if [ -e /run/udev/hwclock-set ]; then
     exit 0
 fi

Now what about confirming that I’m actually falling back to the system clock, how can this be done?

When I did have I2C enabled via the dietpi-config I was able to check via sudo i2cdetect -y 1 which would either output 69 (Circuit is correct but chip not detected) or UU (which means the RTC chip is recognized by the kernel, once disabling I2C I can’t run these checks, and when enabled it prompts me every reboot with those two errors I mentioned in my previous post.

Is there any other way to confirm this is working as intended?

Notes for anyone struggling, this link does have some great diagrams for those wiring this up. Adding a Real Time Clock (RTC) to the Raspberry Pi - Pi My Life Up

if you run into any errors after rebooting your Pi and attempting to read or write from and to the RTC Module there’s a possibility your coin battery is bad.

Finally it’s worth mentioning that in the adafruit guide, they mention that the Pi1 used the following command to check if the rtc circuit was correct, sudo i2cdetect -y 0 the bus address changed from 0 to 1 but on my Pi1 Model B+ only sudo i2cdetect -y 1 works, I would assume this may have been a software change and not a difference in hardware but I could be mistaken, please correct me if I’m wrong.

Please do let me know what you suggest I change from here @MichaIng and @Joulinar thanks for your time, hopefully someone find this information helpful in the future.

Oh, and I’ve also created a /etc/rc.local file and added the following line to it sudo hwclock -s -f /dev/rtc1 vmiceli mentions that in order to have the system time set from the DS3231 at boot you need to do so… but when attempting to enable the service via sudo systemctl restart rc.local.service supposedly the service doesn’t exist on my system, what’s the purpose of this, and do I need it? will the rtc time be applied to the system clock anyway?