# connection between raspberrypi and openmvcam

**URL:** <https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784>\
**Category:** OpenMV Boards\
**Created:** [June 16, 2018, 4:56am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784 "2018-06-16T04:56:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 16, 2018, 4:56am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/1 "2018-06-16T04:56:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [June 18, 2018, 4:30am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/2 "2018-06-18T04:30:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 19, 2018, 9:01am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/3 "2018-06-19T09:01:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 19, 2018, 12:47pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/4 "2018-06-19T12:47:50Z")

</div>

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

 ![IMG_20180619_122227467.jpg](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/d35f29d91c522e87b00ff1afb16f7f456dad76d2.jpeg)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 19, 2018, 4:16pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/5 "2018-06-19T16:16:57Z")

</div>

Hi, can you try running this program?

```python
# 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.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 19, 2018, 4:19pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/6 "2018-06-19T16:19:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 20, 2018, 5:18am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/7 "2018-06-20T05:18:58Z")

</div>

k thank you 😃😃🙂🙂

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 20, 2018, 11:44am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/8 "2018-06-20T11:44:03Z")

</div>

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 🙂🙂

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 20, 2018, 6:01pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/9 "2018-06-20T18:01:36Z")

</div>

Will do.

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 21, 2018, 6:44am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/10 "2018-06-21T06:44:01Z")

</div>

thank you.waiting for your video tutorial.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 21, 2018, 4:18pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/11 "2018-06-21T16:18:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 22, 2018, 6:35am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/12 "2018-06-22T06:35:29Z")

</div>

k thank you 🙂🙂 .

---

<div class="post-metadata">

**Author:** ![mjd093](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mjd093](https://forums.openmv.io/u/mjd093)\
**Post date:** [June 27, 2018, 3:10pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/13 "2018-06-27T15:10:59Z")

</div>

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.

 ![2018-06-27-160940_1824x984_scrot.png](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/694b44849d6ecb1c4009e4a82b25a88b1a8f35e1.png)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 27, 2018, 5:08pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/14 "2018-06-27T17:08:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![patrickpoirier51](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@patrickpoirier51](https://forums.openmv.io/u/patrickpoirier51)\
**Post date:** [June 28, 2018, 1:52am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/15 "2018-06-28T01:52:24Z")

</div>

It seems that the baud rate dont match between the openmv code (9600) and the python script (115200)

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 30, 2018, 4:25am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/16 "2018-06-30T04:25:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maha](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maha](https://forums.openmv.io/u/Maha)\
**Post date:** [June 30, 2018, 4:28am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/17 "2018-06-30T04:28:05Z")

</div>

i set the baudrate both for openmv and raspberrypi as 9600.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [June 30, 2018, 5:29am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/18 "2018-06-30T05:29:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Naman](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@Naman](https://forums.openmv.io/u/Naman)\
**Post date:** [March 9, 2019, 8:33pm UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/19 "2019-03-09T20:33:52Z")

</div>

> [@](#):
>
> I just finished moving to my new place and will be working at 100% again soon.

Hi. Is there any update on the tutorial?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [March 10, 2019, 12:55am UTC](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784/20 "2019-03-10T00:55:15Z")

</div>

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.

[Next page](https://forums.openmv.io/t/connection-between-raspberrypi-and-openmvcam/784.md?page=2)
