必须是sg90s 金属齿轮的
塑料sg90不知道为什么不行
import RPi.GPIO as GPIO import time servoPIN = 17#GPIO口 GPIO.setmode(GPIO.BCM) GPIO.setup(servoPIN, GPIO.OUT) p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz p.start(2.5) # Initialization try: while True: p.ChangeDutyCycle(5) time.sleep(0.5) p.ChangeDutyCycle(7.5) time.sleep(0.5) p.ChangeDutyCycle(10) time.sleep(0.5) p.ChangeDutyCycle(12.5) time.sleep(0.5) p.ChangeDutyCycle(10) time.sleep(0.5) p.ChangeDutyCycle(7.5) time.sleep(0.5) p.ChangeDutyCycle(5) time.sleep(0.5) p.ChangeDutyCycle(2.5) time.sleep(0.5) except KeyboardInterrupt: p.stop() GPIO.cleanup()
标签:ChangeDutyCycle,树莓,python,0.5,sleep,time,GPIO,sg90 From: https://www.cnblogs.com/gooutlook/p/17001833.html