Are your servos jumping when controlled by an Arduino UNO R4?
The solution is simple. Update the Servo library so that your Arduino UNO R4 can smoothly control the servos.
Problem description
Instead of a smooth sweep, you may encounter servos that move in discrete steps as shown in Figure 1. In this example, the Digilent Analog Discovery’s persistence was turned on. We can see that the servo has only 10 discrete steps, which makes it impossible to smoothly control a device such as a robot arm.
Figure 1: Without the new library, the Arduino Uno R4 is limited to about 10 discrete steps when driving an RC servo.
How to update the library
Updating the library is as easy as 1, 2, and 3 as shown in Figure 2.
-
Click the Arduino Library icon.
-
Type in word “servo”.
-
Update the library to version .2.2 or greater to properly support the UNO R4.
Don’t forget to recompile your program.
Figure 2: Steps to update the Arduino Servo Library.
Results
The results are shown in Figure 3. We see that the original 10 steps have been replaced with hundreds of discrete steps. This will provide precise control for your robot’s servos.
Figure 3: The servo’s performance is improved as hundreds of discrete pulse width values are now available.
Servo test code
The following code was used to perform both tests. The only difference is that Figure 1 used Servo library V1.2.1 while the Figure 3 test used Servo library V1.2.2.
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(11);
}
void loop() {
static uint16_t i = 1500;
myservo.writeMicroseconds(i++);
if(i > 2000){
i = 1000;
}
delay(5);
}
Parting thoughts
This was a simple fix. Please let us know if you have any questions about the DigiKey products.
Best wishes,
APDahlen
Related information
Please follow these links to related and useful information:
About This Author
Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this.