[PYTHON] Servo motor control with Raspberry Pi

Most of the following articles are as they are. Although it is mentioned in the article, I feel that incorrect information is scattered, so I will post it here in the sense that it worked.

http://bufferoverruns.blogspot.jp/2016/08/raspberry-pisg-90.html

Originally I used a library called ServoBlaster as below, but due to the influence of the Linux kernel change, it became completely unresponsive and I was looking for an alternative (neither jessie nor stretch worked).

http://qiita.com/lumbermill/items/218944f816bdb0483e3c

So the program is as follows.

import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

gp_out = 4
GPIO.setup(gp_out, GPIO.OUT)
servo = GPIO.PWM(gp_out, 50) 

servo.start(0.0)

for i in range(10):
    servo.ChangeDutyCycle(2.5)
    time.sleep(0.5)

    servo.ChangeDutyCycle(12.0)
    time.sleep(0.5)

GPIO.cleanup()

Reference: Servo control with Arduino

Recommended Posts

Servo motor control with Raspberry Pi
[Raspberry Pi] Stepping motor control with Raspberry Pi
Power SG-90 servo motor with raspberry pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Mutter plants with Raspberry Pi
Control brushless motors with GPIOs on Raspberry Pi Zero
Use vl53l0x with Raspberry Pi (python)
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Production of temperature control system with Raspberry Pi and ESP32 (1)
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
I learned how the infrared remote control works with Raspberry Pi
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
Hello World with Raspberry Pi + Minecraft Pi Edition
Build a Tensorflow environment with Raspberry Pi [2020]
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Working with sensors on Mathematica on Raspberry Pi
Use PIR motion sensor with raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Infer Custom Vision model with Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Use python on Raspberry Pi 3 to light the LED with switch control!
Raspberry Pi backup
Production of temperature control system with Raspberry Pi and ESP32 (2) Production of transmission device
Discord bot with python raspberry pi zero with [Notes]
Control Akizuki's I2C-connected OLED display from Raspberry Pi
Media programming with Raspberry Pi (preparation for audio)
I tried L-Chika with Raspberry Pi 4 (Python edition)
Enjoy electronic work with GPIO on Raspberry Pi
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Use Majoca Iris elongated LCD with Raspberry Pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Get CPU information of Raspberry Pi with Python
Play with your Ubuntu desktop on your Raspberry Pi 4
Get temperature and humidity with DHT11 and Raspberry Pi
Stock investment analysis app made with Raspberry Pi
Logging Inkbird IBS-TH1 mini values with Raspberry Pi
Connect to MySQL with Python on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
Record temperature and humidity with systemd on Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Using the digital illuminance sensor TSL2561 with Raspberry Pi
What is Raspberry Pi?