I’m using an Arduino Mega and an OpenMV H7 Plus and attempting to communicate between them.
Here’s the Camera Program
import sensor, image, time
from pyb import UART
uart = UART(3,19200)thresholds = [(64, 66, -51, 47, -31, 34), #Threshold for blue. These are the Min and Max values of L, A, and B colour space.
(38, 40, -5, 2, 40, 46)] #Threshold for yellow
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()
sensor.set_brightness(2)while(True):
img = sensor.snapshot() for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200, merge=True): img.draw_rectangle(blob.rect()) #draw a rectangle around the blue object img.draw_cross(blob.cx(), blob.cy()) # add a cross in the centre of the object uart.write("Blue x: ""%d"%blob.cx()) uart.write(" y: ""%d\n"%blob.cy()) print("Blue x: " "%d"%blob.cx(), "y: ""%d\n"%blob.cy()) #print the x and y values of the object for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200, merge=True): img.draw_rectangle(blob.rect()) #draw a rectangle around the blue object img.draw_cross(blob.cx(), blob.cy()) # add a cross in the centre of the object uart.write("Yellow x: ""%d"%blob.cx()) uart.write(" y: ""%d\n"%blob.cy()) print("Yellow x: " "%d"%blob.cx(), "y: ""%d\n"%blob.cy()) #print the x and y values of the object
And here’s the Arduino code
void setup(){
Serial3.begin(19200);
Serial.begin(19200);
}
void loop(){
if(Serial3.available()){
byte CamOut = Serial3.read();
Serial.print(CamOut);
}
}
For some reason, the TX0 and RX0 work as input and outputs from the camera, but the 3s don’t.
Any ideas why? When I use the 0s the serial monitor on both ends works. Why does this happen?
Also, I’m trying to use the camera without the camera connected to my PC and be powered by the Arduino. I’ve tried disconnecting the camera from my computer, connecting the vin to the 5v on the mega, but all it does is blink blue and doesn’t do anything. I used the same programs as above. What should I do?