I am using CircuitPython on a Raspberry Pi Pico to control 4 servos. The servos are connected to GP0-GP3 and I'm using the
servo class from
adafruit_motor. Functionally, everything works perfectly, but the code is running much slower than I expected. I used
time.monotonic_ns() to get some approximate timing measurements, and
Code: Select all
time1 = time.monotonic_ns()
servos[servoIndex].angle = angle
time2 = time.monotonic_ns()
gives a value of
time2 - time1 of about 15mS. Even allowing a small amount of time (much less than 1mS) for the
time.monotonic_ns() calls, this means that setting
servo.angle is taking more than 14mS. Even on a modest processor like the Pico, this seems a very long time for a call that as far as I know has to:
- do a simple angle-to-PWM calculation
- write a new PWM value to the PWM registers for the output pin
Can anyone help explain either why the servo update is so slow, or what I'm doing wrong?
Thank you in advance for any help!