PWMServo
Arduino 0016 introduced a spanking new Servo library that makes it possible to control a Servo from any pin. The old library used PWM, which limited its use to pins 9 or 10.
Unfortunately, the new library uses an interrupt-based technology which breaks NewSoftSerial. If you’re building a project that needs Servo and Soft serial, you might try this library instead. (I didn’t write it; this is really just the old library renamed.)
[August, 2011 update]
Paul Stoffregen recently updated the library to include support for Teensy, Teensy++, Sanguino, and the Mega varieties. This is really a nice and much appreciated improvement. Because of the additional timers that the Mega and Teensy processors provide, these platforms can support a third simultaneous servo.
Thanks Paul!
The pins that are available for controller servos vary from controller to controller, so here’s a tidy table showing you which pins are available:
Board SERVO_PIN_A SERVO_PIN_B SERVO_PIN_C ----- ----------- ----------- ----------- Arduino Uno, Duemilanove 9 10 (none) Arduino Mega 11 12 13 Sanguino 13 12 (none) Teensy 1.0 17 18 15 Teensy 2.0 14 15 4 Teensy++ 1.0 or 2.0 25 26 27
Download
Download the original PWMServo library (as it was shipped with pre-0016 Arduino).
Download Paul’s version 2 library with Teensy, Teensy++, Mega, and Sanguino support.
Mikal
Kevin
11 months ago
Mikal,
Can you explain how the old PWM works? If it isn’t interrupt based is it reliable? Are there any reasons to not use it?
I am trying to use it in a very simple example sketch to drive an RC car through and ESC and it is very erratic. I can’t seem to identify what the RC car needs to drive it reliably. I can get the wheels to turn but not in a controllable, methodical way. I learned that this library doesn’t have the writeMicroseconds method available.
Your thoughts?
Mikal
11 months ago
Kevin,
The old servo library is very reliable. It coexists with other libraries like tone and NewSoftSerial a lot better. The only drawback is that it only supports a total of 2 servos and these must be on pins 9 and 10.
Mikal
Desmond
11 months ago
desmond,
Is PWMservo the new or OLD servo library? Because i want to be able to drive a single servo while using newsoftserial.
Mikal
11 months ago
PWMServo is the library you want if you want to use NewSoftSerial at the same time.
Mikal
Desmond
11 months ago
Mikal,
COuld you please tell me where i would find information on this library. Because i need to be able to produce a PWM that i can adjust the duty cycle to drive a normal motor.
And
i need to be able to turn a normal motor 90degress in both direction.
How do i use this library to do that.
Mikal
11 months ago
Desmond, this library has (mostly) the same interface as the current Servo library. (See the documentation in arduino.cc for that.) Neither of them will allow you to drive a normal motor. That’s a different technology.
Mikal
Charles
10 months ago
Mikal,
Is it possible to rework the PWMServo library to work on pins other than 9 and 10? I am working on a project with a duemilanove ATmega328 with a sdmicro shield using pin 10, and I have two servos that I need to control. I also have several serial devices which require the use of newsoftserial.
Thanks for any help you can offer!
-Charles