2021-08-16
Actuator, Electronics, Raspberrypi
servo simple RPi
ximport RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
servo_pin = 3
GPIO.setup(3, GPIO.OUT)
servo = GPIO.PWM(3, 50)
servo.start(0)
servo.ChangeDutyCycle(2.0)
time.sleep(2.0)
servo.ChangeDutyCycle(12.0)
time.sleep(2.0)
servo.ChangeDutyCycle(2.0)
time.sleep(1.0)
servo.ChangeDutyCycle(12.0)
time.sleep(2.0)
servo.stop()
GPIO.cleanup()
参考: http://rpi.science.uoit.ca/lab/servo/ PWMのコマンドの意味は
In the above case we have instantiated the PWM module for the pin number 12 with a frequency of 50Hz. That frequency was selected because the servo motor expect a pulse every 20ms (period), that means 50 pulses per second or Hertz.
だそうです.