openmv和arduino 串口通信 为什么发送的数据在arduino 串口监视器上只有横线啊
-
# 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... yellow_threshold = (65, 100, -100, 10, 24, 51) # 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() # 初始化摄像头 sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565. sensor.set_framesize(sensor.QVGA) sensor.skip_frames(10) # 跳过10帧,使新设置生效 sensor.set_auto_whitebal(False) # Create a clock object to track the FPS. uart = UART(3, 115200) ROI=(80,30,15,15) while(True): img = sensor.snapshot() # Take a picture and return the image. statistics=img.get_statistics(roi=ROI) #color_l=statistics.l_mode() color_a=statistics.a_mode() if statistics.a_mode()>0: color_a=0 else: color_a=1 #color_b=statistics.b_mode() print(color_a) data=[] data.append(color_a) data_out = json.dumps(set(data)) img.draw_rectangle(ROI) #uart.write(str(color_a)) print('you send:',data_out) uart.write(data_out +'\n')
#arduino部分
#include <SoftwareSerial.h> SoftwareSerial softSerial(10, 11); // RX, TX typedef struct { int data[50][2] = {{0,0}}; int len = 0; }List; List list; void setup() { // put your setup code here, to run once: softSerial.begin(115200); Serial.begin(115200); } void loop() { if(softSerial.available()) { getList(); for (int i=0; i<list.len; i++) { Serial.print(list.data[i][0]); Serial.print('\t'); Serial.println(list.data[i][1]); } Serial.println("============"); clearList(); } } String detectString() { while(softSerial.read() != '{'); return(softSerial.readStringUntil('}')); } void clearList() { memset(list.data, sizeof(list.data),0); list.len = 0; } void getList() { String s = detectString(); String numStr = ""; for(int i = 0; i<s.length(); i++) { if(s[i]=='('){ numStr = ""; } else if(s[i] == ','){ list.data[list.len][0] = numStr.toInt(); numStr = ""; } else if(s[i]==')'){ list.data[list.len][1] = numStr.toInt(); numStr = ""; list.len++; } else{ numStr += s[i]; } } }
-
先看OpenMV端是否发送了数据。
再看接线对不对
-
openmv 串行终端有数据,接的线是p4-10 P5-11 代码就是openmv官网的串行通信下,然后如果我接的arduino 0 1 (rxtx)的话就可以在看到数据了,不知道为啥子接10 11引脚就不行了,我估计是openmv的输入的数据格式有问题,please帮忙看一下
-
@kidswong999 5fpd 大约14小时之前
openmv 串行终端有数据,接的线是p4-10 P5-11 代码就是openmv官网的串行通信下,然后如果我接的arduino 0 1 (rxtx)的话就可以在看到数据了,不知道为啥子接10 11引脚就不行了,我估计是openmv的输入的数据格式有问题,please帮忙看一下
-
@5fpd 发一下Arduino上的数据