🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Atom to Atom via I2C

    SOFTWARE
    3
    4
    5.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ExieE
      Exie
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by

        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

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        ExieE 1 Reply Last reply Reply Quote 1
        • ExieE
          Exie @felmue
          last edited by

          @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=5320

          So I will try this later today and see how I go.

          B 1 Reply Last reply Reply Quote 0
          • B
            brus @Exie
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post