Created
March 12, 2018 17:48
-
-
Save iotguider/0ae0a0e746892df38c94cec3c2794b8d to your computer and use it in GitHub Desktop.
Code for interfacing servo motor with Raspberry Pi
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 # calling for header file for GPIO’s of PI | |
import time # calling for time to provide delays in program | |
GPIO.setmode (GPIO.BCM) # programming the GPIO by BCM pin numbers. | |
GPIO.setup(17,GPIO.OUT) # initialize GPIO17 as an output | |
servo = GPIO.PWM(17,50) # GPIO17 as PWM output, with 50Hz frequency | |
servo.start(0) # generate PWM signal with 7.5% duty cycle | |
servo.ChangeDutyCycle(7.5) # change duty cycle for getting the servo position to 90º | |
time.sleep(1) # sleep for 1 second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment