RV3028 and Raspberry Pi Pico

Hi everybody
I come to you with a question about the RV3028 breakout card
I use it with Pico Explorer
when I start the first time the RTC says
(2000, 1, 1, 5, 0, 0, 6, 0)
when I read with this program
import machine
import time
import RV3028

sda=machine.Pin(20)
scl=machine.Pin(21)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

ds=RV3028.RV3028(i2c)
print(ds.datetime())

the function datetime is in the RV3028 library

*def datetime(self, datetime=None):*
  •    """Get or set datetime"""*
    
  •    if datetime is None:*
    
  •        buf = self.i2c.readfrom_mem(self.addr, DATETIME_REG, 7)*
    
  •        return (*
    
  •            self._bcd2dec(buf[6]) + 2000, # year*
    
  •            self._bcd2dec(buf[5]), # month*
    
  •            self._bcd2dec(buf[4]), # day*
    
  •            self._bcd2dec(buf[3] - self.weekday_start), # weekday*
    
  •            self._bcd2dec(buf[2]), # hour*
    
  •            self._bcd2dec(buf[1]), # minute*
    
  •            self._bcd2dec(buf[0] & 0x7F), # second*
    
  •            0 # subseconds*
    
  •        )*
    

It reads the first datas in the RTC

%Run -c $EDITOR_CONTENT
(2000, 1, 1, 5, 0, 0, 6, 0) => year, month, day, weekday, hour, minute, seconds

Then I write the actual value of time with this program : (for now time is coded in the program)

import machine
import time
import RV3028

sda=machine.Pin(20)
scl=machine.Pin(21)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

ds=RV3028.RV3028(i2c)
print(ds.datetime())
print (“Ecriture date actuelle”)

# Créer un bloc de data
an = bytearray(7)
an[0]=0 # Secondes BCD
an[1]=0x05 # Minutes
an[2]=04 # Heures
an[3]=5 # Jour de la semaine
an[4]=0x18 # Date
*an[5]=4 # Mois *
an[6]=0x21 # Année
i2c.writeto_mem(0x52, 0, an)
print(ds.datetime())
i2c.readfrom_mem (0x52, 0, 7)
print (“Relecture”)

Ecriture date actuelle (write actual time) year is 2021, month 4…
(2021, 4, 18, 4, 4, 5, 0, 0)
Relecture Then i launch the read program :

%Run -c $EDITOR_CONTENT
(2021, 4, 18, 4, 4, 5, 38, 0)
%Run -c $EDITOR_CONTENT
(2021, 4, 18, 4, 4, 6, 7, 0)
%Run -c $EDITOR_CONTENT
(2021, 4, 18, 4, 4, 8, 11, 0)

You can see when i launch succesive reads seconds grow and then minutes… the clock works well

Now i disconnect the PICO, wait a moment then connect again
Then i read data again on the breakout RV3028

%Run -c $EDITOR_CONTENT
(2000, 1, 1, 5, 0, 0, 5, 0)

What I wrote is gone and we are back to the original settings (January 2000)

I tested the battery : it’s ok Voltage > 1.5v

Do you have an idea ?

I got lost a bit in what you posted but I’ll chime in on my experience with that breakout on a Pi. It’s my understanding that the backup battery isn’t enabled out of the box. If you look at the set-time.py file it states the following.
print("""set-time.py - Sets RTC with current time for your system and
enables battery backup to preserve the time when power is off.
I’ve used several of these on Raspberry Pi’s. I do the sudo pip install rv3028 then run the set-time.py and get-time.py. Then do my normal RTC setup stuff.
Have a look at the set-time.py file
rv3028-python/set-time.py at master · pimoroni/rv3028-python · GitHub
I think you need to do the equivalent to
rtc.set_battery_switchover('level_switching_mode')
It may be easier to just connect it to a Raspberry Pi and run the set time. As far as I know you only have to do this once.

Thank you !
OK i understand i only have breakout on pico explorer but i will connect the bord on pi and try it !
Many thanks 🙂

On a sort of side note, I do believe the PICO have an onboard RTC. No battery backup for it though, so you’d have to have reliable 24/7 power or run the PICO on battery. The new PICO LIPO Shim may fit the bill?
LiPo SHIM for Pico – Pimoroni
I have one on order so I may be testing this out at some point.
If you get yours working please share your code. =)

I’m also wondering if the onboard one is maybe messing things up for you?

Hello
yes indeed in the RP2040 datasheet the RTC is mentioned in 4.8.
The idea here is not to make the Pico work 24/24h but to implement breakout cards or other components in I2C.
In this example I have a BME680 sensor in the breakout1 slot which I access in micropython to read the information and then display it on the Pico Explorer screen. This works. I would now like to integrate this RV3028 RTC card so that when we connect the power to the Pico, it sets the time and displays date+time+climate information.
The purpose is mainly educational to discover the different Pimoroni breakout boards with MicroPython.
Thank you for your answers and of course if I have a solution that works it will be online on my blog: www.framboise314.fr where I have started to publish articles on Pico. Vous avez cherché pico - Framboise 314, le Raspberry Pi à la sauce française....

Wow, impressive, don’t let me slow you down. =)
I’ve used a bunch of the Breakout Garden stuff on a Pi. I have several of what I call Weather clocks. They display the Day, Date, Time, Temperature, Humidity and Barometric Pressure in a scrolling message on a Unicorn HD. They have RV3028 RTC’s in them so the date and time is bang on on boot up. Plus one is portable and may not have WIFI to update it on its own. BME280’s mostly. Some also have the light sensor and UV sensor breakouts. Some have the 0.96 LCD breakout and run modified Enviro+ code.

Anyway, long story made short, I want to replicate a lot of that on a PICO. I have the Explorer Pack on the way, I wanted the PICO Breakout Garden but its still listed as coming soon. I’ll be doing something similar in a few weeks, well trying to anyway.

I’m also keen on this idea using the RV3028 RTC to set the time. Which library did you use? Keep us posted.

Hi i used rv3038.py for python lib. Now i start from other libs for other rtc but for micropython. I am not full time on it but will publish when i progress

1 Like

Ok thanks,

I was just fiddling with this one, works nicely.

Thank you !! i try it today :)

1 Like

Seems to hold time, ran my program this morning and clock still correct. :-)

1 Like

hi
it works here too
thank you :)

from machine import Pin, I2C
import time
import rv3028_rtc

sda=machine.Pin(20)
scl=machine.Pin(21)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=100000)

rtc=rv3028_rtc.RV3028(0x52, i2c, "LSM")

print (rtc.get_rtc_date_time())
# Valeur actuelle des registres An, mois, date...
date_actuelle = (2021, 04, 22, 15, 37, 0)
rtc.set_rtc_date_time(date_actuelle)
1 Like

Just FYI code tags for this forum are three ` before and after your code.
On my English US keyboard its the key to the left of the 1 key with
~

That will retain indents etc for you.

Thank you :) i try to edit…

Hi
All is now here

1 Like

Hello, thank you for the PICO MicroPython code. Have tested the RV3028 with I2C Scanner and device is found:

Scanning the i2c bus …
Component (s) detected : 1
Address in decimal : 82 | Address in Hexadecimal : 0x52
But when I run the Clock check/Set I get the following:

Traceback (most recent call last):
File “”, line 9, in
File “rv3028_rtc.py”, line 147, in init
File “rv3028_rtc.py”, line 371, in _get
OSError: [Errno 5] EIO

Can you help?
I have installed the driver and am using GPIO Pins 8 for data and 9 for CLK.
Just using PICO on breadboard, not the Pico Explorer like you. ;-)
Thanks
Chas
Many thanks

Whenever I got EIO error it was an issue with the RV3028 not connected to the Pico. I found with not solering the connectors I would sometimes get EIO errors.

Just check the connectors are 100%.

1 Like

Thank you. I reflowed the PIN connections and tried again, et. voilá it now works :)

Odd though that the I2C test worked?

I guess depends on which pin was a cold solder. Glad it worked.