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.
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.
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!
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!
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.
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?
And you can get our latest projects and tips straight away by following us on: