Atom to Atom via I2C
-
Hi Folks,
I'm trying to get 2 M5Stack Atom's to talk together via I2C, or more specifcially, SoftI2C in Micropython.
I've flashed both devices with Micropython 1.18 and have code on device A that looks like:
import machine i2c = machine.SoftI2C(scl=machine.Pin(26), sda=machine.Pin(32), freq=400000, timeout=50000) data = i2c.readfrom_mem(2, 1, 10) print(data.decode('utf-8'), end="")
Then on device B, I have the code to send data:
import machine i2c = machine.SoftI2C(scl=machine.Pin(26), sda=machine.Pin(32), freq=400000, timeout=50000) i2c.writeto_mem(2, 1, bytearray("Hello World"))
Nothing seems to come through, I have tried
i2c.scan()
however it just returns and empty list on both.I realise these are not hardware I2C pins, but they are for the Grove cable I'm using to power the second Atom.
If anyone has any examples/reference/docs or general tips, that would be great.
-
Hello @Exie
you would need one M5Atom to assume the I2C slave role. Right now both of your M5Atoms are acting as I2C master, but on a given I2C bus there can only be one master.
That said, I have no idea whether ESP32 can assume the I2C slave role or not and if yes, whether that functionality is accessible from within micropython.
Thanks
Felix -
@felmue Yes, I think you are absolutely right.
I just struggled to find any useful references to do this.
Today I came across this post:
https://forum.micropython.org/viewtopic.php?t=5320So I will try this later today and see how I go.
-
@exie @felmue I have never worked with micropython, however ESP32 can act as a slave on the I2C bus without any issues, irrespective of the pins that are used (any pair of GPIO can, in fact, be used as front-end for the I2C interface). I've taken a peek to the linked thread and the idea of continuously polling the bus to reply to an address as a slave is quite cumbersome and to say the least, inefficient.