# RV3028 RTC with PICO, set time to local time?

**URL:** <https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419>\
**Category:** Support\
**Created:** [July 2, 2021, 6:22pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419 "2021-07-02T18:22:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 2, 2021, 6:22pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/1 "2021-07-02T18:22:27Z")

</div>

I just got my PICO Breakout Garden and plugged an RV3028 RTC Breakout in.  
I ran the demo for it and it worked just fine. Seems to have set it to GMT time though?  
I’d like to set it to local time instead and could use some help.  
The demo file is as follows.  
from pimoroni\_i2c import PimoroniI2C  
from breakout\_rtc import BreakoutRTC  
import time

```auto
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} # i2c pins 4, 5 for Breakout Garden
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} # Default i2c pins for Pico Explorer

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
rtc = BreakoutRTC(i2c)

if rtc.is_12_hour():
    rtc.set_24_hour()

rtc.enable_periodic_update_interrupt(True)

while True:
    if rtc.read_periodic_update_interrupt_flag():
        rtc.clear_periodic_update_interrupt_flag()

        if rtc.update_time():
            rtc_date = rtc.string_date()
            rtc_time = rtc.string_time()
            print("Date: ", rtc_date, ", Time: ", rtc_time, sep="")

    time.sleep(0.1)

```

Reading it without updating first would be an option too. I can easily set it on a Pi.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 2, 2021, 7:47pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/2 "2021-07-02T19:47:04Z")

</div>

If I do this

```auto
#if rtc.is_12_hour():
rtc.set_12_hour()

#rtc.enable_periodic_update_interrupt(True)

```

I get 12 hour time and it doesn’t auto update. Just have to figure out how to set it to a specific time?  
@gadgetoid

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 5, 2021, 6:11pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/3 "2021-07-05T18:11:52Z")

</div>

Anybody? =( Am I the only one using this breakout with a PICO?  
@hel

---

<div class="post-metadata">

**Author:** ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)\
**Post date:** [July 6, 2021, 11:25am UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/4 "2021-07-06T11:25:29Z")

</div>

I’ve not had chance to plug one of these into a Pico yet, but it looks like you should be able to set the RTC time with `rtc.set_time(sec, min, hour, weekday, date, month, year)` (there are also micropython bindings for `set_seconds`, `set_minutes` etc if you just want to set one of the parameters?)

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 6, 2021, 11:39am UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/5 "2021-07-06T11:39:00Z")

</div>

Thanks, I’ll give that a try and post back how it goes.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 6, 2021, 1:08pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/6 "2021-07-06T13:08:10Z")

</div>

What do you enter for year? Or have I messed up one of the other entries?  
rtc.set\_time(00, 00, 09, 02, 06, 07, 00)  
gets me  
Date: 06/07/2048, Time: 09:00:20AM  
and  
rtc.set\_time(00, 00, 09, 02, 06, 07, 21)  
gets me  
Date: 06/07/2069, Time: 09:00:00AM

Using 2021 for year gets me  
ValueError: year out of range. Expected 0 to 99

EDIT: Is the following correct?  
rtc.set\_time(sec, min, hour, weekday, date, month, year)  
sec = 0-59  
min = 0-59  
hour = 0-23  
weekday = 1-7  
date = 1-31  
month = 1-12  
year = 0-99

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 6, 2021, 6:21pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/7 "2021-07-06T18:21:48Z")

</div>

Once I run rtc.set\_time its all down hill from there. I get the wrong year 2069 and running the stock demo file won’t reset it / update it to UTC? Even taking the battery out didn’t help? Running the demo just got me  
Date: 01/01/2000, Time: 00:00:01 and it wouldn’t update? I’ve tried two different RV3028’s that worked as advertised on my Raspberry Pi Breakout Garden. I’ll have to plug this one into my raspberry Pi and run set\_time.py to get it back to the correct time.

---

<div class="post-metadata">

**Author:** ![lexfiend](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/lexfiend/32/7136_2.png) [@lexfiend](https://forums.pimoroni.com/u/lexfiend)\
**Post date:** [July 7, 2021, 10:42am UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/8 "2021-07-07T10:42:43Z")

</div>

It looks like a library bug. [`rtc.set_time`](https://github.com/pimoroni/pimoroni-pico/blob/cb958a7c8a73cdc51873058be4918b893d2c7797/micropython/modules/breakout_rtc/breakout_rtc.cpp#L101-L145) constrains the year to the range [00-99], but then calls the [corresponding RV3028 driver routine](https://github.com/pimoroni/pimoroni-pico/blob/cb958a7c8a73cdc51873058be4918b893d2c7797/drivers/rv3028/rv3028.cpp#L114-L134), which treats it as a 16-bit unsigned int _and subtracts 2000 from it_.

When you take all that into account, the results you got are actually inevitable:

`00` (rtc) → `-2000` (RV3028) → `0xf830` (16-bit uint) → `72` (BCD) → **`48`** (decimal)

`21` (rtc) → `-1979` (RV3028) → `0xf845` (16-bit uint) → `105` (BCD) → **`69`** (decimal)

`2021` (rtc) → `21` (RV3028) → `0x0015` (16-bit uint) → `33` (BCD) → **`21`** (decimal)

Methinks `rtc.set_time` should actually take the full year instead of artificially constraining the input value.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 7, 2021, 11:05am UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/9 "2021-07-07T11:05:39Z")

</div>

I think I’m going to have to report this as an issue on the github page.  
Thanks for posting that info.

EDIT: [RV3028 RTC with PICO, manual set time doesn’t work correctly. · Issue #176 · pimoroni/pimoroni-pico (github.com)](https://github.com/pimoroni/pimoroni-pico/issues/176)

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [July 7, 2021, 7:28pm UTC](https://forums.pimoroni.com/t/rv3028-rtc-with-pico-set-time-to-local-time/17419/10 "2021-07-07T19:28:14Z")

</div>

@lexfiend Problem solved / fixed by Phil Howard @gadgetoid. There is a link to the fixed file here.  
[RV3028 RTC with PICO, manual set time doesn’t work correctly. · Issue #176 · pimoroni/pimoroni-pico (github.com)](https://github.com/pimoroni/pimoroni-pico/issues/176#issuecomment-875734795)

What you posted was the issue and that info made fixing it easier. Thanks.
