We tried changing the baud rate and also used 3.3V from the camera, but it still does not work.
I am attaching the code from the Arduino and the OpenMV cam just in case that might be the issue.
Sometimes when we connect the camera we get random letters or numbers, like D or 5 in the Arduino Serial monitor when we are expecting 1 or 0. In addition, while we get those random results the camera doesnt react.
ARDUINO IDE:
#include <openmvrpc.h>
openmv::rpc_scratch_buffer<256> scratch_buffer;
//openmv::rpc_hardware_serial1_uart_master interface(19200); // Removed; trying UART 3 to see if the pins are damaged
openmv::rpc_hardware_serial3_uart_master interface(19200);
int find_patient()
{ //Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
int8_t color_thresholds[6] = {0, 100, 12, 127, -6, 64}; // generic_red_thresholds
uint8_t status = 0; // initializes variable as BYTE; 0 (no detection) or 1 (detection)
struct { uint16_t cx, cy; } find_red_rectangle_result;
if (interface.call(F("find_red_rectangle"), color_thresholds, sizeof(color_thresholds), &status, sizeof(status))) {
if (status==0){
return 0;
}else if (status==1){
return 1;
}
}
}
void loop(){
int status = find_patient(); //FUNCTION CALL
Serial.println(status);
}
/////////////////////////////////
OPENMV IDE:
import sensor, struct
import time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_whitebal(False)
clock = time.clock()
import rpc
# uart = UART(baudrate=115200, uart_port=1)
interface = rpc.rpc_uart_slave(baudrate=19200,uart_port=1)
# Function creates a drawing around the identified object.
def draw_detections(img, dects):
for d in dects:
c = d.corners()
l = len(c)
for i in range(l):
img.draw_line(c[(i + 0) % l] + c[(i + 1) % l], color=(0, 255, 0))
img.draw_rectangle(d.rect(), color=(255, 0, 0))
# Function for finding rectangle
def find_rectangle():
while True:
clock.tick()
img = sensor.snapshot()
# threshold below should be set to a high enough value to filter out noise
# rectangles detected in the image which have low edge magnitudes. Rectangles
# have larger edge magnitudes the larger and more contrasty they are...
for r in img.find_rects(threshold=25000):
img.draw_rectangle(r.rect(), color=(255, 0, 0))
for p in r.corners():
img.draw_circle(p[0], p[1], 5, color=(0, 255, 0))
print(r)
print("FPS %f" % clock.fps())
# Function for identifying red rectangle
def find_red_rectangle(data):
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
thresholds = struct.unpack("<bbbbbb", data)
blobs = sensor.snapshot().find_blobs(
[thresholds], pixels_threshold=500, area_threshold=500, merge=True, margin=20
)
if not blobs:
#return bytes() # No detections.
return b'\x00' # Means "no detection"
for b in blobs:
sensor.get_fb().draw_rectangle(b.rect(), color=(255, 0, 0))
sensor.get_fb().draw_cross(b.cx(), b.cy(), color=(0, 255, 0))
#out_blob = max(blobs, key=lambda b: b.density())
#return struct.pack("<HH", out_blob.cx(), out_blob.cy())
return b'\x01' # Detection found
# Register callback with function ID 0
interface.register_callback(find_red_rectangle)
# Start the interface loop (blocking — handles commands from Arduino)
interface.loop()