My problem is that the servo does not make any steps below 9°. So when I run the code, the servo makes the movement to 180° but in approx. 9° steps and not 1° steps. I tried to manually set the "pos" value to 1, 2, and so on - nothing happens until I set the value to 9° and then the servo moves...
I am using an Arduino Uno R4 and tried with and without the motor shield R3. Same result (not surprisingly).
I tried with two different (digital) RC servos, using pin 6, pin 9, pin A2: always the same result. I powered the servo from the orange out6 connector of the motor board and from the "gnd" and "5V" connectors on the "power" section of the Arduino - always the same result.
Ok, thanks for this hint. I checked it and added the Arduino board (and motor shield) version that I use.
I didn't find a category/topic where my question would fit in better and I provided the code (in the link) and the wiring situation is described (I also clarified this more).
Is there anything missing or not according to the rules now?
You should also try the sweep example that is installed with the IDE. Still waiting to see your code. It's important you post exactly the code that relates to the problem you're describing. Too many times, "but I didn't change anything...important" becomes "well, just that, but that couldn't be the problem, could it?" Guess what.
The change of the servo position? I just look at the lever... The 9° "quess" comes from the fact that when I set the "pos" value to 8, nothing happens and when I set it to 9 the servo moves. So the "critical" value is somewhere between 8 and 9.
Interesting. Thought you might be measuring change in pulse width, which runs IIRC around 6 us/degree.
Sorry, can't help until I get to the lab, won't be tonight. Maybe, others?
I limited the total travel angle to remain in the field that the servo can handle. See code below. Now the servo makes the travel in four steps (of approx 9°) and then the same on the way back.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 45; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(85); // waits 15 ms for the servo to reach the position
}
for (pos = 90; pos >= 45; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(85); // waits 15 ms for the servo to reach the position
}
}
I am (now) powering the servo with an external power source of 5V. Ground of the external power source is connected to the ground of the Arduino Uno R4. The yellow wire of the servo is connected to pin 9.
I just read on another site that other people also had problems with servos on the Uno R4. Including a user that also had movement in 10 degree steps. Are you libraries up to date.
I would put the R4 in the back of a drawer for now.
Get the R3 out, and give that a try.
Leo..
A fix has been merged to the library, but a new release hasn't been done to include it. So you won't get the fix by installing the library through the Library Manager.
But you can manually install the library with the latest fixes from the link below and your servo should rotate as smooth as silk.
You could also try the MoToServo class of the MobaTools library. This library can move the servo slowly by itself without the need of a for loop. And it runs smoothly on R4. The library can be installed via the library manager.
There is also a sweep example.
For the benefit of anyone who is interested in what is going on, who doesn't have an Arduino Uno R4 and/or an oscilloscope, here is a video showing how the pulse width varies using the IDE example 'Sweep'.
The IDE Example 'Sweep' has been modified by changing the delay(15) to delay(100).
The pulses are repeated every 20ms.
The width of the pulse can be seen to jump in steps of 100µs.
Compare that with exactly the same code on an Arduino Uno R3:
You don't need to download the zip. Just install it with the library manager ( typing MobaTools in the search field ).
I never had a problem with a virus when downloading the zip ...