RV3028 RTC not passing time to Raspbian?

I ran sudo pip install rv3028 and sudo pip3 install rv3028.
Then ran the set-time.py file. And get-time.py shows the correct time.
Raspbian isn’t getting the correct time from the RTC though.
As a test I let Raspbian sync its time online, ran set-time.py and verified it with get-time.py.
Disconnected from the Internet and shut down.
On boot up the displayed time is the time it was shut down at, but get-time.py shows the correct time is stored in the RV3028?
I even did the manual install, but same deal. The RV3028 has the correct time stored but its not passed on to Raspbian? Raspbian Buster with desktop on a Pi 3B+.

  • git clone https://github.com/pimoroni/rv3028-python
  • cd rv3028-python
  • sudo ./install.sh

i2c is enabled and i2cdetect shows it at address 52.

I got it working but its not a real fix for the one line installer. At least I know the hardware is fine, its a software issue. I did the following
I enabled i2c via raspberry Pi Configuration
Then opened a terminal window and ran
sudo i2cdetect -y 1
The RV3028 shows up as 52
I then edited the config.txt
sudo nano /boot/config.txt
and added
dtoverlay=i2c-rtc,rv3028
ctrl x, y, enter
sudo reboot
Then open the terminal window and ran
sudo i2cdetect -y 1
The 52 is now UU which means its under system control

Next I disable the “fake hwclock” which interferes with the ‘real’ hwclock
sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
sudo systemctl disable fake-hwclock

Now with the fake-hw clock off, you can start the original ‘hardware clock’ script.
sudo nano /lib/udev/hwclock-set
and comment out these three lines:
#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

Also comment out the two lines
/sbin/hwclock --rtc=$dev --systz --badyear
/sbin/hwclock --rtc=$dev --systz

ctrl x, y, enter

Sync time from Pi to RTC

sudo hwclock -w
sudo hwclock -r
sudo reboot

A side effect of doing all this is now set-time.py and get-time.py no longer work, they error out.
I had already run set-time.py to enable the battery backup, otherwise I would still be sol.
I would really like to get some feedback from somebody at Pimoroni
@gadgetoid @sandyjmacdonald

Thanks to your guide alphanumeric. I think this guide sould defitely be in the RV3028 pimoroni webpage…whilst there is just some python code to read and write to the clock.
So if someone of the support is reading us…please update the RV3028 documentation

And i have a question for you…as the rtc can “loose” 1 seconds every 11 days (more or less), i wanted to sync the hwclock with an ntp server on the boot every time an internet connection is available. What way could be the best to achieve that in your opinion?
Thanks

I do believe it does that all on its own. Raspbian I mean. My understanding is Raspbian will still sync and update its time. And that updated time will get saved to the RTC. Thats what I was told on the Pi foundation forums anyway. I’ve never bothered to or had to manually update the time on the several RTC equipped Pi’s I have on the go. Not after setting them correctly that once during setup.

Thank you alphanumeric, you are very precious.
I’ve find a document that could be interesting to this link:
At the end it says:
Please note that when system clock is set to Local Time, systemd-timesyncd won’t update hardware clock.
So, as you said, with default settings (system clock not set to Local Time), timesyncd should update hardware clock.
To check settings:
timedatectl | grep local
as shown in this link

I’ve updated our README to at least mention that the Python library/installer there doesn’t set up the RV3028 as a realtime clock - https://github.com/pimoroni/rv3028-python/commit/80810d298b37e1ddbab64b9a33d8bcc757c54176

It looks like @alphanumeric has gone into much more detail, however, and I think this would be worthy of a Learning Portal article and probably some details on the store page. It’s a little off topic for GitHub, frustratingly since that’s expressly for the Python driver.

@alphanumeric was the backup-switchover-mode=1 option not available to you when you set this up?

Also, running the Kernel driver will break the Python library quite handily, since it reserves the i2c address used for the device and wont let anything else communciate with it. This is why I needed to upstream the backup-switchover-mode option.

I didn’t know about the backup-switchover-mode=1 Should I edit my dtoverlay entry and add it?

I should probably give credit where credit is due. Most of what I posted above is in a tutorial on Adafruit’s site. It’s what I used to setup my DS3231’s. I had it all clip and pasted into a text file for reference. Should have mentioned this earlier.

@gadgetoid

Changing dtoverlay=i2c-rtc,rv3028 to dtoverlay=i2c-rtc,rv3028,backup-switchover-mode=1
has broken something?
Raspbian is no longer getting the time from the RTC.
And running sudo hwclock -r now gets me an error message.
hwclock: ioctl(RTC_RD_TIME) to .dev/rtc0 to read time failed: invalid argument
If I do a write then a read, hwclock -r works with no error message?
If I connect to the Internet the time updates to the correct time, and I can write that to the RTC. If I disconnect from the Internet and shut down for a while. When I boot back up the time is what it was when I shut down. Even after changing the entry back to just dtoverlay=i2c-rtc,rv3028.

EDIT: It appears that the battery backup got turned “off”?
I have a second RV3028 that I had also setup and tested on this Pi. I swapped that in and hwclock -r worked with no error. And after syncing the time, and doing a write and read it worked just fine. That Pi was back to keeping accurate time with no Internet connection.
So I swapped the other RTC back in, remarked out the dtoverlay=i2c-rtc,rv3028 line in config.txt, and rebooted. That let me run set-time.py and turn the battery backup back on. Then I reinstated the dtoverlay=i2c-rtc,rv3028 entry and rebooted. I then synced the time, did a write and read, and rebooted. Now this one is working again also.

I’m still having issues with that one breakout that was installed when I did the config.txt edit. I started a new thread on it. I could use some help with this Phil @gadgetoid or Sandy @sandyjmacdonald

EDIT: It appears to be a dud battery. It tests in the red on my battery tester set for 1.5V coin cells. I’ll have to have a look for one at a pharmacy etc.

If you go to the other thread I started, linked to in my post above, you will see I had a major fight getting this working again. Until told otherwise by somebody from Pimoroni I would “not” add the backup-switchover-mode=1 to the config.txt dtoverlay entry, just use the following.
dtoverlay=i2c-rtc,rv3028
If you run the python set time file before making that config.txt edit it will work. It will set the time and put the battery in the correct backup mode. Once you make that entry and reboot, you can use sudo hwclock -w and sudo hwclock -r.
I redid my install from scratch, just as I had done it the first time around detailed above and it is working. I left it shut down with the power supply unplugged overnight 12+ hours and it was working when I checked it moments ago. I booted it up with no Internet connection and the time was accurate.
And running sudo hwclock -r worked with no error message.
I’m going to hold off testing my second RV3028 until I can get a replacement battery for it.