I2C EEPROM on uPy/ESP8266?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
mcauser
Posts: 410
Joined: Mon Jun 15, 2015 8:03 am

Re: I2C EEPROM on uPy/ESP8266?

Post by mcauser » Thu Feb 02, 2017 3:20 pm

Facepalm. :oops: The STM32 board that I was using has an AT24C08 1024k EEPROM on the back, exposed at the same address 0x50.
It actually has 4x devices, each with 256k. [80,81,82,83].
My tests that were passing were to the onboard EEPROM, not the LC Tech module!

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: I2C EEPROM on uPy/ESP8266?

Post by kfricke » Thu Feb 02, 2017 5:46 pm

:lol:

mikruth
Posts: 18
Joined: Wed Jan 11, 2017 6:00 pm

Re: I2C EEPROM on uPy/ESP8266?

Post by mikruth » Thu Feb 02, 2017 7:07 pm

Just a thought... The eeprom memory is 16 bits. Arduino sends 2 bytes consisting of MSB followed by LSB. Are we sending a 16 bit address with micropython?

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

Re: I2C EEPROM on uPy/ESP8266?

Post by deshipu » Thu Feb 02, 2017 9:06 pm

Only if you passed addrsize keyword argument to writeto_mem that specifies it. See http://micropython.org/resources/docs/e ... operations

Note that the documentation is wrong and the addrsize is already supported on ESP8266.

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

Re: I2C EEPROM on uPy/ESP8266?

Post by mcauser » Fri Feb 03, 2017 1:27 am

Ok, so this works on my WeMos D1 Mini on 3v3:

Code: Select all

# esp8266 -- eeprom
# 3v3 ------ vcc
# gnd ------ gnd
# D1 scl --- scl
# D2 sda --- sda

from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)

i2c.scan()
# [80]

# does not work, addrsize defaults to 8.
i2c.writeto_mem(0x50, 0, b'hello world')
i2c.readfrom_mem(0x50, 0, 11)
# b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'

# does work!
i2c.writeto_mem(0x50, 0, b'hello world', addrsize=16)
i2c.readfrom_mem(80, 0, 11, addrsize=16)
# b'hello world'
i2c.readfrom_mem(80, 2, 11, addrsize=16)
# b'llo world\xff\xff'
Adding addrsize=16 to reads/writes makes it work.

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

Re: I2C EEPROM on uPy/ESP8266?

Post by ioukos » Fri Feb 03, 2017 10:02 am

Hello,

I'll give this "address size" solution a shot this evening (in 9 hours here).

Anyway, thank you, you are very talented and very well educated !

i'll keep you informed.

warren
Posts: 73
Joined: Tue Jul 12, 2016 5:47 pm

Re: I2C EEPROM on uPy/ESP8266?

Post by warren » Fri Feb 03, 2017 4:04 pm

@mcauser:

That works *perfectly*!

Thank you so much...

mikruth
Posts: 18
Joined: Wed Jan 11, 2017 6:00 pm

Re: I2C EEPROM on uPy/ESP8266?

Post by mikruth » Fri Feb 03, 2017 4:46 pm

That's great.....Thanks!

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

Re: I2C EEPROM on uPy/ESP8266?

Post by ioukos » Fri Feb 03, 2017 6:02 pm

Work like a charm !

Post Reply