Created
October 21, 2019 19:32
-
-
Save javaplus/a2e6aab7669501da0fe298a4cc3629c1 to your computer and use it in GitHub Desktop.
RaspberryPi Simple Servo Example
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
# Servo Control | |
import time | |
import wiringpi | |
def moveToDegree(degrees): | |
wiringpi.pwmWrite(18, degrees) | |
# https://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/servo-motors | |
# use 'GPIO naming' | |
wiringpi.wiringPiSetupGpio() | |
# set #18 to be a PWM output | |
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT) | |
# set the PWM mode to milliseconds stype | |
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS) | |
# divide down clock | |
wiringpi.pwmSetClock(192) | |
wiringpi.pwmSetRange(2000) | |
delay_period = 0.01 | |
while True: | |
for pulse in range(50, 250, 1): | |
moveToDegree(pulse) | |
time.sleep(delay_period) | |
for pulse in range(250, 50, -1): | |
moveToDegree(pulse) | |
time.sleep(delay_period) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment