2

So I just decided to start a small side project using the RPi to control 1 or 2 servos.

At first, I thought this would just mean plugging the GPIO pins of the servo to the GPIO pins on the RPi, and send some PWM using a python library.

Then I read about breadboards, and how you should use them to prevent overpower.

Then I read the "Raspberry Pi Cookbook" (https://youtu.be/LwEBB6v559I?list=PL055Epbe6d5aNCgzEvabfFefkjSqtsEdx&t=285) and the guy basically demonstrated that programming a servo through PWM just end up with insane jitter.

Then I read about expansion boards (like PiFace) and how you should use them to program servos using I2C.

Then I read about drivers, relays, and whatever...

I'm now completely lost as to what I should use to start. Should I use a breadboard/PWM, or will that end up with insane jitter just like in the video? Or should I use I2C with an expansion card? which expansion card should I use? Or maybe I should use one of these "servo drivers" cards?

6

You can drive as many servos from the Pi as you can find spare gpios.

You have to use hardware timed PWM rather than software timed PWM.

People who report jitter have been using software timed PWM.

My pigpio library generates independent hardware timed PWM on all the user gpios and is suitable for servos. I think the defaults used mean it has fractionally less resolution (5 µs steps) than the add on boards you can buy, but hobby servos are not that accurate anyhow.

pigpio will also let you use the two hardware PWM channels if you do have expensive well engineered servos. That will give you a million resolution steps to play with.

The other modules to consider for hardware timed PWM are servoblaster and its forks, and RPIO.GPIO (note, not RPi.GPIO). RPIO.GPIO does not currently work on the Pi2.

You may connect the servo control wire direct to a gpio. Some people suggest putting a 1k (or so) resistor in series to protect the gpio. I have never bothered.

You should use an external power supply to power the servos. The Pi will only be able to supply power for one standard sized servo or perhaps 2 or 3 9g servos. But the power drain and or spikes can crash the Pi.

Make sure the Pi ground is connected to the external power supply ground (so there is a circuit for the control wire).

See https://www.youtube.com/watch?v=5luZQFxfLCo

The video predates pigpio and used software timed PWM from a C program. It is intended to show the sort of connections needed.

2

The answer, as usual, is "it depends"

Usually, if you're driving just one servo, you can of course make it work directly from the hardware PWM GPIO pin (there's only one that, unless you go the DMA route, will avoid the jitter that happens using one of the other GPIO pins). This Adafruit tutorial shows you how to use the one pin that won't jitter.

if you need to drive more than one servo, then yes, you're looking at some kind of hat (daughterboard) that will run the servos off of a digital signal. Again, Adafruit has a tutorial for a daughterboard they sell that can drive 16 servos.

1

Here is a full source code example that allows you to control n servos via a RESTful web service. The project also includes a bunch of real pictures in the "Content" directory that shows how to look up the servo(s). It looks to use i2C as you mention. I also found an html web page that demonstrates how to control the servo directions in a pan/tilt scenario (e.g. camera) in the servo plugin project. We'll worth the download. It is a C# application that runs with Mono on the Pi; this may be a drawback for you.

https://bitbucket.org/PaulTechGuy/raspberrypi.dotnet.gpioweb

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.