Hi everybody,
I am on a project where I would like follow a micro-line with a robot and I have a big problem on an I2C communication between an arduino mega(SLAVE) and the OpenMV cam M7 (MASTER).
Problem :
The communication run perfectly when the arduino and the cam are connected at the computer. When I unplug the cam, it’s running but if I restart them, the communication does not start.
OpenMV code :
enable_lens_corr = False # turn on for straighter lines...
from pyb import LED
import sensor, image, time, pyb
from pyb import DAC
from pyb import I2C
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE) # grayscale is faster
sensor.set_framesize(sensor.VGA) #
sensor.skip_frames(time = 2000)
i2c = pyb.I2C(2,I2C.MASTER)
#i2c.scan()
clock = time.clock()
dac = DAC("P6")
Yun=0
Ydeux=0
min_degree = 1
max_degree = 179
teensy = 8
angle = 0
code1 = 90
while(True):
clock.tick()
clock.fps()
img = sensor.snapshot()
#img.draw_line(0,240,640,240,color=(0,0,255),thickness=2)
#img.draw_keypoints(1,color = (255,0,0))
for l in img.find_lines(threshold = 4500, theta_margin = 25, rho_margin = 25):
if (min_degree <= l.theta()) and (l.theta() <= max_degree):
img.draw_line(l.line(), color = (255, 0, 0))
dac.write(l.theta())
#print("Theta %f" % l.theta())
Yun=l.y1()
Ydeux=l.y2()
print("Y1= %f" %Yun)
print("Y2= %f" %Ydeux)
Yc=Ydeux-((Yun-Ydeux)/2)
print("Yc = %.4f" % Yc)
code1 = int(l.theta())
#print("Theta = %i" % code1)
if(i2c.is_ready(teensy)):
i2c.send(90 ,addr = 8, timeout=9999999)
time.sleep(10)
Arduino code :
#include <Wire.h>
void setup() {
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
}
void loop() {
delay(1000);
}
void receiveEvent(int x){
while(Wire.available()){
int c = Wire.read();
Serial.print("receveid: ");
Serial.print(c);
Serial.println();
}
}
I’m sorry for my english, i’m french student and it’s difficult .