舵机的接线原理:
舵机的接口连接:
红线----->VIN
棕线----->GND
OpenMV3 M7 / OpenMV4 H7上增加:
注意:OpenMV4 H7 Plus P9不能使用PWM
代码如下:
from pyb import Servo import time #180°的舵机 s1 = Servo(1) # servo on position 1 (P7) s1.angle(0) # move to 0 degrees time.sleep(1000) while(1): s1.angle(90) # move to 90 degrees time.sleep(600) s1.angle(45) # move to 180 degrees time.sleep(0) s1.angle(-90) # move to 90 degrees time.sleep(600) s1.angle(-45) # move to -90 degrees time.sleep(600) s1.angle(0) # move to 0 degrees time.sleep(1000) #s1.angle(-60, 1500) # move to -60 degrees in 1500ms #s1.speed(50) # for continuous rotation servos
运行效果:
注意:1.openmv可以同时控制三路舵机
2.使用舵机拓展版的时候应选用5~7.2V的电源驱动
3.不使用电源驱动,红线接openmv的VIN,即使代码正确也不会转动(电压不够)
正是步行者,一步步登峰!
原文:https://www.cnblogs.com/ouyangmail/p/14421556.html