[SOLVED] DS3231 uRTC set / read problems

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

[SOLVED] DS3231 uRTC set / read problems

Post by jpj » Sat Jan 21, 2017 10:39 pm

I now have this Adafruit DS3231 breakout board (with backup battery) connected to my Adafruit esp8266 Feather Huzzah:
https://www.adafruit.com/products/3013

Before connecting the DS3231 to the esp8266 I used an Arduino Uno to set and read back the time without issue. On the esp8266 I have version 1.2 of urtc.py downloaded from here:
https://github.com/adafruit/Adafruit-uRTC

The firmware on the esp8266 is CircuitPython 0.8.3:

Code: Select all

PYB: soft reboot
#6 ets_task(40100164, 3, 3fff8488, 4)
network config: ('192.168.1.113', '255.255.255.0', '192.168.1.1', '192.168.1.1')
could not open file 'main.py' for reading

Adafruit CircuitPython 0.8.3 on 2017-01-18; ESP module with ESP8266
After setting the time on the DS3231 with the Uno I connected it to the esp8266 and ran these commands one at a time through the REPL. I've added some white space here to enhance readability. 104 (0x68) is the DS3231 and 112 (0x70) is a display that works without issue.

Code: Select all

>>> import machine, urtc
>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> i2c.scan()
[104, 112]

>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=20, weekday=4, hour=0, minute=1, second=0, millisecond=0)

>>> mytuple = (2017, 1, 21, 6, 14, 17, 0, 0)
>>> mytuple
(2017, 1, 21, 6, 14, 17, 0, 0)
>>> rtc.datetime(mytuple)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=21, weekday=4, hour=0, minute=7, second=0, millisecond=0)
It looks like the values being retrieved with urtc.py are in error. I looked at the urtc.py file but don't see anything wrong. Any advice or guidance would be appreciated.

Thanks,
J
Last edited by jpj on Sun Jan 22, 2017 5:57 pm, edited 1 time in total.

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: DS3231 uRTC set / read problems

Post by jpj » Sun Jan 22, 2017 1:24 am

Update: I connected the DS3231 to my Pyboard v1.1 and using the exact same urtc.py it functions without issue:

Code: Select all

>>> from machine import I2C, Pin
>>> sdapin = pyb.Pin.board.Y10
>>> sclpin = pyb.Pin.board.Y9
>>> i2c = I2C(sclpin, sdapin)
>>> import urtc
>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=21, weekday=6, hour=14, minute=53, second=36, millisecond=0)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=21, weekday=6, hour=14, minute=53, second=39, millisecond=0)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=21, weekday=6, hour=14, minute=53, second=42, millisecond=0)

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: DS3231 uRTC set / read problems

Post by jpj » Sun Jan 22, 2017 3:54 pm

@deshipu - I tried the code with pullup you recommended in the Gitter thread. The DS3231 is the only device on the i2c bus connected to the Adafruit esp8266 Feather Huzzah.

Code: Select all

>>> i2c = I2C(scl=Pin(5, Pin.OUT, Pin.PULL_UP), sda=Pin(4, Pin.OUT, Pin.PULL_UP))
>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=22, weekday=7, hour=3, minute=6, second=0, millisecond=0)

>>> mytuple = (2017, 1, 22, 7, 7, 36, 0, 0)
>>> rtc.datetime(mytuple)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=22, weekday=3, hour=3, minute=6, second=0, millisecond=0)

>>> i2c.scan()
[104]
>>>

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: DS3231 uRTC set / read problems

Post by Mike Teachman » Sun Jan 22, 2017 4:58 pm

A small contribution to help find root cause .... I see normal rtc operation with a Feather esp8266 and the micropython 1.8.6 release. I'm using the same urtc library. Perhaps try with this micropython release?

here is the REPL trace:

Code: Select all

MicroPython v1.8.6-7-gefd0927 on 2016-11-10; ESP module with ESP8266
Type "help()" for more information.
>>> import machine
>>> import urtc
>>>
>>> i2c = machine.I2C(machine.Pin(5), machine.Pin(4))
>>> rtc = urtc.DS3231(i2c)
>>>
>>> rtc.datetime()
DateTimeTuple(year=2017, month=1, day=22, weekday=1, hour=8, minute=41, second=58, millisecond=0)
>>>
>>> rtc.datetime((2020, 6, 30, 5, 16, 55, 0, 0))
>>>
>>> rtc.datetime()
DateTimeTuple(year=2020, month=6, day=30, weekday=5, hour=16, minute=55, second=3, millisecond=0)
>>>
>>> rtc.datetime()
DateTimeTuple(year=2020, month=6, day=30, weekday=5, hour=16, minute=55, second=9, millisecond=0)
>>>
>>> rtc.datetime()
DateTimeTuple(year=2020, month=6, day=30, weekday=5, hour=16, minute=55, second=15, millisecond=0)
>>>
>>>

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: DS3231 uRTC set / read problems

Post by jpj » Sun Jan 22, 2017 5:19 pm

Thanks Mike. I'm going to reload 1.8.6 and try your code.
Last edited by jpj on Sun Jan 22, 2017 10:01 pm, edited 1 time in total.

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: DS3231 uRTC set / read problems

Post by jpj » Sun Jan 22, 2017 5:57 pm

SOLVED: @deshipu reminded me the Adalogger has an RTC on it too. It's a PCF8523 that is also at address 104 (0x68). I took the Adalogger out and the DS3231 is functioning properly now, with micropython 1.8.6. I'll re-install CircuitPython 0.8.3 and try that too.

Wow, that's embarrassing :oops:

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Supporting CircuitPython

Post by pythoncoder » Sun Jan 22, 2017 5:59 pm

Supporting CircuitPython here promises to be a headache - this is the MicroPython forum after all. I'm loath to invest time and energy learning incompatible forks. This isn't to criticise Adafruit, a company I use and admire; amongst other things they make kit that runs MicroPython :D

I'm just concerned about practicalities - perhaps support queries should be pointed in their direction? What does the team think?
Peter Hinch
Index to my micropython libraries.

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: [SOLVED] DS3231 uRTC set / read problems

Post by jpj » Sun Jan 22, 2017 6:03 pm

Functioning without issue under CircuitPython 0.8.3 too. Sorry for the obvious mistake. Thanks for the help.

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

Re: Supporting CircuitPython

Post by deshipu » Sun Jan 22, 2017 6:28 pm

pythoncoder wrote:Supporting CircuitPython here promises to be a headache - this is the MicroPython forum after all.
The same problem was present on MicroPython (I specificially asked to try that). Also, uRTC is a thrid party library, not included in either MicroPython or CircuitPython (or any other fork). If you discussion about libraries and drivers is not welcome here, I will happily move to a more welcoming community.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: [SOLVED] DS3231 uRTC set / read problems

Post by pythoncoder » Mon Jan 23, 2017 7:02 am

I'm sorry if I caused offence - it's the last thing I intended. I appreciate the specific problem was solved but was trying to raise a general point. I have posted the general point as a root message as I think it warrants discussion.
Peter Hinch
Index to my micropython libraries.

Post Reply