[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.
User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Mon Jan 23, 2017 10:49 am

No offense, I just don't think we should start chasing away people who come here for help as soon as they mention the name "CircuitPython" or "WiPy". Sure, if the problem seems to be specific to the platform, stemming from a design decision or a bug specifically in that fork, we might be unable to help and will do better by pointing the user to a better source of help. But in cases like this, where the bug is most likely in a library I wrote, and would affect MicroPython and CircuitPython users equally, I think it's good to have it here -- in case others stumble upon a similar problem.

And if you are serious about waging a petty war with all the forks, may I just point out that a much better strategy to alienating the users of those forks would be an attempt to convert them to our side -- seeing much better support and friendlier community in MicroPython, they might decide to switch. Just saying.

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: [SOLVED] DS3231 uRTC set / read problems

Post by ioukos » Tue Feb 14, 2017 8:20 am

Hi every one,

I'm not sure I have to post here or create a new thread :

I'm able to use deshipu's urtc.py (the one mentioned at the beginning of this thread) with DS3231 to set/read time.
But i'm not able to use it to set/read alarm, is it a known issue ?

I set the alarm with :

Code: Select all

rtc.alarm_time((2017,2,14,1,9,15))
#Set alarm to 9:15, 14/2/2017
When I check the alarm previously set with :

Code: Select all

rtc.alarm_time()
#Read previously set alarm
every parameters of the returned Tuple is set to 0 (year, month, week, weekday, hour, minute...)

Obviously, when I read the alarm flag with :

Code: Select all

rtc.alarm()
#Check alarm
All I get is "False", even after 9:15.

Do you think it's a problem with firmware 1.8.7 and i2c ? (none of the command above raises an error)

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Tue Feb 14, 2017 10:32 am

Looking at the code for that alarm_time() function, I wonder how it ever worked. It certainly doesn't work on the recent releases of MicroPython. I will need to rework that part. I'm sorry about that.

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: [SOLVED] DS3231 uRTC set / read problems

Post by ioukos » Tue Feb 14, 2017 10:59 am

Ok thanks for the answer.

You don't have to be sorry.

You're doing a great job for the community.

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Tue Feb 14, 2017 11:01 am

I have pushed a fix to https://github.com/adafruit/Adafruit-uRTC -- please test.

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: [SOLVED] DS3231 uRTC set / read problems

Post by ioukos » Wed Feb 15, 2017 8:46 pm

Well well, I feel stupid but i don't understand how to use it.

I set the alarm with

Code: Select all

>>> rtc.alarm_time((2017,2,15,None,21,50,0))
But I can't check if it's well set, as rtc.alarm_time() return nothing , and now,

Code: Select all

rtc.alarm()
Is always set to... True. I try to set it back to False with :

Code: Select all

rtc.alarm(False)
But it fails.

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Thu Feb 16, 2017 9:04 am

Can you be a little more precise? What does it mean "returns nothing" and "fails"? What does it return exactly, and how it fails? Is there an exception thrown?

This is how this works for me:

Code: Select all

>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> import urtc
>>> rtc = urtc.DS3231(i2c)
>>> rtc.alarm_time((2017,2,15,None,21,50,0))
>>> rtc.alarm_time()
DateTimeTuple(year=None, month=None, day=15, weekday=None, hour=21, minute=50, second=0, millisecond=None)
>>> rtc.alarm()
True
>>> rtc.alarm(0)
>>> rtc.alarm()
False
(I had the alarm set from previous experiments.)

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: [SOLVED] DS3231 uRTC set / read problems

Post by ioukos » Thu Feb 16, 2017 8:20 pm

Hi,

Here is my output :

Code: Select all

>>> from machine import I2C, Pin                                                
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))                                           
>>> import urtc                                                                 
>>> rtc = urtc.DS3231(i2c)                                                      
>>> rtc.alarm_time((2017,2,15,None,21,50,0))                                    
>>> rtc.alarm_time()                                                            
Traceback (most recent call last):                                              
  File "<stdin>", line 1, in <module>                                           
  File "urtc.py", line 138, in alarm_time                                       
IndexError: bytes index out of range 

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Thu Feb 16, 2017 9:51 pm

Thank you! That was my mistake, I didn't correct for a shorter buffer in all the places that I should. I pushed the fix.

User avatar
ioukos
Posts: 34
Joined: Wed Oct 19, 2016 11:31 am
Location: Alsace, Europe

Re: [SOLVED] DS3231 uRTC set / read problems

Post by ioukos » Fri Feb 17, 2017 6:40 pm

Thank You Deshipu, we are progressing but it's still not effective, let me show you :

Code: Select all

>>> rtc.alarm_time((2017,2,17,None,19,35,0))
>>> rtc.alarm_time()
DateTimeTuple(year=None, month=None, day=17, weekday=None, hour=19, minute=35, second=0, millisecond=None)
>>> while True: #Start a test to visualise the alarm
...     rtc.datetime()
...     rtc.alarm()
...     time.sleep(0.5)
...     
Here is the output :

Code: Select all

DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=34, second=59, millisecond=None)
False
DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=34, second=59, millisecond=None)
False
DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=35, second=0, millisecond=None)
False
DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=35, second=0, millisecond=None)
False
DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=35, second=1, millisecond=None)
False
DateTimeTuple(year=2017, month=2, day=17, weekday=4, hour=19, minute=35, second=1, millisecond=None)
False
As you can see, the alarm is not triggered at 19h35.

Post Reply