I have an OpenMV acting as a slave device. It isn’t actually doing anything but returning test data. It works great when I hook it up to an Arduino Uno which acts as the master. The problem is trying to get it to work with an old NXT lego brick (in RobotC).
The problem is it will return data on the first request from the NXT and then it appears the OpenMV holds the scl line low for 5 second. It then works again for one request and then holds the line low for 5 seconds again…and again…
First… here is the code on the OpenMV side (note I did the deinit() based on a post on this forum for another problem… didn’t help)
from pyb import I2C
def initI2C():
return I2C(2, I2C.SLAVE,addr=0x14//2)
bus = initI2C()
bus.deinit() # Fully reset I2C device...
bus = initI2C()
print("Starting...")
data = bytearray(1) # create a buffer
while(True):
try:
bus.recv(data,timeout=10000) # receive 3 bytes, writing them into data
print (data)
bus.send("19191919")
except OSError as error:
print(error)
pass
The print out in the serial console is:
bytearray(b'B')
[Errno 110] ETIMEDOUT
[Errno 5] EIO
bytearray(b'B')
[Errno 110] ETIMEDOUT
[Errno 5] EIO
[Errno 5] EIO
‘B’ (0x42)is what the NXT is sending to the OpenMV camera… so it does go through and receive it but then the clock is being held low by the OpenMV for 5 seconds.
Below is a screen shot from the logic analyzer. As you can see the clock is held low for 5 seconds almost exactly and it will run like this all day. (I’ve confirmed it is the OpenMV holding it low by yanking out the wire).
Just FYI… The clock and data line are being pulled high by 82K resistors per the NXT specs. It works well if I make the Arduino the slave (the arduino just works… I rarely have an i2c problem with it).