• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 为什么串口接收数据一段好的一段又隔开了正常是0.774536?



    • 0_1697880107752_1.png

      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))
      
      

      0_1697880119891_2.png



    • uart.init(115200, bits=8, parity=None, stop=1)

      改为

      uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000)