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

    I2C slave mode doesn't work for UnitV Stick

    Units
    4
    7
    7.6k
    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.
    • J
      jani
      last edited by jani

      Any ideas how to establish a I2C connection with the M5Stack UnitV as I2C.Slave?

      Setup:

      • M5Stack UnitV = I2C Slave
      • ESP8266 = I2C Master + Wifi

      Setting up the UnitV Stick as a I2C slave is failing. I'm connecting a ESP8266 with ports 34,35 of the UnitV and a 4,7kO Pull-Up resistor.

      The scan from the ESP8266 master is successful, but any read or write operation fails with a timeout message. The connection to other I2C devices is successful, when the UnitV is removed from the bus.
      UPDATE: Any write operation - before a read - is successful. After the first read, the bus is blocked.

      import time
      from machine import I2C
      
      I2C_SLAVE_ADDR = 0x3a
      count=0
      
      def i2c_on_receive (data):
          print ("on_receive:", data)
      
      def i2c_on_transmit ():
          count = count + 1
          print ("on_transmit, send:", count)
          return count
      
      def i2c_on_event (event):
          print ("on_event:", event)
      
      print ("starting i2c")
      i2c = I2C(I2C.I2C1, mode = I2C.MODE_SLAVE, scl=34, sda=35,
                  freq = 400000, addr = I2C_SLAVE_ADDR,
                  addr_size = 7,
                  on_receive = i2c_on_receive,
                  on_transmit = i2c_on_transmit,
                  on_event = i2c_on_event)
      while True:
          time.sleep(20)
      

      ESP8266 Micropython Code:

      from machine import Pin, I2C
      i2c = I2C(scl=Pin(12), sda=Pin(13), freq=400000)
      i2c.scan()  # returns [58]
      i2c.writeto(0x3a,'test') # success, write 4 bytes to slave with address 0x3a
      result = i2c.readfrom(0x3a, 4)  # fails with Timeout
      print(q)
      

      UPDATE 2020-06-26:

      • Code Cleanup (remove ws2812 reference), add esp8266 code
      1 Reply Last reply Reply Quote 0
      • m5stackM
        m5stack
        last edited by

        i2c.deinit()? why you add deinit? that mean is close the I2C bus

        J 1 Reply Last reply Reply Quote 0
        • J
          jani @m5stack
          last edited by

          @m5stack The deinit() is just called at the end for cleanup. I2C should work in the endless loop "while True: time.sleep(20)"

          1 Reply Last reply Reply Quote 0
          • lukasmaximusL
            lukasmaximus
            last edited by

            Why not just import the neopixel module if you are just driving some ws2812 rgb leds?

            J 1 Reply Last reply Reply Quote 0
            • J
              jani @lukasmaximus
              last edited by

              Hi @lukasmaximus,

              I want create snapshots with the UnitV via WIFI. The ws2812 import is only to show the status of the camera.

              UnitV = I2C Slave
              ESP8266 = I2C Master + Wifi

              Jan

              1 Reply Last reply Reply Quote 0
              • m5stackM
                m5stack
                last edited by m5stack

                I2C problem seems from the maixpy. maybe you could commit a issues to maixpy github

                1 Reply Last reply Reply Quote 0
                • T
                  TakekazuKATO
                  last edited by

                  Is this problem already solved?

                  It seems to be a mistake in the sample program.

                  Although, the variable 'count' in the function i2c_transmit() should be global, it is interpreted as local.

                  I modified the function i2c_on_transmit() as follows:

                  def i2c_on_transmit ():
                      global count
                      count = count + 1
                      print ("on_transmit, send:", count)
                      return count
                  

                  Then, it worked well.

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