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



    • THRESHOLD = (3, 34, -69, 115, -48, 127)
      
      import sensor, image, time, pyb
      from pyb import LED
      from pid import PID
      from pyb import UART
      import math
      from machine import I2C
      from vl53l1x import VL53L1X
      rho_pid = PID(p=0.4, i=0)
      theta_pid = PID(p=0.001, i=0)
      uart = UART(3, 115200)
      i2c = I2C(2)
      distance_sensor = VL53L1X(i2c)
      LED(1).on()
      LED(2).on()
      LED(3).on()
      
      sensor.reset()
      sensor.set_vflip(True)
      sensor.set_hmirror(True)
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQQVGA)
      sensor.skip_frames(time = 2000)
      data1 = 0x2c
      data2 = 0x2b
      clock = time.clock()
      
      roi1 = [(0, 0, 25, 20),
              (0, 45, 32, 50),
              (50, 45, 30, 50)
              ]
      
      while True:
          clock.tick()
          img = sensor.snapshot().binary([THRESHOLD])
      
          ROI_L = (22, 31, 4, 5)
          ROI_R = (43, 31, 6, 5)
          ROI1 = (34, 12, 12, 31)
          ROI2 = (27, 45, 15, 15)
          ROI3 = (32, 30, 6, 12)
      
          blobs1 = img.find_blobs([(100, 100)], roi=ROI_L, area_threshold=15, merge=True)
          blobs2 = img.find_blobs([(100, 100)], roi=ROI_R, area_threshold=15, merge=True)
          blobs3 = img.find_blobs([(100, 100)], roi=ROI1, area_threshold=15, merge=True)
          blobs4 = img.find_blobs([(100, 100)], roi=ROI2, area_threshold=15, merge=True)
          blobs5 = img.find_blobs([(100, 100)], roi=ROI3, area_threshold=15, merge=True)
      
          img = sensor.snapshot().binary([THRESHOLD])
      
          line = img.get_regression([(100, 100)], robust=True)
      
          img.draw_line((25, 0, 25, 60), color=(0, 255, 0))
          img.draw_line((47, 0, 47, 60), color=(0, 255, 0))
          img.draw_line((0, 45, 25, 45), color=(0, 255, 0))
          img.draw_line((47, 45, 80, 45), color=(0, 255, 0))
      
          if blobs1 and blobs2:
              #print(666)
              output1 = int(50) + 50
              output_str1 = bytearray([output1])
              uart.write('@')
              uart.write(bytearray(b'd'))
              uart.write('\r\n')
      
          if line:
      		 rho_err = abs(line.rho()) - img.width() / 2
      		 if line.theta() > 90:
      			 theta_err = line.theta() - 180
      		 else:
      			 theta_err = line.theta()
      			 img.draw_line(line.line(), color=127)
      		 if line.magnitude() > 8:
      			 rho_output = rho_pid.get_pid(rho_err, 1)
      			 theta_output = theta_pid.get_pid(theta_err, 1)
      			 output = rho_output + theta_output
      			 output = int(output) + 50
                               OUTPUT = str(round(output))
                               outut_str = bytearray([output])
                               uart.write(bytes([0x2C]))
                               uart.write(outut_str )
                               uart.write(bytes([0x5B]))  # 将16进制转换为字
                               print(outut_str )
      # 读取测距模块数据
          distance = distance_sensor.read()
      
          # 对测距数据进行处理
          distance = distance / 10  # 假设测距模块返回的是以毫米为单位的距离数据
          distance = int(distance)
          print("Distance:", distance, "mm")
          outut_str2 = bytearray([distance])
          uart.write(bytes([0x2C]))
          uart.write(outut_str2 )
          uart.write(bytes([0x5B]))
          time.sleep(0.1)
      


    • 原因:串口3和i2c引脚冲突。

      解决办法:把串口3改为串口1,使用P0P1引脚发送串口数据。