pimoroni-pico
                                
                                 pimoroni-pico copied to clipboard
                                
                                    pimoroni-pico copied to clipboard
                            
                            
                            
                        Micropython RTC set_unix() not working
I've been trying to sync the RTC to the current time and I'm having problems.
I've been using the Thonny console since this appears to set the current board time to the computer time when connected. I tried pasting the following script into the console.
As you can see the set_unix() returns True but does not update the rtc values returned after update_time() is called.
from pimoroni_i2c import PimoroniI2C
from breakout_rtc import BreakoutRTC
import time
PINS_PLASMA = {"sda": 20, "scl": 21}
i2c = PimoroniI2C(**PINS_PLASMA)
rtc = BreakoutRTC(i2c)
rtc.set_24_hour()
rtc.update_time()
print(rtc.string_time())
print(rtc.string_date())
time.localtime()
rtc.set_unix(time.time())
rtc.update_time()
print(rtc.string_time())
print(rtc.string_date())
True
00:00:25
01/01/2000
(2021, 9, 18, 18, 14, 41, 5, 261)
True
True
00:00:25
01/01/2000
If I use the rtc.set_time() with suitable values it works:
>>> rtc.set_time(20,23,18,6,18,9,2021)
True
>>> rtc.update_time()
print(rtc.string_time())
print(rtc.string_date())
True
18:23:44
18/09/2021
Using a Plasma 2040 with the v0.2.6 release (MicroPython with Pimoroni Libs + Adafruit Blinka + Adafruit PlatformDetect)
OK, I assume I need to call rtc.set_backup_switchover_mode() to enable the battery backup and allow the RTC to maintain the time, but I have no idea what value I should pass to this.
OK, looking at the desktop code I've assume rtc.set_backup_switchover_mode() should be passed 3 for level_switching_mode.
So the only outstanding issue is that rtc.set_unix() doesn't  look to work
This might explain the set_unix() issue:
https://github.com/pimoroni/pimoroni-pico/blob/37209cd0c005c8c186fa63ab1c06ec714f2f525a/drivers/rv3028/rv3028.cpp#L385-L401
It looks like the unix timestamp is completely independent from the rest of the RTC... hooookaay! That's a gotcha. I think we might need a bit of documentation to cover that.
yeah, some docs for how to enable from new (rtc.set_backup_switchover_mode()) and that unix time != "real" time would be useful.
Thank.