Page 2 of 4

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Mon Jan 23, 2017 10:49 am
by deshipu
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.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Tue Feb 14, 2017 8:20 am
by ioukos
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)

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Tue Feb 14, 2017 10:32 am
by deshipu
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.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Tue Feb 14, 2017 10:59 am
by ioukos
Ok thanks for the answer.

You don't have to be sorry.

You're doing a great job for the community.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Tue Feb 14, 2017 11:01 am
by deshipu
I have pushed a fix to https://github.com/adafruit/Adafruit-uRTC -- please test.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Wed Feb 15, 2017 8:46 pm
by ioukos
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.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Thu Feb 16, 2017 9:04 am
by deshipu
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.)

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Thu Feb 16, 2017 8:20 pm
by ioukos
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 

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Thu Feb 16, 2017 9:51 pm
by deshipu
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.

Re: [SOLVED] DS3231 uRTC set / read problems

Posted: Fri Feb 17, 2017 6:40 pm
by ioukos
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.