没事儿了,代码是对的,同一套代码,昨天不行今天又行了,炒!
C
cktf
@cktf
0
声望
2
楼层
114
资料浏览
0
粉丝
0
关注
cktf 发布的帖子
-
关于uart1与uart3的同时调用
我是想用uart3传输板子,uart1传输PC串口看,同时传输同一组数据,但uart3正常传输,uart1完全没效果(先前uart3也能单独传输),然后代码就改了4个地方,仿照uart3改的4句:定义,初始化,2个传输数据语句 接口连线也没问题,连接串口前也没有打开IDE(我用自己做的串口助手,可以同时读双串口的,不是这的问题)
import sensor, image, time import pyb import utime from pyb import UART from pyb import LED from pyb import Pin, Timer import ustruct EXPOSURE_TIME_SCALE = 0.001 thresholds = (100, 255) high_threshold = (100, 255) red_threshold = (0,100, 0,127, 0,127) brightness = 0 uart = UART(3, 115200) uart1 =UART(1, 115200) uart.init(115200, bits=8, parity=None, stop=1) uart1.init(115200, bits=8, parity=None, stop=1) x_deviation = 0 y_deviation = 0 gainx = -1 gainy = -1 imageSize = 128 roi2 = (155, 110, 165, 120) xPositionNow = 0 yPositionNow = 0 xPositionLast = 0 yPositionLast = 0 blue_led = LED(3) green_led = LED(2) red_led = LED(1) def send_data(cx, cy): out_data = data = ustruct.pack("<bbhhb", 0x2C, 0x12, int(cx), int(cy), 0x5B) return out_data def find_max(blobs): max_size = 0 for blob in blobs: if blob.pixels() > max_size: max_blob = blob max_size = blob.pixels() return max_blob sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor. QVGA) sensor.skip_frames(time=900) sensor.set_auto_gain(False) sensor.set_auto_exposure(False, 100) sensor.set_auto_gain(False) sensor.set_windowing(roi2) x1 = 0 y1 = 0 while True: img = sensor.snapshot() blobs = img.find_blobs([thresholds],x_stride=1, y_stride=1, area_threshold=10, pixels_threshold=10,merge=True,margin=1) for b in blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(), max_blob.cy()) x1 = max_blob.cx() y1 = max_blob.cy() if len(blobs) >= 1: uart.write(send_data(x1, y1)) uart1.write(send_data(x1, y1)) print(x1,y1) else: uart.write(send_data(-1, -1)) uart1.write(send_data(-1, -1))