Raspberry Pi Control Servo Moto with Source Code
Sample to show you how to simple control Servo moto:
The angle of rotation of the servo motor:
Usually, when receiving the pulse width is 1ms, the servo will turn to 0 degree angle and pulse width 2ms after receiving it will turn to the corner angle 180. The remaining 2 linearly with this milestone. In fact two landmark 1ms, 2ms 0 degrees and 180 degrees are usually composed of errors due to each engine so we need to experiment on the engine to determine the 2 landmark. In the case of iotbreaks.vn motor used, that is musty 0,4ms 2, 0 degrees and 2,4ms, 180 degrees
Video: Ongoing...[Will update on youtube channel: funPi]
Source Code:
The angle of rotation of the servo motor:
Usually, when receiving the pulse width is 1ms, the servo will turn to 0 degree angle and pulse width 2ms after receiving it will turn to the corner angle 180. The remaining 2 linearly with this milestone. In fact two landmark 1ms, 2ms 0 degrees and 180 degrees are usually composed of errors due to each engine so we need to experiment on the engine to determine the 2 landmark. In the case of iotbreaks.vn motor used, that is musty 0,4ms 2, 0 degrees and 2,4ms, 180 degrees
Wiring Connection:
As seen on the picture will have external power supply (4 * AAA battery, 1.2V) for servo motor without using Raspberry Pi from the line is to prevent too large and damaging Pi. However, you also have to note one thing is connected to GND of the source of the Raspberry Pi servo and GND (pin 6) as shown. Thus, the new servo can understand PWM from Pi
Video: Ongoing...[Will update on youtube channel: funPi]
Source Code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
servo=GPIO.PWM(7,50)
while True:
servo.start(2)
time.sleep(1) # Dừng 1 giây để motor quay đến vị trí
servo.ChangeDutyCycle(4)
time.sleep(1)
servo.ChangeDutyCycle(6)
time.sleep(1)
servo.ChangeDutyCycle(8)
time.sleep(1)
servo.ChangeDutyCycle(10)
time.sleep(1)
servo.ChangeDutyCycle(12)
time.sleep(1)
Raspberry Pi Control Servo Moto with Source Code
Reviewed by Unknown
on
December 19, 2016
Rating:

No comments: