为什么用串口助手接受 不到呢?
-
# Untitled - By: HP - 周五 6月 7 2019 import sensor,time,pyb,math,image import json from pyb import Pin,Timer,LED,UART uart_buf =bytearray([0x55,0x00,0x00,0x00,0x00,0xAA]) #设置发送串口3 uart = UART(3,9600) uart.init(9600,bits=8,parity=None,stop=1) x_error =0 y_error =0 x_Sign = 0 y_Sign = 0 error_flag=0 car_lost=1 lenth=3 def find_max(blobs): #寻找最大色块函数定义 max_pixels=0 #通过像素比较 for blob in blobs: #blob[0,1,2,3,4]=x,y,w,h,pixels (int) if blob[4]>max_pixels: max_blob=blob max_pixels=blob[4] return max_blob sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger... 图像像素大小QQVGA是160✖120 sensor.skip_frames(30) sensor.set_auto_gain(False) # must turn this off to prevent image washout... sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... sensor.set_auto_exposure(True) clock = time.clock() black = (25, 95, 77, 22, -16, 63) while(True): clock.tick() img=sensor.snapshot() blobs = img.find_blobs([black]) if blobs: max_blob=find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(),max_blob.cy()) x_error = int(max_blob.cx()-img.width()/2) y_error = int(max_blob.cy()-img.height()/2) if x_error==0: x_Sign = 0 if x_error >0: x_Sign = 1 if x_error <0: x_Sign = 2 if y_error == 0: y_Sign = 0 if y_error >0: y_Sign = 1 if y_error < 0: y_Sign = 2 error_flag=0 print_data=(error_flag,x_error,y_error) print('error_flag: %d x_error: %d y_error: %d' % print_data) #x_abs=abs(x_error) #y_abs=abs(y_error) uart_buf_1 = bytearray([0x55, lenth, error_flag, x_error, y_error, 0xAA]) uart.write(uart_buf_1) else: error_flag |= car_lost x_error = 0 y_error = 0 print_data=(error_flag,x_error,y_error) print('error_flag: %d x_error: %d y_error: %d' % print_data) uart_buf_2 = bytearray([0x55, lenth, error_flag, x_error, y_error, 0xAA]) uart.write(uart_buf_2)
-
https://singtown.com/learn/50235/
先按照视频操作。