I
I
Igor Markov2019-03-25 17:19:10
Raspberry Pi
Igor Markov, 2019-03-25 17:19:10

How to implement servo operation on Raspberry pi 3 B+?

Guys tell me in this matter.
I connected the MG90S servo to my Raspberry PI 3 B+ on GPIO12, that is, on a pin that supports hardware PWM.
Using the RPi.GPIO library with simple code:

spoiler
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12,GPIO.OUT)
p = GPIO.PWM(12,50)
p.start(7.5)
try:
while True:
p.ChangeDutyCycle(7.5)
time.sleep(0.5)
p.ChangeDutyCycle(12.5)
time.sleep(5)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()

Serva works with jerks.
The question is, how best to implement work with hardware PWM?
What library to use, any code examples?
The fact is that I am not strong in programming, but I could not find instructions on the network, can you tell me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Luisafie, 2019-03-27
@luisafie

No way, the implementation of PWM is poor.
considered for example here: https://codius.ru/articles/Raspberry_Pi_3_GPIO_part_2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question