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



    • import sensor, image, time
      import pyb, ustruct # ustruct 用于打包和解压原始数据类型 的 "类"
      import gc
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(time = 300)
      sensor.set_auto_gain(False) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock()
      
      K=560#the value should be measure
      
      bus = pyb.I2C(2, pyb.I2C.SLAVE, addr=0x12)
      bus.deinit() # 完全关闭设备
      bus = pyb.I2C(2, pyb.I2C.SLAVE, addr=0x12)
      print("Waiting for Arduino...")
      
      
      while(True):
          length=0
          circlex=0
          circley=0
          clock.tick()
          img = sensor.snapshot().lens_corr(1.8)
          for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,
                  r_min = 2, r_max = 100, r_step = 2):
              area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())
              circlex=c.x()
              circley=c.y()
              img.draw_rectangle(area, color = (255, 255, 255))#将非红色的圆用白色的矩形框出来
              Lm =  2*c.r()
              length = K/Lm
          #print("FPS %f" % clock.fps())
          print("length:",length)
          output_str=[length,circlex,circley]
          for i in range(3):
              data = output_str[i]
              #sensor.shutdown(True)
              #try:
                  #bus.send(4, timeout=10000) # Send the len first (16-bits).
              try:
                  bus.send(data, timeout=10000) # Send the data second.
                  print(data)
                  print("Sent Data!") # Only reached on no error.
              except OSError as err:
                  pass # Don't care about errors - so pass.
                      # Note that there are 3 possible errors. A timeout error, a general purpose error, or
                      # a busy error. The error codes are 116, 5, 16 respectively for "err.arg[0]".
              #except OSError as err:
                  #pass
          del img
          gc.collect()
      ![0_1684415443045_屏幕截图 2023-05-18 211022.png](https://fcdn.singtown.com/95586d9d-64a8-4183-9c0b-5b51f5c9c481.png)