UART output failing

I am trying to use the RPC library to request image analysis on command from an Arduino to the Open MV CamH7 Plus.
Here is my OpenMV code:
import sensor, image, time, os, tf, uos, gc, rpc, pyb, struct
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
interface = rpc.rpc_uart_slave(baudrate=115200)
red_led = pyb.LED(1)
blue_led = pyb.LED(3)
g_led = pyb.LED(2)
g_led.on()
net = None
labels = None
t_red = (15, 50, 15, 45, -10, 21)
t_green = (10, 30, -10, 10, -10, 21)
t_yel = (40, 60, -10, 20, 0, 30)
rtc = pyb.RTC()
newFile = False

global o
o=1

if not “images” in os.listdir(): os.mkdir(“images”)
try:
net = tf.load(“trained.tflite”, load_to_fb=uos.stat(‘trained.tflite’)[6] > (gc.mem_free() - (64*1024)))
except Exception as e:
print(e)
raise Exception(‘Failed to load “trained.tflite”, did you copy the .tflite and labels.txt file onto the mass-storage device? (’ + str(e) + ‘)’)
try:
labels = [line.rstrip(‘\n’) for line in open(“labels.txt”)]
except Exception as e:
raise Exception(‘Failed to load “labels.txt”, did you copy the .tflite and labels.txt file onto the mass-storage device? (’ + str(e) + ‘)’)
g_led.off()

def objscan(data):
print(“SUUUUUUUUUUUUUUUIIIIIIIIIIIIIIIIII”)
#red_led.on()
#g_led.on()
strobject = 0
confobject = 0
img = sensor.snapshot()
strobject = “N”
blue_led.on()

#This code checks for the Letters and prints their percentages
for obj in net.classify(img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
    predictions_list = list(zip(labels, obj.output()))
    for i in range(len(predictions_list)):
        print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))
        with open('similar.txt', 'a') as similar:
            similar.write("%s = %f" % (predictions_list[i][0], predictions_list[i][1]) + "\n")
        if predictions_list[i][1] > .7:
            strobject = predictions_list[i][0]
            with open('similar.txt', 'a') as similar:
                similar.write("Object found:" + str(object) +"\n")
            if (predictions_list[i][0] != "N"):
                img.save(predictions_list[i][0] + str(o))
sensor.skip_frames(time=10)

for r in img.find_rects(threshold = 10000):
    img.draw_rectangle(r.rect(), color = (255, 0, 0))
    stats=img.get_statistics(roi=r.rect())
    for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
    print(stats)
    info = str(stats)
    with open('similar.txt', 'a') as similar:
        similar.write(info + "\n")
    if t_red[0]<stats.l_mean()<t_red[1]:
        if t_red[2]<stats.a_mean()<t_red[3]:
            if t_red[4]<stats.b_mean()<t_red[5]:
                strobject = "R"
                print("red")
                img.save("red" + str(o))
                with open('similar.txt', 'a') as similar:
                    similar.write("Object found:" + strobject +"\n")
    if t_green[0]<stats.l_mean()<t_green[1]:
        if t_green[2]<stats.a_mean()<t_green[3]:
            if t_green[4]<stats.b_mean()<t_green[5]:
                strobject = "G"
                print("green")
                img.save("green" + str(o))
                with open('similar.txt', 'a') as similar:
                    similar.write("Object found:" + strobject +"\n")
    if t_yel[0]<stats.l_mean()<t_yel[1]:
        if t_yel[2]<stats.a_mean()<t_yel[3]:
            if t_yel[4]<stats.b_mean()<t_yel[5]:
                strobject = "Y"
                print("yellow")
                img.save("yellow" + str(o))
                with open('similar.txt', 'a') as similar:
                    similar.write("Object found:" + strobject +"\n")
    print(strobject)

blue_led.off()
return struct.pack("<s",strobject)

while True:
o+=1
with open(‘similar.txt’, ‘a’) as similar:
similar.write(“}” + “\n” +“line:” + str(o) + “{” +“\n”)
interface.register_callback(objscan)
interface.loop()
Here is my Ardunio Code:
#include <openmvrpc.h>
openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
openmv::rpc_hardware_serial_uart_master interface(115200);
// * rx_pin - RX Pin (See the reference guide about what pins can be used)
// * tx_pin - TX Pin (see the reference guide about what pins can be used)
void setup() {

// Startup the RPC interface and a debug channel.
interface.begin();
Serial.begin(115200);
Serial.println("Starting...");

}

void exe_scan()
{
Serial.println(“exe_scan…”);
struct { char type[1]; } obj_result;
if (interface.call_no_args(F(“objscan”), &obj_result, sizeof(obj_result))) {
Serial.print(F(“Object = “));
Serial.println(obj_result.type[0]);
if (obj_result.type[0] == ‘N’){
Serial.println(“THINKS N”);
}
if (obj_result.type[0] == ‘H’){
Serial.println(“THINKS H”);
}
if (obj_result.type[0] == ‘S’){
Serial.println(“THINKS S”);
}
if (obj_result.type[0] == ‘U’){
Serial.println(“THINKS U”);
}
if (obj_result.type[0] == ‘R’){
Serial.println(“THINKS R “);
}
if (obj_result.type[0] == ‘G’){
Serial.println(“THINKS G”);
}
if (obj_result.type[0] == ‘Y’){
Serial.println(“THINKS Y”);
}
//Serial.print(F(”, Conf=”));
// Serial.println(obj_result.conf);
}
}
void take_pic()
{
Serial.println(“Take Pic…”);
struct { char type[1]; } pic_result;
if (interface.call_no_args(F(“takepic”), &pic_result, sizeof(pic_result))) {
Serial.print(F(“Pic Taken”));
// Serial.println(obj_result.type);
// Serial.print(F(”, Conf=”));
//Serial.println(obj_result.conf);
}
}
void loop() {
Serial.print(“Sus”);
exe_scan();
delay(1000);
}

Here is part of the output to com 15, I will try to attach a photo.

The pin setup is:
Arduino Tx3 pin 14 → Cam Rx pin 5
Arduino Rx3 pin 15 → Cam Rx pin 4
Arduino Ground → Cam ground

Please let me know is anything else is necessary.

I had to change the UART port from 0 to 3.

Hi, please don’t post a lot of code, then expect anyone to debug it for you. Also, please use the code formatting feature when posting.

If you want help debugging its best to post a question about something that you are confused by it’s behavior after reducing it down to the most simple issue.