1

Is it possible to control 3 servos with a raspberry pi without hardware for it?

My firsts tests showed me it was possible, but sadly just ssh connecting to the raspberry pi makes the servo move really fast in all directions without asking, (same thing for anything which uses cpu)

I fell like I can't trust raspberry pi for controlling "rc" stuff

how come raspberry pi don't come with low level driver to control PWM with a decent stability? any reasons?

Any chances a low level driver (like servoblaster) helps me?

Should I go with hardware solution?

  • it should be possible to do what you want, but it depends on a number of factors such as how stable is stable? with many control mechanisms a small amount of jitter can be expected, it's working out how much is intolerable to you. and you also have made no mention of what language you are using. using python and RPi.GPIO is unlikely to be stable for 3 servos, but using pigpio which runs as a system daemon should be possible and reliable, and also gives you several interfaces so a choice of languages. – James Kent Mar 14 '17 at 12:56
4

You need to use hardware timed pulses for servos.

Software timed pulses will lead to jitter and a shorter servo lifetime.

Try pigpio, servoblaster, RPIO.GPIO, or similar which use hardware timed pulses.

1

Adafruit has a tutorial on this here. It's old, so it might not work on a Pi 2, but you never know.

Very short summary:

Connect the servo's signal pin to GPIO 18 (I think that's pin 12 on the header).

Then this code should work (you'll need to run sudo apt-get install -y python-pip and sudo pip install wiringpi with a network connection first).

# Servo Control
import time
import wiringpi

# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()

# set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)

delay_period = 0.01

while True:
        for pulse in range(50, 250, 1):
                wiringpi.pwmWrite(18, pulse)
                time.sleep(delay_period)
        for pulse in range(250, 50, -1):
                wiringpi.pwmWrite(18, pulse)
                time.sleep(delay_period)

They also recommend using dedicated hardware if you have problems with jitter.

  • any reasons using wiringpi instead of rPI.GPIO (default installed on raspberry pi) ? – mou Mar 13 '17 at 12:04
  • @mou, I didn't write the tutorial, so I don't know. – anonymoose Mar 13 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.