Skip to content

Working with the AT24C32n.py package #9378

Discussion options

You must be logged in to vote

I'm pretty sure the following will work:

adata = eeprom.read(5, 1) # eeprom.read() returns bytes
bdata = bytearray(1)
bdata[0] = adata[0]
bdata[0] += 1
eeprom.write(5, bdata)   # eeprom.write() wants an array

Your mistake here is to assume that eeprom.write() can handle plain integers (hence the question of @mcauser above).
This is wrong - the code in https://github.com/mcauser/micropython-tinyrtc-i2c/blob/master/at24c32n.py reads:

def write(self, addr, buf):
    """Write one or more bytes to the EEPROM starting from a specific address"""
    ....
    self.i2c.writeto_mem(self.i2c_addr, addr, buf[0:partial], addrsize=16)

This clearly indicates that the buf argument to write() needs to b…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@mcauser
Comment options

@Comalco
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Comalco
Comment options

@karfas
Comment options

@Comalco
Comment options

Answer selected by Comalco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants