TinyRTC I2C Module DS1307 + AT24C32N

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

TinyRTC I2C Module DS1307 + AT24C32N

Post by mcauser » Wed Mar 28, 2018 12:22 pm

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

Blechi
Posts: 8
Joined: Mon Apr 23, 2018 5:55 pm

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by Blechi » Fri Apr 27, 2018 9:12 pm

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

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

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by pythoncoder » Sat Apr 28, 2018 10:12 am

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.
Peter Hinch
Index to my micropython libraries.

Blechi
Posts: 8
Joined: Mon Apr 23, 2018 5:55 pm

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by Blechi » Sun Apr 29, 2018 1:40 pm

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)

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by mcauser » Tue May 01, 2018 11:06 am

Does the loboris port support readfrom_mem() with addrsize=16?

Blechi
Posts: 8
Joined: Mon Apr 23, 2018 5:55 pm

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by Blechi » Tue May 01, 2018 8:00 pm

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.

User avatar
philwilkinson40
Posts: 63
Joined: Tue Nov 14, 2017 3:11 am
Location: Perth, Australia

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by philwilkinson40 » Thu Oct 11, 2018 11:02 am

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.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by mcauser » Thu Oct 11, 2018 2:51 pm

What’s the voltage on your coin cell?

User avatar
philwilkinson40
Posts: 63
Joined: Tue Nov 14, 2017 3:11 am
Location: Perth, Australia

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by philwilkinson40 » Fri Oct 12, 2018 2:42 am

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

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: TinyRTC I2C Module DS1307 + AT24C32N

Post by mcauser » Fri Oct 12, 2018 5:44 am

Is it the same RTC module as in the photo above?
I’ll give it a try with my D1 mini pro tonight.

Post Reply