DS1307

The DS1307 real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar controllable via I2C protocol. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.

Using the module is simple:

from maxim.ds1307 import ds1307
import streams
streams.serial()

ds = ds1307.DS1307(I2C0)
ds.start()

while True:
    print("%02d:%02d:%02d - %02d/%02d/%d - %d"%ds.get_time())
    sleep(1000)

DS1307 class

class DS1307(drvname)

Creates a DS1307 instance using the MCU I2C circuitry drvname (one of I2C0, I2C1, ... check pinmap for details). The created instance is configured and ready to communicate.

DS1307 inherits from i2c.I2C, therefore the method start() must be called to setup the I2C channel before the RTC can be used.

get_time()

Return a tuple (hours,minutes,seconds,day,month,year,day_of_week) with the current time and date readings.

Current time is always expressed in the 24 hours format.

The time and date readings conversion algorithm assumes that the DS1307 has been previously configured with a call to set_time().

set_time(hours, minutes, seconds, day, month, year, day_of_week)

Configure the DS1307 with time hours:minutes:seconds expressed in 24 hours format. The value of year must be greater or equal than 2000 and day_of_week must be in range 1 to 7 included.