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



    • 舵机主函数代码

      # Servo Shield Example.
      #
      # This example demonstrates the servo shield. Please follow these steps:
      #
      #   1. Connect a servo to any PWM output.
      #   2. Connect a 3.7v battery (or 5V source) to VIN and GND.
      #   3. Copy pca9685.py and servo.py to OpenMV and reset it.
      #   4. Connect and run this script in the IDE.
      
      import time , sensor
      from servo import Servos
      from machine import I2C, Pin
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      #sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_framesize(sensor.VGA)
      sensor.set_windowing((100 ,100))
      sensor.set_vflip(True)  #水平竖直翻转
      sensor.set_hmirror(True)
      sensor.skip_frames(time = 2000)
      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()
      
      i2c = I2C(sda=Pin('P5'), scl=Pin('P4'))
      servo = Servos(i2c, address=0x40, freq=50, min_us=500, max_us=2500, degrees=180)
      
      while True:
          clock.tick()
          img = sensor.snapshot()
          servo.position(7, 180)
          sensor.skip_frames(time = 1000)
          time.sleep(1000)
          servo.position(7, 90)
          sensor.skip_frames(time = 1000)
          time.sleep(1000)
          print(clock.fps())
          #servo.position(0, 120)
          #time.sleep(1000)
          #servo.position(0, 90)
          #time.sleep(1000)
      

      PCA9685代码

      import utime
      import ustruct
      class PCA9685:
      	def __init__(self, i2c, address=0x40):
      		self.i2c = i2c
      		self.address = address
      		self.reset()
      	def _write(self, address, value):
      		self.i2c.writeto_mem(self.address, address, bytearray([value]))
      	def _read(self, address):
      		return self.i2c.readfrom_mem(self.address, address, 1)[0]
      	def reset(self):
      		self._write(0x00, 0x00)
      	def freq(self, freq=None):
      		if freq is None:
      			return int(25000000.0 / 4096 / (self._read(0xfe) - 0.5))
      		prescale = int(25000000.0 / 4096.0 / freq + 0.5)
      		old_mode = self._read(0x00)
      		self._write(0x00, (old_mode & 0x7F) | 0x10)
      		self._write(0xfe, prescale)
      		self._write(0x00, old_mode)
      		utime.sleep_us(5)
      		self._write(0x00, old_mode | 0xa1)
              def pwm(self, index, on=None, off=None):
                  if on is None or off is None:
                      data = self.i2c.readfrom_mem(self.address, 0x06 + 4 * index, 4)
                      return ustruct.unpack('<HH', data)
                  data = ustruct.pack('<HH', on, off)
                  self.i2c.writeto_mem(self.address, 0x06 + 4 * index,  data)
              def duty(self, index, value=None, invert=False):
                  if value is None:
                      pwm = self.pwm(index)
                      if pwm == (0, 4096):
                          value = 0
                      elif pwm == (4096, 0):
      				value = 4095
      			value = pwm[1]
      			if invert:
      				value = 4095 - value
      			return value
      		if not 0 <= value <= 4095:
      			raise ValueError("Out of range")
      		if invert:
      			value = 4095 - value
      		if value == 0:
      			self.pwm(index, 0, 4096)
      		elif value == 4095:
      			self.pwm(index, 4096, 0)
      		else:
      			self.pwm(index, 0, value)
      

      0_1602568246946_e6474282-2968-43e2-b69e-75caa9bb9dfe-image.png



    • 看上去没插好。

      按照视频操作:https://singtown.com/learn/50057/