• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • openmv串口和测距模块



    • import sensor, image, time
      from machine import I2C
      from vl53l1x import VL53L1X
      from pyb import LED
      from pyb import UART, Timer
      from pyb import Servo
      from pid import PID
      
      uart = UART(1,115200)
      i2c = I2C(2)
      distance = VL53L1X(i2c)
      
      test_state = 1
      L = 0
      chang = 0
      #cir.r = 300
      
      pan_pid=PID(p=0.05, i=0.01, d=0, imax=90) #在线调试PID
      tilt_pid=PID(p=0.05, i=0.012,d=0, imax=90)
      
      #pan_pid=PID(p=0.06, i=0.1, d=0.02, imax=100) #脱机运行PID
      #tilt_pid=PID(P=0.05, i=0.05, d=0, imax=90)
      
      '''
      rect_threshold=(20, 47, 29, 70, 12, 58) #(24, 45, 32, 70, 12, 58)
      circle_threshold=(61, 23, 31, 81, 5, 59)
      '''
      
      all_thresholds = [(30, 100, 15, 127, 15, 127), # _red_thresholds
                        (30, 100, -64, -8, -32, 32), # _green_thresholds
                        (0, 15, 0, 40, -80, -20)] # _blue_thresholds
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      
      
      
      def uart_singal():
          buff = 0
          buff = uart.any()
          if buff > 0:
              _data_receive(readchar())
          else:
              pass
      
      def _data_receive(data):
      
          if data == 65:
              test_state = 1
          elif data == 66:
              test_state = 2
          else:
              print('error!!!')
      
      
      def test1_2():
          for r in img.find_rects(threshold = 20000):
              area_rectangle = (r.rect()) #是为了在检测矩形的基础上检测有颜色的矩形
              for blob in img.find_blobs(all_thresholds, pixels_threshold=100, area_threshold=100, merge=True, margin=10,roi = area_rectangle):
                  img.draw_rectangle(area_rectangle, color = (0, 255, 0))
                  LED(1).toggle()
          for c in img.find_circles(threshold = 2200):
              area_circle = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())#是为了在检测有圆的基础上检测有颜色的圆
              draw_cir = (c.x(), c.y(), c.r())#画圆的轮廓
              for blob in img.find_blobs(all_thresholds, pixels_threshold=100, area_threshold=100, merge=True, margin=10, roi = area_circle):
                  img.draw_circle(draw_cir,  thickness=1, color = (0,255,0),  fill=False)
                  LED(3).toggle()
                  L = distance.read()-50
                  print(L)
                  chang = L
                  uart.write(chang)
      def test3_4():
          pass
      
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob[2]*blob[3]>max_size:
                  max_blob=blob
                  max_size=blob[2]*blob[3]
          return max_blob
      
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          if(test_state == 1):
              test1_2()
          elif(test_state == 2):
              test3_4()
          else:
              pass
          uart_singal()
      
      
      

      我想问问为啥我用串口1发送openmv测距模块得到的距离值他会报错,测距模块不是占用的串口3吗?0_1602417353915_QQ图片20201011195521.png



    • L是int,uart.write只能发送字节串(字符串)。

      uart.write(str(L))#转为字符串