DS1307
I2C RTC driver for DS1307
https://github.com/mcauser/micropython-tinyrtc-i2c
MIT License
Copyright (c) 2018 Mike Causer
Extended 2023 by brainelectronics
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
BCD Format:
https://en.wikipedia.org/wiki/Binary-coded_decimal
-
class ds1307.ds1307.DS1307(addr=104, i2c: None = None)[source]
Bases: object
Driver for the DS1307 RTC.
-
_bcd_to_dec(value: int) → int[source]
Convert binary coded decimal (BCD) format to decimal
- Parameters
value (int) – The value
- Returns
Decimal value
- Return type
int
-
_dec_to_bcd(value: int) → int[source]
Convert decimal to binary coded decimal (BCD) format
- Parameters
value (int) – The value
- Returns
Binary coded decimal (BCD) format
- Return type
int
-
property addr: int
Get the DS1307 I2C bus address
- Returns
DS1307 I2C bus address
- Return type
int
-
property datetime: None
Get the current datetime
(2023, 4, 18, 0, 10, 34, 4, 108)
y, m, d, h, m, s, wd, yd
- Returns
(year, month, day, hour, minute, second, weekday, yearday)
- Return type
Tuple[int, int, int, int, int, int, int, int]
-
property day: int
Get the day from the RTC
- Returns
Day of RTC
- Return type
int
-
day_of_year(year: int, month: int, day: int) → int[source]
Get the day of the year
- Parameters
year (int) – The year
month (int) – The month
day (int) – The day
- Returns
Day of the year, January 1 is day 1
- Return type
int
-
property halt: bool
Get status of DS1307
- Returns
Status of DS1307
- Return type
bool
-
property hour: int
Get the hour from the RTC
- Returns
Hour of RTC
- Return type
int
-
is_leap_year(year: int) → bool[source]
Determines whether the specified year is a leap year.
- Parameters
year (int) – The year
- Returns
True if the specified year is leap year, False otherwise.
- Return type
bool
-
property minute: int
Get the minute from the RTC
- Returns
Minute of RTC
- Return type
int
-
property month: int
Get the month from the RTC
- Returns
Month of RTC
- Return type
int
-
property second: int
Get the second from the RTC
- Returns
Second of RTC
- Return type
int
-
square_wave(sqw: int = 0, out: int = 0) → None[source]
Output square wave on pin SQ
at 1Hz, 4.096kHz, 8.192kHz or 32.768kHz, or disable the oscillator
and output logic level high/low.
-
property weekday: int
Get the weekday from the RTC
- Returns
Weekday of RTC
- Return type
int
-
property weekday_start: int
Get the start of the weekday
- Returns
Weekday start
- Return type
int
-
property year: int
Get the year from the RTC
- Returns
Year of RTC
- Return type
int
-
property yearday: int
Get the yearday from the RTC
- Returns
Yearday of RTC
- Return type
int