2016-06-07 22:46:27 +01:00
|
|
|
.. currentmodule:: machine
|
2017-04-18 06:27:37 +01:00
|
|
|
.. _machine.RTC:
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
class RTC -- real time clock
|
|
|
|
============================
|
|
|
|
|
2021-01-19 09:22:04 +00:00
|
|
|
The RTC is an independent clock that keeps track of the date
|
2015-10-14 11:32:01 +01:00
|
|
|
and time.
|
|
|
|
|
|
|
|
Example usage::
|
|
|
|
|
|
|
|
rtc = machine.RTC()
|
2020-01-21 10:36:08 +00:00
|
|
|
rtc.datetime((2020, 1, 21, 2, 10, 32, 36, 0))
|
|
|
|
print(rtc.datetime())
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
Constructors
|
|
|
|
------------
|
|
|
|
|
2016-06-09 01:03:53 +01:00
|
|
|
.. class:: RTC(id=0, ...)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Create an RTC object. See init for parameters of initialization.
|
|
|
|
|
|
|
|
Methods
|
|
|
|
-------
|
|
|
|
|
2020-01-21 10:36:08 +00:00
|
|
|
.. method:: RTC.datetime([datetimetuple])
|
|
|
|
|
|
|
|
Get or set the date and time of the RTC.
|
|
|
|
|
|
|
|
With no arguments, this method returns an 8-tuple with the current
|
|
|
|
date and time. With 1 argument (being an 8-tuple) it sets the date
|
|
|
|
and time.
|
|
|
|
|
|
|
|
The 8-tuple has the following format:
|
|
|
|
|
|
|
|
(year, month, day, weekday, hours, minutes, seconds, subseconds)
|
|
|
|
|
|
|
|
The meaning of the ``subseconds`` field is hardware dependent.
|
|
|
|
|
2016-06-07 23:33:49 +01:00
|
|
|
.. method:: RTC.init(datetime)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Initialise the RTC. Datetime is a tuple of the form:
|
2019-12-04 04:02:54 +00:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
``(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])``
|
|
|
|
|
2016-06-07 23:33:49 +01:00
|
|
|
.. method:: RTC.now()
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Get get the current datetime tuple.
|
|
|
|
|
2016-06-07 23:33:49 +01:00
|
|
|
.. method:: RTC.deinit()
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Resets the RTC to the time of January 1, 2015 and starts running it again.
|
|
|
|
|
2020-07-11 07:53:26 +01:00
|
|
|
.. method:: RTC.alarm(id, time, *, repeat=False)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
2016-08-01 00:52:00 +01:00
|
|
|
Set the RTC alarm. Time might be either a millisecond value to program the alarm to
|
2015-10-14 11:32:01 +01:00
|
|
|
current time + time_in_ms in the future, or a datetimetuple. If the time passed is in
|
|
|
|
milliseconds, repeat can be set to ``True`` to make the alarm periodic.
|
|
|
|
|
2016-06-07 23:33:49 +01:00
|
|
|
.. method:: RTC.alarm_left(alarm_id=0)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Get the number of milliseconds left before the alarm expires.
|
|
|
|
|
2016-06-07 23:33:49 +01:00
|
|
|
.. method:: RTC.cancel(alarm_id=0)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Cancel a running alarm.
|
|
|
|
|
2020-07-11 07:53:26 +01:00
|
|
|
.. method:: RTC.irq(*, trigger, handler=None, wake=machine.IDLE)
|
2015-10-14 11:32:01 +01:00
|
|
|
|
|
|
|
Create an irq object triggered by a real time clock alarm.
|
|
|
|
|
|
|
|
- ``trigger`` must be ``RTC.ALARM0``
|
|
|
|
- ``handler`` is the function to be called when the callback is triggered.
|
|
|
|
- ``wake`` specifies the sleep mode from where this interrupt can wake
|
|
|
|
up the system.
|
|
|
|
|
|
|
|
Constants
|
|
|
|
---------
|
|
|
|
|
|
|
|
.. data:: RTC.ALARM0
|
|
|
|
|
|
|
|
irq trigger source
|