Does anyone know how to communicate an OpenMV camera to LEGO EV3 MINDSTORMS using I2C communication?
The robot me and my team built has to follow a line. For that we used a light array sensor for MINDSTORMS. And on the line can be obstacles (like a brick or a bottle) of about 3 cm and I’m trying to detect it with the camera, and once it’s detected I want it to go around it and continue following the line. An at the end of that parkour, it will enter a white field with a black corner and multiple silver balls. I need the camera to detect the silver balls and push it towards the black corner.
I have all of the necessary codes for both the robot and camera. I’ve tried to follow multiple tutorials of I2C communication for the LEGO, but I’m not exactly sure how to connect it for both hard- and software. I do have a code for the OpenMV camera, but I’m not 100% sure if my code for the I2C communication of the camera is correct. I will put the code of the OpenMV camera below.
from pyb import I2C, Servo
I2C_SLAVE_ADDR = 0x12
i2c = I2C(2, I2C.SLAVE, addr=I2C_SLAVE_ADDR) # Use the correct I2C bus index
servo = Servo(1) # Assuming servo is connected to servo channel 1
instruction = [0, 0, 0]
while True:
try:
instruction = list(i2c.recv(3))
i2c.send(instruction[0])
if instruction[0] == 2:
servo.angle(instruction[1])
except OSError:
pass