Page 1 of 1

Adafruit uRTC library for real time clock modules

Posted: Mon Aug 15, 2016 7:27 pm
by deshipu
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.

Re: Adafruit uRTC library for real time clock modules

Posted: Thu Aug 18, 2016 7:22 am
by joehunt588
Thank you for the info, :) :) it really help

Re: Adafruit uRTC library for real time clock modules

Posted: Wed Feb 28, 2018 8:21 pm
by dubaleeiro
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!!

Re: Adafruit uRTC library for real time clock modules

Posted: Thu Mar 01, 2018 1:35 pm
by deshipu
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).

Re: Adafruit uRTC library for real time clock modules

Posted: Fri Mar 09, 2018 1:40 pm
by philwilkinson40
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?