为什么串口接收数据一段好的一段又隔开了正常是0.774536?
-
thresholds = [(0, 100, 8, 123, -3, 127), #red (9, 96, -128, 111, -81, -17), #blue (0, 97, -127, -15, 127, -128)] #green import ustruct,sensor,image,time from machine import UART from pyb import Servo #time.sleep(17) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(10) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking #初始化串口 uart = UART(1, 115200) #串口1发送到单片机串口4 uart.init(115200, bits=8, parity=None, stop=1) #端口定义 s1 = Servo(1) # servo on position 1 (P7) s2 = Servo(2) # servo on position 1 (P8) #函数初始化 chucun = 0 zhuangtaiji = 0 zhuangtaiji2 = 0 zhuangtaiji3 = 0 a = 0 b = 0 s2.angle(-90) time.sleep(1) s1.angle(-90) # move to 45 degrees time.sleep(1) while(True): img = sensor.snapshot() flag = 0 for blob in img.find_blobs(thresholds,x_stride=80,y_stride=80,pixels_threshold=32500,area_threshold=30000, merge = False): if int(blob.code()) == 1: img.draw_string(10,10,"red",color=(255,0,0),scale = 2) flag = 1 if int(blob.code()) == 2: img.draw_string(10,10,"blue",color=(0,0,255),scale = 2) flag = 2 if int(blob.code()) == 4: img.draw_string(10,10,"green",color=(0,255,0),scale = 2) flag = 4 img.draw_rectangle(blob.rect()) if uart.any(): a = uart.readline().decode().strip() # re.match chucun: # case 0: if(flag == 0 and zhuangtaiji2 == 1): zhuangtaiji = 1 if(flag == 1 or flag == 2 or flag == 4): if(chucun == 0): chucun = flag zhuangtaiji2 = 1 if(chucun == flag and zhuangtaiji == 1 and zhuangtaiji3 == 0): uart.write((ustruct.pack("<BBBB",0X5C,0X5A,flag,0x5B))) uart.write((ustruct.pack("<BBBB",0X5C,0X5A,flag,0x5B))) uart.write((ustruct.pack("<BBBB",0X5C,0X5A,flag,0x5B))) uart.write((ustruct.pack("<BBBB",0X5C,0X5A,flag,0x5B))) time.sleep(0.5) s1.angle(90) time.sleep(1) s1.angle(-90) time.sleep(1) zhuangtaiji3 =0 print (float(a))
-
uart.init(115200, bits=8, parity=None, stop=1)
改为
uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000)