connection between raspberrypi and openmvcam

Iam using openmv cam m4 and i have ordered openmv cam 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 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.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.

start = pyb.millis()
img = sensor.snapshot()
for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=100, area_threshold=100, merge=False):

print(,, blob.w(),blob.h())

uart.write("%d ; %d ; %d ; %d \r\n " % (,,blob.w(),blob.h()))

#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)

def blob_xysize(self):

blob_found = False
blob_x = 0
blob_y = 0
blob_radius = 0
w = 0

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

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:


open_mv = OpenMV()

if name == “main”:

please give a suitable solution for this

I forgot to add image in the above post the uart connection is as in the photo.

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)
    uart.write("Hello World!\r")

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 :smiley: :smiley: :slight_smile: :slight_smile:

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 can i send the position of various blob values from my open mv cam to my raspberrypi thanks in advance :slight_smile: :slight_smile:

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 :slight_smile: :slight_smile: .

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.