Raspberry Pi + servo

Greetings! We have figured out the concept PWM and tried to connect our servo to Arduino, so in theory we will not dwell.

Connecting to Raspberry Pi

From the servo cable goes from three wires:

Red – Power – connected to a contact 5V (pin 2) or directly to the power supply;

brown or black – ground GND (pin 6 Raspberry Pi);

yellow or white – signal; Connect to pin 7.
gpio

Specifications of our servo
Model: TowerPro SG90
Operating Voltage: 4.8 DC
Speed: 60 degrees on 0.1 s
Torque: 1.6 kg cm
Weight: 9 g
The range of pulse width: 0.5 ms – 2.5 ms

towerpro-sg-90-9g-servoaccessories-1534857789

This servo can not rotate 360 degrees. It has a neutral position (Neutral) and limits of zero and 180 degrees. To install the servo in the neutral position, you must submit a high signal duration of 1.5 ms at 0 degrees – 0.5 ms to 180 degrees – 2.5 ms.

кут серво

Consider the following program:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7,GPIO.OUT)

p = GPIO.PWM(7,50)
p.start(7.5)

try:
        while True:
                p.ChangeDutyCycle(7.5)
                time.sleep(1)
                p.ChangeDutyCycle(12.5)
                time.sleep(1)
                p.ChangeDutyCycle(2.5)
                time.sleep(1)

except KeyboardInterrupt:
        p.stop()

        GPIO.cleanup()

In this program we set seventh pin for pulse-width modulation frequency of 50 Hertz: GPIO.PWM(7,50)

Now giving the servo pulses of different lengths, we can change its position
цикл серво
The work of this program:

It was very useful video

Оставить ответ

Обязательные поля помечены*

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.