Controlling Standard Servos with Raspberry Pi

Hey all, just completed the last tutorial “Controlling Standard Servos with Raspberry Pi”.

This should be the fastest and most effective way to get up and running with a servo using a Raspberry Pi Micro-processor - no matter the size of the servo.

Demonstrated here is the fast way to control either small 9 gram servos or a much more powerful 15 kg servo. Servos are an immensely useful way to turn electrical energy into a rotational or linear motion with high efficiency and with great precision. The ones in this guide are all Standard Rotary Actuator Servos that can rotate 180 degrees or 270 degrees. Precise control over the narrow range (degrees of movement) is achieved through position. Information on the desired position is sent through via a PWM (pulse-width modulation) signal.

Read More

4 Likes

I’m sure that Tim got results. How good they were I don’t know.

I did something similar a year ago to remotely turn amplifier volume knobs using a Pi Zero W. The Pi Zero has limits and it was hopeless using Tim’s approach. I purchased an Adafruit 16-Channel PWM / Servo Bonnet and got excellent results. It was crazy to use a Pi 4 when a Pi Zero W could do the job.

My advice is to use I2C modules with any Raspberry Pi. Arduinos had the advantage re analogue input. I now use Raspberry Pis and I2C ADC modules. The cost is about the same. The accuracy is much better. I can update my software without touching my custom module. I now have only one Arduino controller and it is doing a very simple job.

2 Likes

Hey John,

Sounds awesome! Yeah, the Pi’s software PWM is trumped by a microcontroller’s onboard timers for generating a PWM.
I2C definitely is the most plug and play solution. With the new RP2040 released by Pi foundation I’d be keen to see some controller-peripheral HAT’s for the Pi’s - something that’s a jack of all trades, ADC’s hardware PWM, and on the fly programming would be cool to see!

Liam.

1 Like

Hiw can i control sbus servos?

1 Like

Hi Don,

Welcome to the forum! Very interesting question.

There’s an interesting forum topic and project on GitHub solving just the question you had!

But if you’re after something quick to put together for the Pi, I’d go for the PWM signal based servo’s as they are very well documented in the Hobby electronics space!

Liam

1 Like

As a novice to the subject of servo control, I found the code in this tutorial caused some “jitter” on my Tower Pro SG51R servo. The pigpio library resulted in smoother control in my setup.

Hi team,

I am planning to use the GPIO Zero Angular Servo - pretty much the example code you provided here.

Could you please suggest what would be the min_pulse_width and max_pulse_width for following digital servos?

  1. ES9052MD Coreless motor/ All purpose use / Metal Digital Servo | Emax

  2. Emax ES3054 17g 3.5kg 0.13sec 23T Metal Gear Digital Servo For RC Airp | Emax

On the product page it says 600 - 2400. Does it equate to 0.0006 to 0.0024 in the code?

Also, what would be the min and max angle for these? at one place it says 360 degree servo while at other place it says 145 degrees for one and 160 degrees for another. If I want to set min and max, will it be -145 for min and 145 for max?