I2C slave mode doesn't work for UnitV Stick
-
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 writeoperation 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
-
i2c.deinit()? why you add deinit? that mean is close the I2C bus
-
@m5stack The deinit() is just called at the end for cleanup. I2C should work in the endless loop "while True: time.sleep(20)"
-
Why not just import the neopixel module if you are just driving some ws2812 rgb leds?
-
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 + WifiJan
-
I2C problem seems from the maixpy. maybe you could commit a issues to maixpy github
-
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 countThen, it worked well.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login