Created
June 20, 2019 19:12
-
-
Save khiet/fd705d69c28da581671643b1f5544b73 to your computer and use it in GitHub Desktop.
RPi Servo SG90 https://www.youtube.com/watch?v=ddlDgUymbxc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(7,GPIO.OUT) | |
# https://www.youtube.com/watch?v=ddlDgUymbxc | |
# SG90 angle and pulse width | |
# 0: 0.5 ms | |
# neutral: 1.5 ms | |
# 180: 2.5 ms | |
p = GPIO.PWM(7,50) # 50 Hz | |
p.start(7.5) # neutral ((1.5/20) * 100) % | |
try: | |
while True: | |
p.ChangeDutyCycle(2.5) # 0 | |
time.sleep(1) | |
p.ChangeDutyCycle(7.5) # 90 | |
time.sleep(1) | |
p.ChangeDutyCycle(12.5) # 180 | |
time.sleep(1) | |
p.ChangeDutyCycle(7.5) # 90 | |
time.sleep(1) | |
except KeyboardInterrupt: | |
p.stop() | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment