hi,
Iam using openmv cam m4 and i have ordered openmv cam m7.my question is what will be the best choice to share data between openmv and raspberrypi whether UART is best or else shall i go with SPI.in my project based on the data given by openmvcam i have to move in x and y direction.
Iād use UART to avoid the SPI master/slave issue, and you donāt need high baudrates if youāre just sending the detection results.
as per your suggestion iam moving with UART but i donāt get my data from openmvcam to raspberry pi.i have connected my raspberrypi and openmv as in the image,both open mv and raspberrypi are connected to my pc which has ubuntu,my python code to transfer data from openmv is as follows:
import image, math, pyb, sensor, struct, time
uart_baudrate = 9600
uart = pyb.UART(3, uart_baudrate, timeout_char =1)
clock = time.clock()
threshold_index = 0 # 0 for red, 1 for green, 2 for blue
Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
The below thresholds track in general red/green/blue things. You may wish to tune themā¦
thresholds = [(23, 48, -128, 74, -37, 66), # generic_red_thresholds
(30, 100, -64, -8, -32, 32), # generic_green_thresholds
(0, 30, 0, 64, -128, 0)] # generic_blue_thresholds
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
\
Only blobs that with more pixels than āpixel_thresholdā and more area than āarea_thresholdā are
returned by āfind_blobsā below. Change āpixels_thresholdā and āarea_thresholdā if you change the
camera resolution. āmerge=Trueā merges all overlapping blobs in the image.
while(True):
clock.tick()
start = pyb.millis()
img = sensor.snapshot()
for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=100, area_threshold=100, merge=False):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print(blob.cx(), blob.cy(), blob.w(),blob.h())
uart.write("%d ; %d ; %d ; %d \r\n " % (blob.cx(), blob.cy(),blob.w(),blob.h()))
print(clock.fps())
#and my code to receive at the receiver end raspberrypi is :
import serial
import string
import time
class OpenMV(object):
def init(self):
self.ser = serial.Serial(ā/dev/ttyAMA0ā,baudrate=115200, timeout = 0.5)
self.ser.flushInput();
def blob_xysize(self):
blob_found = False
blob_x = 0
blob_y = 0
blob_radius = 0
w = 0
self.ser.flushInput();
line = self.ser.readline()
words = string.split(line , ā;ā)
if len(words) > 3:
blob_found = True
blob_x = int (words [0])
blob_y = int (words [1])
w = int (words [2])
blob_radius = w
else:
blob_found = False
blob_x = 0
blob_y = 0
blob_radius = 0
w = 0
#print āInvalid lineā
print(blob_found, blob_x, blob_y, blob_radius)
\
main - tests the Openmv class
def main(self):
while True:
self.blob_xysize()
exit(1)
self.ser.close()
open_mv = OpenMV()
if name == āmainā:
open_mv.main()
please give a suitable solution for this
Hi, can you try running this program?
# UART Control
#
# This example shows how to use the serial port on your OpenMV Cam. Attach pin
# P4 to the serial input of a serial LCD screen to see "Hello World!" printed
# on the serial LCD display.
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, 19200, timeout_char=1000)
while(True):
uart.write("Hello World!\r")
time.sleep(1000)
You should get āHello Worldā from a serial terminal. The program definitely works so if you are having issues then itās a wiring problem between the camera and the Pi. Note that you can control the OpenMV Cam through USB on the Pi.
So, Iām just going to add some example scripts for this to the OpenMV Repo. It seems thereās enough folks asking for this that it needs to get done.
k thank you
![]()
hi,
i have done all things which you have mentioned but i didn,t get any data from raspberrypi if possible can u pls provide a video based tutorial to serially connect raspberrypi with openmv cam it would be more helpful because lot of my friends also have the same isssue. i have raspberrypi model B and openmvcam m4 and 5 inch lcd screen.how can i send the position of various blob values from my open mv cam to my raspberrypi thanks in advance
![]()
Will do.
thank you.waiting for your video tutorial.
Hi, itās going to take a while to get this done. Iām in the middle of moving to a new apartment.
Iāll make this my next high priority however.
k thank you
.
Hi there,
I was attempting to set up the UART of my own Raspberry Pi and tested the OpenMV code you had and I can confirm that the UART on my Pi sees the incoming data stream from the Camera in the format you created with the āuart.writeā command.
Are you sure you have set up the Pi correctly? On Raspberry Pi 3s the UART is Serial0 in the /boot/ file and the channel for listening on is /dev/ttyS0
Using minicom on my Pi I was able to listen on /dev/ttyS0 for both the example UART code and the python script you designed. I have not tested your receiving code as my knowledge of Python is limited and I canāt figure out the indentations on your code as everything posted here is without indentation.
Hi, use the code tags (see the code button on the forum editor) to post idented code.
ā¦
I just finished moving to my new place and will be working at 100% again soon.
It seems that the baud rate dont match between the openmv code (9600) and the python script (115200)
i have changed baudrate in both cam and raspberrypi and it works quite good and now iam getting my data serially.thank you.But sometimes some data are missing for example,suppose if i got my blob.x(),blob.y(),blob.z() value as (172,165,31) in openmv cam but in raspberrypi end the first digit is missing and my data comes as (72,165,31).what may be the reason kwagye.
i set the baudrate both for openmv and raspberrypi as 9600.
Increase the timoutechar value in the constructor. If you read the docs for what that does it controls how long the python code blocks on sending each character.
Hi. Is there any update on the tutorial?
Dunno, I kinda need help documenting all the ways to use the camera. I only have bandwidth to add features. Generally, understanding how to write serial communications should be a skill you should have it for you want to do serial communications. We designed the cam to have processing power and the ability to manipulate I/O pins on purpose and itās not really our design goal to have it be a slave device of a Pi.
Anyway, that said, Iāve got an RS232 shield and BLE shield for easier serial port communication back to a host PC using the hardware UART on the camera so you can still debug with the system.

