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.
warren
Posts: 67
Joined: Tue Jul 12, 2016 5:47 pm

I2C EEPROM on uPy/ESP8266?

Postby warren » Tue Jan 10, 2017 11:32 am

Hi,

I want to add an i2c EEPROM to an ESP sensors - is there any existing code / library available that I can use/modify?

Thanks

User avatar
Roberthh
Posts: 442
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C EEPROM on uPy/ESP8266?

Postby Roberthh » Tue Jan 10, 2017 12:15 pm

If you just want to read/write data, the existing I2C lib works well. At least, I used that for a quick hack, and just followed the examples in the doc, believe it or not, here:
http://docs.micropython.org/en/latest/e ... hlight=i2c
and here:
http://docs.micropython.org/en/latest/e ... ml#i2c-bus

ioukos
Posts: 6
Joined: Wed Oct 19, 2016 11:31 am

Re: I2C EEPROM on uPy/ESP8266?

Postby ioukos » Wed Jan 11, 2017 10:42 am

Hi warren,

I've found this library on Github but didn't try it :
[url]
https://github.com/dda/MicroPython/blob ... /EEPROM.py[/url]

Share the result if you give it a try !

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

Re: I2C EEPROM on uPy/ESP8266?

Postby warren » Thu Jan 12, 2017 1:10 pm

Roberthh wrote:If you just want to read/write data, the existing I2C lib works well. At least, I used that for a quick hack, and just followed the examples in the doc, believe it or not, here:
http://docs.micropython.org/en/latest/e ... hlight=i2c
and here:
http://docs.micropython.org/en/latest/e ... ml#i2c-bus


Hmmm OK - thank you that is helpful.

Just waiting for my EEPROM to arrive.....

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

Re: I2C EEPROM on uPy/ESP8266?

Postby mcauser » Fri Jan 13, 2017 6:40 am

i2c.readfrom_mem + i2c.writeto_mem is what you are after.
http://docs.micropython.org/en/latest/e ... e.I2C.html

Code: Select all

>>> from machine import I2C, Pin
>>> i2c = I2C(scl=Pin(5), sda=Pin(4), freq=50000)
>>> i2c.scan()

Read 11 bytes starting at memory address 0
>>> i2c.readfrom_mem(0x50, 0, 11)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

Write "hello " at the beginning
>>> i2c.writeto_mem(0x50, 0, bytearray([104, 101, 108, 108, 111, 32]))

What is 104? It's the ascii value for "h".
>>> ord('h')
104

Read 11 bytes
>>> i2c.readfrom_mem(0x50, 0, 11)
b'hello \x00\x00\x00\x00\x00'

# write "world" starting at memory address 6
>>> i2c.writeto_mem(0x50, 6, bytearray('world'))

# read 11 bytes
>>> i2c.readfrom_mem(0x50, 0, 11)
b'hello world'


Return to “ESP8266 boards”

Who is online

Users browsing this forum: No registered users and 7 guests