I’m using an openMV to communicate with an Arduino Mega 2560, but during UART communication data is easily lost and I need precision to read data in real time, can anyone help me?
I’m using a battery that powers the Arduino and OpenMV, the Arduino and OpenMV gnds are connected to the battery, does this affect anything? Would it be better to connect a direct gnd between the Arduino and the OpenMV
?
As long as they both reference the same ground, it should work.
If the rate at which the camera is sending uart data matches the rate at which it’s being printed on the screen by the Arduino, but the characters are wrong, then this implies there’s some signal corruption, which would be due to a lack of ground between the two boards.
I have another question. I wanted when openMV sent the data, the Arduino would interrupt and read this data, but when I did that it interrupted but was unable to read the data from openMV, so I tested the same code but between two arduinos and it worked, but between OpenMV and Arduino it didn’t work.
I’m not sure what the error would be then… the UART definitely works fine. I can only think it’s an electrical or wiring issue. Your code looks more or less fine. Please pass the timeout_char=100 as the example code specifies when creating the UART.
Also, I would not use a baud rate of 9600 ever anymore. Make 115200 you min. 9600 bps means each character takes over a millisecond to send.
Generally, if you want to do two processor comms you should invest in one of these: Saleae Logic Analyzers. It’s expensive but one of the most valuable tools on my bench. It saves you so much time that the investment will be paid off instantly with how much sanity is restored.
On the OpenMV Cam H7/H7 Plus this code sends a character at 115200 bps via UART3:
import time
from pyb import UART
# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 115200, timeout_char=200)
while True:
uart.write("Hello World!\r")
time.sleep_ms(10)
import time
from pyb import UART
# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(1, 115200, timeout_char=200)
while True:
uart.write("Hello World!\r")
time.sleep_ms(10)