logo

请问大神们arduino与openmv通信问题

2018-05-16 14:20
5
_13531193294

# Blob Detection and uart transport

import sensor, image, time

from pyb import UART

import json

# For color tracking to work really well you should ideally be in a very, very,

# very, controlled enviroment where the lighting is constant...

red_threshold_01 = (38, 73, 63, 4, 51, 2)

# You may need to tweak the above settings for tracking green things...

# Select an area in the Framebuffer to copy the color settings.

sensor.reset() # Initialize the camera sensor.

sensor.set_pixformat(sensor.RGB565) # use RGB565.

sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.

sensor.skip_frames(10) # Let new settings take affect.

sensor.set_auto_whitebal(False) # turn this off.

clock = time.clock() # Tracks FPS.

ROI=(70,0,20,120)

uart = UART(3, 115200)

while(True):

img = sensor.snapshot() # Take a picture and return the image.

statistics=img.get_statistics(roi=ROI)

blobs = img.find_blobs([red_threshold_01],roi=ROI)

if blobs:

print('sum :', len(blobs))

output_str = json.dumps(blobs)

for b in blobs:

# Draw a rect around the blob.

img.draw_rectangle(b.rect()) # rect

img.draw_cross(b.cx(), b.cy()) # cx, cy

print('you send:',output_str)

uart.write("Hello!\r")

else:

print('not found!')

这个是openmv的代码,主要就是当有红色运动到图片中心是,arduino就会发送代码给arduino,

char a;

SoftwareSerial softSerial(10, 11); // RX, TX

void setup() {

// put your setup code here, to run once:

softSerial.begin(115200);

Serial.begin(115200);

}

void loop() {

if(softSerial.available()){

a=softSerial.read();

Serial.println(a);

}

}

这是arduino代码,用软串口接受openmv数据,然后发送到电脑,但是只打这个代码

import time

from pyb import UART

uart = UART(3, 19200)

while(True):

uart.write("Hello World!\r")

time.sleep(1000)

arduino就可以传输数据,一加上上面那个识别红色代码后就没办法传输数据了

输大神解释

2018-05-17 19:47
I
网红小智智 星瞳科技

太复杂了,看不太懂,你有两个Arduino和一个OpenMV?