Adafruit uRTC library for real time clock modules

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
deshipu
Posts: 1348
Joined: Thu May 28, 2015 5:54 pm

Adafruit uRTC library for real time clock modules

Post by deshipu » Mon Aug 15, 2016 7:27 pm

I have to say that I was very wrong about Adafruit not caring about MicroPython. They actually are supporting me now in writing MicroPyton libraries for their products. The first one is the library for real-time clock modules -- right now it supports DS1307, DS3231 and PCF8523.

The source is at https://github.com/adafruit/Adafruit-uRTC. The documentation is at http://micropython-urtc.rtfd.io/, and it should also soon be available in the cheeseshop.

Testing and feedback appreciated.

joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: Adafruit uRTC library for real time clock modules

Post by joehunt588 » Thu Aug 18, 2016 7:22 am

Thank you for the info, :) :) it really help

dubaleeiro
Posts: 6
Joined: Mon Feb 12, 2018 9:52 pm

Re: Adafruit uRTC library for real time clock modules

Post by dubaleeiro » Wed Feb 28, 2018 8:21 pm

Hello,
I am trying to update only one time element at a time (hour for example) using the library for DS1307 RTC, but it seems that one single element can be updated only when the "year" is part of the tuple. For example when I try:

>>> rtc.datetime(urtc.datetime_tuple(year=2002))
>>> rtc.datetime()
DateTimeTuple(year=2002, month=0, day=0, weekday=0, hour=0, minute=0, second=9, millisecond=None)
it works fine. But when I try to update only the month I got an error:

>>> rtc.datetime(urtc.datetime_tuple(month=2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "urtc.py", line 88, in datetime
TypeError: unsupported types for __sub__: 'NoneType', 'int'

However it works when I try:
>>> rtc.datetime(urtc.datetime_tuple(year=2001, month=3))
>>> rtc.datetime()
DateTimeTuple(year=2001, month=3, day=0, weekday=0, hour=0, minute=0, second=5, millisecond=None)

Any ideas about what wrong I am doing?

Thanks!!

User avatar
deshipu
Posts: 1348
Joined: Thu May 28, 2015 5:54 pm

Re: Adafruit uRTC library for real time clock modules

Post by deshipu » Thu Mar 01, 2018 1:35 pm

You can't update a single field. You are setting a new date every time, with the fields you didn't specify set to defaults (usually 0 or 1).

User avatar
philwilkinson40
Posts: 59
Joined: Tue Nov 14, 2017 3:11 am
Location: Perth, Australia

Re: Adafruit uRTC library for real time clock modules

Post by philwilkinson40 » Fri Mar 09, 2018 1:40 pm

very old thread. Sorry

I am running MicroPython v1.9.3-8 on a WEMOS D1 Mini ESP8266.
While the ESP8266 is connected, I am able to set the ESP RTC by using the npttime library. This is ok until I turn off the power, or drop into deepsleep.

So I have a DS1307 shield which I have tried to use with the uRTC library and supporting information.

I am then able to manually set the DS1307 RTC using:

Code: Select all

import urtc
from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4))
rtc = urtc.DS1307(i2c)
datetime = urtc.datetime_tuple(year=2018, month=3, day=9)
rtc.datetime(datetime)
However, I then have a situation where the utime.localtime() and DS1307 urtc.datetime_tuple() return different datetime stamps.

Is there any elegant way to set the DS1307 urtc.datetime_tuple() with the ESP's time obtained using ntptime?

Or perhaps I am doing all this wrong?

Post Reply