[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
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: [SOLVED] DS3231 uRTC set / read problems

Post by raspi3ua » Thu May 11, 2017 1:59 pm

Hello,
I have the same problem with Alarm.
DS3231 RTC connected to NodeMCU v3.

Code: Select all

>>> import urtc 
>>> from machine import I2C, Pin 
>>> i2c = I2C(scl=Pin(5), sda=Pin(4)) 
>>> rtc = urtc.DS3231(i2c)

>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=11, weekday=4, hour=16, minute=42, second=37, millisecond=None)

>>> rtc.alarm_time((None,None,11,None,16,55))
>>> rtc.alarm_time()
DateTimeTuple(year=None, month=None, day=11, weekday=None, hour=16, minute=55, second=None, millisecond=None)

>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=11, weekday=4, hour=16, minute=53, second=38, millisecond=None)
>>> rtc.alarm()
False
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=11, weekday=4, hour=16, minute=56, second=38, millisecond=None)
>>> rtc.alarm()
False

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Thu May 11, 2017 3:16 pm

Make sure you have the latest version of the library. There were some more bugs fixed.

User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: [SOLVED] DS3231 uRTC set / read problems

Post by raspi3ua » Fri May 12, 2017 6:21 am

deshipu wrote:Make sure you have the latest version of the library. There were some more bugs fixed.
Hello,
Download 1.2 version of library from https://github.com/adafruit/Adafruit-uRTC/releases.

Current situation:

Code: Select all

>>> i2c.scan()
[64, 104, 112]
>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=9, minute=10, second=8, millisecond=0)
>>> rtc.alarm_time((None,None,12,None,9,17))
>>> rtc.alarm_time()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "urtc.py", line 93, in alarm_time
AttributeError: 'I2C' object has no attribute 'redfrom_mem_into'
>>> rtc.alarm()
False
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=9, minute=27, second=14, millisecond=0)
>>> rtc.alarm()
False

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Fri May 12, 2017 8:14 am

Can you try with the master?

Also, please use the I2C object from machine, not from pyb.

User avatar
raspi3ua
Posts: 21
Joined: Sat Mar 18, 2017 4:49 pm
Location: Kiev, Ukraine
Contact:

Re: [SOLVED] DS3231 uRTC set / read problems

Post by raspi3ua » Fri May 12, 2017 8:39 am

deshipu wrote:Can you try with the master?

Also, please use the I2C object from machine, not from pyb.
Use Library master.

Code: Select all

MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
>>> import urtc
>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> i2c.scan()
[104]
>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=32, second=50, millisecond=None)
>>> rtc.alarm_time((None,None,12,None,11,34))
>>> rtc.alarm_time()
DateTimeTuple(year=None, month=None, day=12, weekday=None, hour=11, minute=34, second=None, millisecond=None)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=33, second=19, millisecond=None)
>>> rtc.alarm()
False
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=35, second=8, millisecond=None)
>>> rtc.alarm()
False
Use Library ver2.

Code: Select all

>>> import urtc 
>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> i2c.scan()
[104]
>>> rtc = urtc.DS3231(i2c)
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=28, second=58, millisecond=0)
>>> rtc.alarm_time((None,None,12,None,11,30))
>>> rtc.alarm_time()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "urtc.py", line 93, in alarm_time
AttributeError: 'I2C' object has no attribute 'redfrom_mem_into'
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=29, second=50, millisecond=0)
>>> rtc.alarm()
False
>>> rtc.datetime()
DateTimeTuple(year=2017, month=5, day=12, weekday=5, hour=11, minute=31, second=0, millisecond=0)
>>> rtc.alarm()
False

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Fri May 12, 2017 11:40 am

I will try to look into it in the evening. There must be one more bug left there. Sorry for that, I didn't test that particular chip very well.

vahithosan
Posts: 12
Joined: Wed Jul 26, 2017 5:15 pm

Re: [SOLVED] DS3231 uRTC set / read problems

Post by vahithosan » Wed Jul 26, 2017 5:34 pm

Hi. I have nodemcu v3 and DS3231 rtc. I want to use external rtc for high accuracy. And I want to awaken the ESP8266 from sleep with this rtc. I connected the RTC's SQW to reset terminal of the ESP8266. But nothing is happening.
I use urtc on 1.9.1 firmware

[code]
import network
import time
import utime
import machine
import urtc
import network, time
from ntptime import settime
from machine import I2C, Pin

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('SSID', 'passwd')
sta_if.ifconfig()

i2c = I2C(scl=Pin(5), sda=Pin(4))
rtc = urtc.DS3231(i2c)

settime() # ntp
tampon1=utime.time() # for convert to second
tampon2=tampon1+10800 # for gmt+3
datetime = urtc.seconds2tuple(tampon2)
rtc.datetime(datetime)
rtc.datetime()

rtc.alarm_time((None,None,datetime.day,None,datetime.hour,datetime.minute+1,0)) # Alarm after a minute
rtc.alarm_time()

machine.deepsleep()
[/code]

vahithosan
Posts: 12
Joined: Wed Jul 26, 2017 5:15 pm

Re: [SOLVED] DS3231 uRTC set / read problems

Post by vahithosan » Sat Aug 05, 2017 10:40 pm

I am confused when working with ds3231. I dont understand how the alarm works. I want an alarm every minute.
I can not see changes in 0E and 0F.

[code]
import network
import utime
import machine
import urtc
import ustruct
import network, time
from ntptime import settime
from machine import I2C, Pin

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('SSID', 'PASSWD')
sta_if.ifconfig()

i2c = I2C(scl=Pin(5), sda=Pin(4))
rtc = urtc.DS3231(i2c)

settime()
tampon1=utime.time()
tampon2=tampon1+10800
datetime = urtc.seconds2tuple(tampon2)
rtc.datetime(datetime)
rtc.datetime()

rtc.alarm_time((None,None,None,None,None,None,55))
[/code]


[code]
def liste():
s=rtc.datetime()
al=rtc.alarm_time()
print("Time : ",s.year,s.month,s.day,s.hour,s.minute,s.second,sep=" | ")
print("Alarm : ",s.year,s.month,s.day,s.hour,s.minute,al.second,sep=" | ")
print("Is alarm set ? ",rtc.alarm())
print("#"*36)
for i in range(0,19):
a = i2c.readfrom_mem(104,i,1)
b = ustruct.unpack('<h',a)
c = '{:08b}'.format(b[0])
print("{:0{}x}".format(i,2),c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],sep=" | ",end="")
print(" | ")
print("-"*36)
return
[/code]


>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 34
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------

>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 55
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------

>>> liste()
Time : | 2017 | 8 | 6 | 1 | 19 | 56
Alarm : | 2017 | 8 | 6 | 1 | 19 | 55
Is alarm set ? True
####################################
------------------------------------
0e | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
------------------------------------
0f | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
------------------------------------


Thanks.

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

Re: [SOLVED] DS3231 uRTC set / read problems

Post by deshipu » Sun Aug 06, 2017 9:13 am

I guess there is still a bug in the DS3231 alarm handling in that library, but I can't figure out what could possibly be wrong.

vahithosan
Posts: 12
Joined: Wed Jul 26, 2017 5:15 pm

Re: [SOLVED] DS3231 uRTC set / read problems

Post by vahithosan » Sun Aug 06, 2017 5:56 pm

deshipu wrote:I guess there is still a bug in the DS3231 alarm handling in that library, but I can't figure out what could possibly be wrong.
Thanks for your efforts.

I think there are 3 conditions for alarm activation.
INTCN==1 and
A1IE==1 and
A1F==1

A1F is 1 when the time and alarm match

For A1IE;
At first 0x0E register has 0x1c value. (No Time, No Alarm)
0x0E register must be 0x1d when alarm is set. But 0x0E content (0x1c) does not change when alarm is set

According to my opinion
If the value of the control register changes to 0x1d when the alarm is set, the alarm will run.

Post Reply