I have just shared content in Guides > PiicoDev: "PiicoDev Real Time Clock (RTC) RV-3028 - Getting Started Guide"
Read more
Hi, can you tell me the accuracy of this clock?
Earlier, I found somebody here was looking for an RTC with millisecond accuracy.
https://forum.core-electronics.com.au/t/rtc-to-milliseconds/14259/19
Is it possible to achieve that with your setup? Thank you.
Hi @tepalia02203352 - this clock isnât intended to be used as a lab-grade frequency standard. You can configure the CLK pin to output a squarewave at different frequencies if you wish to use it as a frequency standard - see the advanced examples section.
Real-Time Clocks are not usually used for very high-precision timing. For that, there exists a device called a âFrequency Standardâ or âFrequency Referenceâ. As the other thread mentioned, a GPS-disciplined oscillator can also work and is often cheaper.
If you need to guarantee long-term millisecond stability, have a look around for these devices.
I have a doubt that will the rtc program run in background even after we poweroff the pi or closing the programming application ( throny python after running code)
Hi Aadi,
Welcome to the forum!
The RTC module isnât just a program! Thereâs a dedicated chip that keeps the time for up to days at a time (provided the capacitor has been charged up)
Iâm trying to use the RV3028 RTC with a Raspberry Pi Pico W running CircuitPython as opposed to MicroPython. Is this possible?
WARNING: Do not run as main.py as will brick your Pico requiring a complete reset
Goal. Put Pico 2W to sleep for 2 seconds then using the RTC alarm wake-up the Pico. This code puts the Pico to sleep permanently:
from machine import, deepsleep
from drivers.PiicoDev_RV3028 import PiicoDev_RV3028
from drivers.PiicoDev_Unified import sleep_ms
RTC = PiicoDev_RV3028()
# Set alarm for 2 minutes from now
current_min = RTC.minute
current_hr = RTC.hour
next_min = (current_min + 1) % 60
next_hr = (current_hr + ((current_min + 1) // 60)) % 24
RTC.alarmMinutes = next_min + 1
RTC.alarmHours = next_hr
RTC.alarmWeekdayDate = RTC.day # same day
RTC.alarm_ampm = â24â
RTC.alarmSetup()
# Confirm setup
print(ââ Alarm configured:â)
print(f" Hour: {RTC.alarmHours}â)
print(fâ Minute: {RTC.alarmMinutes}â)
print(fâ Date: {RTC.alarmWeekdayDate}")
print(f"Alarm set for {next_hr:02}:{next_min:02}")
sleep_ms(200)
# Enter deep sleep
print(âEntering deep sleepâŚâ)
deepsleep()
Hey @Jon140244,
Thanks for sharing this project!
Good idea to include that warning about naming the code file something other than main.py. I can imagine that may be a tip discovered from personal experience, followed by a bit of head scratching to figure out why the Pico isnât turning on.
Thanks again!
Apologies: my question is why doesnât this work? The logic looks pretty simple:
- connect to PiicoDev_RV3028
- set alarm
- confirm alarm
- enter deepsleep. IE: put Pico2W (RP2350) to deep sleep until it is woken by the PiicoDev_RV3028 by the alarm set in #2
When it hits #4 / deepsleep it never wakes up. The only way to reset it is to unplug power and reconnect.
Hey @Jon140244,
Sorry about the confusion with that. I think this comes down to a misunderstanding as to how deepsleep on the Pico works. When the Pico enters deepsleep, it stops all running processes, including this code. If you wake the device from deepsleep it will start running as if it has just been connected to power which means running main.py from the beginning.
As your code is currently written, it wonât be able to wake up from deepsleep as the code before the deepsleep() line is effectively forgotten.
I would consider switching over to use the lightsleep function. This will still reduce the power consumption of the Pico by a fair amount, but allows it to still run useful features such as the inbuilt timer and a few other things.
I donât have a ton of experience with either deepsleep or lightsleep but lightsleep looks like a much better road to go down.
Hope this helps!
Thanks Samuel
From what I can see from deepsleep and lightsleep using (MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico 2 W with RP2350) they function the same.
I also agree that either will put the Pico into a sleep mode when executed.
My understanding of the PiicoDev_RV3028 is it would fire an interrupt (in my case after 2 minutes using alarmSetup) waking up the Pico and running main.py from scratch?
Would i be correct in this assumption?
Results from some debugging. Deepsleep() and ligfhtsleep() do the following:
- deepsleep() restarts the Pico, no wait, just a plain reboot, power off/power on
- lightsleep() doe3s absolutely nothing
Below is the power usage as shown using: Power Profiler Kit II - nordicsemi.com that seems to prove there is basically no deep or light sleep occuring:
Example source:
from machine import Pin, lightsleep, deepsleep
import time
from drivers.PiicoDev_RV3028 import PiicoDev_RV3028
from drivers.PiicoDev_Unified import sleep_ms
from drivers.PiicoDev_Buzzer import PiicoDev_Buzzer
# INT pin used to wake from deep sleep (connect RV3028 INT to GPIO15)
INT_PIN = Pin(15, Pin.IN, Pin.PULL_UP)
LED = Pin("LED", Pin.OUT)
RTC = PiicoDev_RV3028()
BUZZ = PiicoDev_Buzzer()
# Detect if INT pin is low = woke from RTC alarm
if INT_PIN.value() == 0:
print('â
Woke from RTC alarm')
else:
print('âšď¸ Normal boot')
# Check if last wake was due to alarm
if RTC.getEventInterrupt():
print("â
Alarm triggered last wake.")
RTC.resetEventInterrupt()
else:
print("âšď¸ No alarm interrupt detected.")
if RTC.checkAlarm():
# RTC.alarmSetup(minutes=36) # set alarm for {n}th minute
print("Alarm Triggered: YES: checkAlarm()")
else:
print("Alarm Triggered: NO: checkAlarm()")
# Init RTC
RTC = PiicoDev_RV3028()
sleep_ms(50)
# LED on during reading
LED.on()
date_time = RTC.timestamp()
print(f'{date_time=}')
sleep_ms(550)
LED.off()
# ---
def blink_led(times, interval):
for _ in range(times):
LED.on()
time.sleep_ms(interval)
LED.off()
BUZZ.tone(800, 500) # high tone (800Hz for 500ms)
sleep_ms(500)
BUZZ.tone(400, 500) # low tone (400Hz for 500ms)
sleep_ms(5500)
while True:
BUZZ.tone(100, 250)
sleep_ms(500)
blink_led(6, 200)
time.sleep(1)
print('entering light sleep: start')
BUZZ.tone(250, 400)
lightsleep(2000)
print('entering light sleep: end')
blink_led(6, 400)
time.sleep(1)
print('entering deep sleep: start')
deepsleep(4000)
print('entering deep sleep: end')
blink_led(6, 800)
time.sleep(10)
print('awoken, one more time!')
And the following (with no parameters) locks up the Pico and do nothing further until power off/on, issuing a Run/Stop/Restart backend does nothing and responds with âDevice is busy or does not respondâŚâ:
- lightsleep()
- deepsleep()
Hey @Jon140244,
Youâre correct that lightsleep()
isnât particularly meaningful on the Pico, it doesnât reduce power or suspend processing in any useful way. It behaves more like a simple delay and does not engage any low-power features or allow wake-up from interrupts.
To achieve your goal of:
âputting the Pico 2W into a low-power state for 2 minutes, then waking it via the PiicoDev RV3028 RTC alarm,â
you can still use deepsleep()
, but with a small hardware-assisted trick.
Since deepsleep()
on the RP2040 simply resets the device (it doesnât halt and resume like on some other MCUs), the key is to use the RV3028âs interrupt pin to signal that the alarm has triggered, and then detect that on boot.
Hereâs a general approach:
- Connect the RV3028âs INT pin to a GPIO on the Pico (e.g., GPIO15).
- On first boot, configure the RTC alarm for a future time (e.g., 2 minutes ahead).
- Enter
deepsleep()
, which will reboot the Pico when it wakes. - On reboot, check if the INT pin is low and verify the RTCâs alarm flag â this tells you that you woke due to the alarm.
- If so, run your wake-up logic. Otherwise, itâs a fresh boot, and the process repeats.
I think this approach should be solid for the goal you outlined in your previous posts.