connection between raspberrypi and openmvcam

Discussion related to "under the hood" OpenMV topics.
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

connection between raspberrypi and openmvcam

Postby Maha » Sat Jun 16, 2018 12:56 am

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.
User avatar
iabdalkader
Posts: 482
Joined: Sun May 24, 2015 3:53 pm

Re: connection between raspberrypi and openmvcam

Postby iabdalkader » Mon Jun 18, 2018 12:30 am

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.
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Tue Jun 19, 2018 5:01 am

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
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Tue Jun 19, 2018 8:47 am

I forgot to add image in the above post the uart connection is as in the photo.
Attachments
IMG_20180619_122227467.jpg
IMG_20180619_122227467.jpg (4 MiB) Viewed 298 times
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Tue Jun 19, 2018 12:16 pm

Hi, can you try running this program?

Code: Select all

# 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.
Nyamekye,
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Tue Jun 19, 2018 12:19 pm

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.
Nyamekye,
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Wed Jun 20, 2018 1:18 am

k thank you :D :D :) :)
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Wed Jun 20, 2018 7:44 am

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 :) :)
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Wed Jun 20, 2018 2:01 pm

Will do.
Nyamekye,
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Thu Jun 21, 2018 2:44 am

thank you.waiting for your video tutorial.
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Thu Jun 21, 2018 12:18 pm

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.
Nyamekye,
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Fri Jun 22, 2018 2:35 am

k thank you :) :) .
mjd093
Posts: 5
Joined: Thu May 24, 2018 9:21 am

Re: connection between raspberrypi and openmvcam

Postby mjd093 » Wed Jun 27, 2018 11:10 am

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
2018-06-27-160940_1824x984_scrot.png (335.59 KiB) Viewed 138 times
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Wed Jun 27, 2018 1:08 pm

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.
Nyamekye,
patrickpoirier51
Posts: 32
Joined: Sat Apr 08, 2017 9:04 am

Re: connection between raspberrypi and openmvcam

Postby patrickpoirier51 » Wed Jun 27, 2018 9:52 pm

It seems that the baud rate dont match between the openmv code (9600) and the python script (115200)
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Sat Jun 30, 2018 12:25 am

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.
Maha
Posts: 9
Joined: Fri Jun 15, 2018 8:32 am

Re: connection between raspberrypi and openmvcam

Postby Maha » Sat Jun 30, 2018 12:28 am

i set the baudrate both for openmv and raspberrypi as 9600.
User avatar
kwagyeman
Posts: 2042
Joined: Sun May 24, 2015 2:10 pm

Re: connection between raspberrypi and openmvcam

Postby kwagyeman » Sat Jun 30, 2018 1:29 am

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.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests