experimental.clocks.ds1307

Interface class for the DS1307 Realtime Clock

This class is designed to work with a DS1307 chip mounted on an I2C carrier board that can be connected to EuroPi’s external I2C interface. The user is required to 1) provide their own RTC module 2) create/source an appropriate adapter to connect the GND, VCC, SDA, and SCL pins on EuroPi to the RTC module 3) Mount the RTC module securely in such a way that it won’t come loose nor accidentally short out any other components.

Based on work by Mike Causer released under the MIT license (c) 2018: https://github.com/mcauser/micropython-tinyrtc-i2c/blob/master/ds1307.py

NOTE: the author of this module does NOT have access to a DS1307 module; this class is thoroughly untested. USE AT YOUR OWN RISK.

Hopefully I, or another EuroPi contributor, will get access to the required module to validate the code. But at present this class is provided as-is, based wholly on Mike Causer’s work with the necessary changes to support EuroPi’s RTC interface.

class experimental.clocks.ds1307.DS1307(i2c, addr=104)

Driver for the DS1307 RTC.

check_valid_datetime(datetime)

Check if a datetime contains valid values.

Raises

ValueError – if any field is out of range

Parameters

datetime – The datetime tuple to validate

datetime()

Get the current time.

Returns

a tuple of the form (0-year, 1-month, 2-day, 3-hour, 4-minutes, 5-seconds, 6-weekday, 7-yearday)

halt(val=None)

Power up, power down or check status

is_leap_year(datetime)

Determine if the datetime’s year is a leap year or not.

Returns

True if the datetime is a leap year, otherwise False

month_length(datetime)

Get the numer of days in the month.

This takes leap-years into consideration

Returns

The number of days in the datetime’s month

set_datetime(datetime)

Set the current time.

Parameters

datetime – tuple of the form (0-year, 1-month, 2-day, 3-hour, 4-minutes, 5-seconds, 6-weekday, 7-yearday)

square_wave(sqw=0, out=0)

Output square wave on pin SQ

Available frequencues: 1Hz, 4.096kHz, 8.192kHz or 32.768kHz, or disable the oscillator and output logic level high/low.

year_length(datetime)

Determine the number of days in the datetime’s year.

Returns

The number of days in the year, taking leap years into account