Go Down

Topic: Hardware Servo: Example Code (Read 4 times) previous topic - next topic


Thanks for writing this code, I was also surprised that the Due rolled out without a formal way to manage servo control.  Thanks for the code.  As far as integrating the modified servo.h library to use, how does one take the code for the modified servo.h and integrate into my working copy onto one's computer?


Feb 01, 2013, 12:04 am Last Edit: Feb 01, 2013, 12:07 am by conradelektro Reason: 1

I've pushed a first porting of the Servo library (the one distributed with Arduino IDE) for the Due, you can find it on the latest revision of the ide-1.5.x branch.


I did some rapid tests, and it seems to work.

I can see the code at https://github.com/arduino/Arduino/commit/db81f52c3a27784fb44ca1ad6c77f9b1f0a4ef7d

but I do not know how to get these files and how to put them in my Arduino Due IDE?

Please have mercy with a beginner!

Can I drive a servo with pins 26, 28 and 30 ?

Greetings, Conrad


In attachment a zip with a copy of the files. Unzip it into hardware/arduino/sam/libraries.


Feb 01, 2013, 12:57 am Last Edit: Feb 01, 2013, 08:43 pm by conradelektro Reason: 1

In attachment a zip with a copy of the files. Unzip it into hardware/arduino/sam/libraries.

Thank you, I did that, and the example Sweep compiled.

How about using pins 26, 28 and 30 for a Servo?

Does it have to be pin 9?

Greetings, Conrad

P.S.: I tried with pins 26, 28 and 30. There seems to be something going on, because I see the LEDs connected (via a 1 K resistor to GND) to these pins dimming and getting brighter as the Servo example Sweep should do. Seems I am set up, thank you C.

P.S.: Servo works on pin 30. So, download the library (ZIP-File) from cmaglie's post above this post, and you are set to use Servos with the Arduino Due.

Sebastian Vik

Hello everyone!

After reading the data sheet properly, I've updated my hardware servo library to use all available PWM channels and all available output pins, see the following table. This overrides the Arduino distribution variant.cpp pin configuration g_APinDescription[] for the Due, which is far from complete.

PWM PinChannel

This means you can output a servo signal to any of the above pins, but only one pin per channel. For example, you cannot output two different servo signals on pin A10 and CANTX at the same time because they are both driven by the hardware PWM channel 3.

It is possible to output a servo/PWM signal on a bunch of other pins as well by using the complementary PWM signal for each channel but the above pins suit me well enough not to warrant writing the code for handling inversion of duty cycle parameters (and thereby increasing the runtime size of the code)

To use the library, simply unpack the ZIP into your libraries folder, restart Arduino and open the DueServo example Sweep.

Go Up