Page 1 of 2

TinyRTC I2C Module DS1307 + AT24C32N

Posted: Wed Mar 28, 2018 12:22 pm
by mcauser
I created a driver for the TinyRTC I2C module. Features a DS1307 RTC IC + AT24C32N 32K EEPROM and headers for optional DS18B20.
https://github.com/mcauser/micropython-tinyrtc-i2c

It was only after I finished that I realised my STM32F407VET6 Mini actually has built-in hardware RTC and all I needed to do was attach a coin cell between GND + VBAT. :shock: Ah well, at least I learned all about RTCs and EEPROMs. You might find this driver useful for boards without a built-in RTC.

Image

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Fri Apr 27, 2018 9:12 pm
by Blechi
Hi,
thank you for the drivers.
DS1307 works like a charm.
The AT24C32N however doesn't do what it's supposed to do:
On my TTGO ESP32 boards (latest loboris port)
when i enter this:

Code: Select all

import machine
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
print('i2c scan:',i2c.scan())
import at24c32n
eeprom = at24c32n.AT24C32N(i2c)
# read 32 bytes starting from memory address 0
eeprom.read(0, 32)
i get this:

Code: Select all

i2c scan: [80, 104, 118]
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "at24c32n.py", line 42, in read
TypeError: extra keyword arguments given
I'm fairly new to Python, so i don't know what to look for.
Maybe someone wiser than me can chime in and show what i'm doing wrong here.
Thank you very much in advance.
Blechi

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Sat Apr 28, 2018 10:12 am
by pythoncoder
Looking at the GitHub code for the AT24C32N driver the line number in your traceback looks wrong. I strongly suspect you have not got the latest version of the driver. I suggest you update and try again.

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Sun Apr 29, 2018 1:40 pm
by Blechi
Thank you for the reply.
Notepad++ had eaten the 4 empty lines in the license terms.
After having fixed that by downloading the latest version from
https://github.com/mcauser/micropython-tinyrtc-i2c
the result is:

Code: Select all

i2c scan: [80, 104, 118]
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "at24c32n.py", line 46, in read
TypeError: extra keyword arguments given
when running this:

Code: Select all

import machine
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
print('i2c scan:',i2c.scan())
import at24c32n
eeprom = at24c32n.AT24C32N(i2c)
# read 32 bytes starting from memory address 0
eeprom.read(0, 32)

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Tue May 01, 2018 11:06 am
by mcauser
Does the loboris port support readfrom_mem() with addrsize=16?

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Tue May 01, 2018 8:00 pm
by Blechi
That was the right hint.
In the Loboris port the read and write functions require adrlen = 2 instead of addrsize = 16 .
After changing that everything works fine.
Thank you all for your help.

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Thu Oct 11, 2018 11:02 am
by philwilkinson40
sorry to add to an old thread, but it seems relevant.
I am using a clone TinyDS1307 with a WEMOS D1 mini Pro ESP8266.

All works well but the RTC time does not survive a power reset.
setting ds.halt(False) has the same outcome. I have tried the same code with the uRTC driver too with the same result. Am I doing this all wrong?

Code: Select all

import ds1307
import ntptime

from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4))
ds = ds1307.DS1307(i2c)
print('initial datetime on ds1307 is...', ds.datetime())

#set the time by ntptime
print('ntp time is set at')
ntptime.settime()

f=utime.localtime()
g=f[0],f[1],f[2],f[6],(f[3]+8),f[4],f[5]

#ds.halt(False)
ds.datetime(g)
print('new datetime on ds1307 is...', ds.datetime())

utime.sleep(5)
print('5secs later is...', ds.datetime())
initially

Code: Select all

initial datetime on ds1307 is... (2000, 1, 1, 0, 0, 0, 0, 0)
ntp time is set at
(2018, 10, 11, 10, 58, 26, 3, 284)
new datetime on ds1307 is... (2018, 10, 11, 3, 18, 58, 26, 0)
5secs later is... (2018, 10, 11, 3, 18, 58, 31, 0)
then after a power reset exactly the same occurs.

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Thu Oct 11, 2018 2:51 pm
by mcauser
What’s the voltage on your coin cell?

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Fri Oct 12, 2018 2:42 am
by philwilkinson40
it was 2.85V, so I put in a brand new CR1220 which read over 3V. Unfortunately this has the same result.
I repeated this on a second tiny RTC clone with the same outcome.
Phil

Re: TinyRTC I2C Module DS1307 + AT24C32N

Posted: Fri Oct 12, 2018 5:44 am
by mcauser
Is it the same RTC module as in the photo above?
I’ll give it a try with my D1 mini pro tonight.