PiicoDev servo control - moving back and forward with no delay

Hi all, I’m using this piicodev servo controller for the high torque FS5115M and was wondering if you could help me out? I’m trying to make servo go from 0 to 180 to 0 with no paused time in between but seem to work it out. I’m using code like this but not sure if I’m controlling it properly? I’ve tried adjusting the sleep time but that doesn’t seem to reduce the time it pauses.

servo.angle = 0
sleep_ms(400)
servo.angle = 180
sleep_ms(400)
servo.angle = 0

Any feedback would be appreciated!

Hey @Sam11767 - welcome to the forums.
You’ll need at least some delay to give the servo time to move to the new setpoint. Exactly how much delay will depend on how far the servo has to travel. It seems like you’ve already arrived at this solution!

Without some feedback mechanism (eg. a servo with positional feedback) this is about as good as it’s going to get.

An alternative if you absolutely must have continuous, smooth motion might be to use a continuous rotation servo/motor and convert the angular movement into a reciprocating movement with a mechanical linkage. DIY at your own risk :stuck_out_tongue:

Don’t move the whole distance in one command. Move one step at a time (eg, 1 degree) with a delay between each step that means the servo moves at the speed you require.

1 Like

Hi Jeff and all

Can someone enlighten me here please. With an Arduino how does one move a servo 1º. Most servos I have seen use a pulse width from 1000µs to 2000µs to move 180º Is this so???
If using pot control the ADC numbers go from 0 to 1023.
The Arduino clock is 16MHz
If using direct register entries (as I have done and will be the subject of a future post) the timer ticks have to be whole numbers.

The point here is I can find no direct mathematical relationship between any of these numbers and 180º. So just how can this happen, that is move a servo a specific number of degrees. I have seen the word “precision” mentioned with regard to servo positioning and I have been wondering about this.

Maybe something other than Arduino may do this, like Pi Pico with its faster clock speed would do this.
That can be my next challenge when I finish with my present problem and have some time.
Cheers Bob

1 Like

Precision is irrelevant in this case. OP is moving the servo 180 degrees and back. To get smooth movement it is necessary to have a consistent delay between each move. To achieve this the total angle to move is divided into multiple small steps (eg, 1 degree) with only enough delay between each step to make the total movement occur at the desired speed. If individual steps are not precise it doesn’t matter - the errors disappear over 180 degrees.

1 Like

Try this demo code @Sam11767
It implements @Jeff105671’s recommendation. You can tune how the servo behaves with the delay and step_size variables

### Import your packages
### Set up your servos here as normal

delay = 50      # milliseconds
step_size = 5   # degrees

while True:
  for ang in range(0,180, step_size):
      servo.angle = ang
      sleep_ms(delay)
  for ang in range(180, 0, -step_size):
      servo.angle = ang
      sleep_ms(delay)

Hi Jeff

Quite so. But what I mentioned is the word has often come up when dealing with servos. Like “servos are ideal when something has to be rotated X degrees with precision”. Not an exact quote but that is the general idea.
The Arduino timers need whole numbers so will only use the interger part of a number with any calculations required. Maybe would be closer if the “round” arithmetic function was included in Arduino reference without doing this the long way.I did notice yesterday a Pico sketch using the “round” function but I have not had any experience with Pico but something to look into.

And my question was

or for that matter any multiple of 1º
Cheers Bob