earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.03k stars 422 forks source link

Servo library troubles #1594

Closed normanhendrich closed 1 year ago

normanhendrich commented 1 year ago

Hi there, we stumbled about weird behaviour of the Servo library yesterday. Our setup uses one standard servo connected to pin 2 of the Pico board and the Arduino tools with the servo library. That seems to work. We then switched from the Pico to the Pico W board. Now the servo is still moving, but not to the intended angles.

Upgraded the Arduino Pico core to the newest version. Tried different servos and power supplies. Didn't help.

Running the provided sweep demo works normally on the Pico board, showing the expected 180 degrees rotation of the servo. Running the same sketch on the Pico Wifi, everything compiles and uploads just fine, and the servo moves - but not with full 180 degrees rotation. Instead the rotation angles seems about half of that. Really strange.

Are the limitations about which pins can be used for Servo on the Pico W? Is this documented somewhere?

Maybe someone who has a Pico Wifi and a normal servo lying around can verify this quickly? (Connect servo to Pico W, upload sweep example sketch, verify the servo turns 180 degrees.)

earlephilhower commented 1 year ago

Use the attach method that lets you set min and max microseconds values. The library defaults to "safer" limits because back on the ESP8266 we had a non-trivial amount of folks damaging their (probably brand-X) servos by overdriving them.

https://github.com/earlephilhower/arduino-pico/blob/14eb8d39067f3fe5ab5c591f9a9622b35979c0a0/libraries/Servo/src/Servo.h#L67

There are no pin limitations, as long as it's a standard GPIO pin. We use the PIO state machine to generate the waveform and it can toggle any of the GPIOs.