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 initialization.
# id of the RTC may be set if multiple are connected. Defaults to id = 0. rtc = RTC(id=0)
Initialize the RTC. The arguments are:
datetime
(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
source
RTC.INTERNAL_RC
RTC.XTAL_32KHZ
For example:
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.
tzinfo
time.timezone
Inits the RTC and sets up automatic fetch and update the time using NTP (SNTP).
server
None
update_period
backup_server
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
Get get the current datetime tuple as (year, month, day, hour, minute, second, usecond, None)
(year, month, day, hour, minute, second, usecond, None)
Returns True if the last ntp_sync has been completed, False otherwise.
True
ntp_sync
False
Reads RTC memory contents or write data in passed Buffer in to RTC memory. The buffer has space to store 2048 bytes.
Example:
rtc = RTC() rtc.memory(b'10101010') # writes data in RTC memory rtc.memory()
Output:
b'10101010'