Communication with Arduino Mega - Serial or I2C?

I’m building a robot that will use an Arduino Mega as the controller and there will be two OpenMV H7 cameras that I need to communicate bidirectionally with. What is the best protocol to use, I2C or Serial? I have searched this forum and found lots of old posts and my own experiments using serial are not producing consistent performance. I’d like to hear what the latest wisdom is. Also, what is the latest firmware for the H7?

Serial is the best to use. I2C is definitely not what you want to use.

Typically folks fail with serial comms because they have difficulty programming things. If you are not new to making two processors talk to each other serial is very easy.

I have serial comm working, but it stops randomly, so I’m leaning towards I2C. I can post my code for Arduino and OpenMV with regards to the serial comm portion.

Can you post the code that you think is in error? I know the serial comm code is robust… I’ve built a robot that uses it to communicate between the OpenMV Cam and an Arduino and it works fine.

Please post the serial comm side snippet and etc.

As promised, here is my code for the OpenMV.

# P4 UART3 tx goes to Mega RX1 on pin 19
# P5 UART3 rx goes to Mega TX1 on pin 18

import time
from pyb import UART

uart = UART(3, 9600, timeout_char=1000)

print("Starting test")

for x in range(0, 6):
    print (x)
    uart.write("Cycle # %d \n" % x)   #send text to display on lcd connected to Mega
    time.sleep(1500)

print("Finished")

and for Arduino Mega

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

String Data = "";

void setup()
{
  Serial.begin(9600);                  // to display on computer screen
  Serial1.begin(9600);                 // Mega Serial1 uses pins 18 (TX1) and 19 (RX1)
  lcd.begin(20, 4);
  Data = "";
  lcd.clear();
  Serial.println("Program start");     // display in serial window on PC
  DisplayL1("Serial COM test");
}


void loop()
{
  if (Serial1.available()) {
    char character = Serial1.read();  
    if (character == '\n') { 
      Serial.println(Data);
      DisplayL1(Data); 
      delay(10);
      Data = ""; 
    }
    else
    {
      Data.concat(character);
    }
  }
  delay(10);
}


void DisplayL1(String Data) {
  lcd.setCursor(0, 0);                    // position cursor
  lcd.print("                    ");          // clear row by printing 20 spaces
  lcd.setCursor(0, 0);                    // re-position cursor
  lcd.print(Data);                          // display data
}

How to I code the OpenMV to read serial data from the Arduino? I want to be able to send commands or data from Arduino to OpenMV, such as for a quick check to see if it’s available.

In the other post you just posted to there’s an example of that.

Yes, I found that post after I made my request. So you see from my code that I am using the Arduino Mega to handle the I2C LCD display. I tried months ago to figure out how to get the OpenMV to display on it but couldn’t figure it out. If someone has OpenMV working with a common I2C LCD display, I’d like to get some code for it.