The RTC is used to keep track of the date and time.
from machine import RTC rtc = RTC() rtc.init((2014, 5, 1, 4, 13, 0, 0, 0)) print(rtc.now())
Create an RTC object. See init for parameters of initialisation.
# id of the RTC may be set if multiple are connected. Defaults to id = 0. rtc = RTC(id=0)
Initialise the RTC. The arguments are:
datetimewhen passed it sets the current time. It is a tuple of the form:
(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
sourceselects the oscillator that drives the RTC. The options are RTC.INTERNAL_RC and RTC.XTAL_32KHZ
# for 2nd of February 2017 at 10:30am (TZ 0) rtc.init((2017, 2, 28, 10, 30, 0, 0, 0))
tzinfo is ignored by this method. Use
time.timezone to achieve similar results.
Get get the current
# returns datetime tuple rtc.now()
Set up automatic fetch and update the time using NTP (SNTP).
serveris the URL of the NTP server. Can be set to
Noneto disable the periodic updates.
update_periodis the number of seconds between updates. Shortest period is 15 seconds.
Can be used like:
rtc.ntp_sync("pool.ntp.org") # this is an example. You can select a more specific server according to your geographical location
True if the last
ntp_sync has been completed,
- Clock source: