How to use servo library without disabling PWM pins 9 & 10?

I have an Arduino Uno, pololu VHN 5019 Motor driver (linked below) and I'm trying to drive a single servo in addition to the 2 motors driven by the motor controller. The problem is that the motor controller uses pins 9 & 10 and can't be remapped according to the user manual.

Links:

My only option is to figure out how to use the servo without the standard library from what I understand? Does anyone have suggestions programmatically how to solve this problem? I tried detaching the servo immediately after moving it, but the motors continue to not work.

Any help would be appreciated, DM.

My only option is to figure out how to use the servo without the standard library from what I understand? Does anyone have suggestions programmatically how to solve this problem?

You can't get round it because the servo library is using the same timer as the PWM. This is known as conflicting resources, trying to use one thing twice.
The only way round it is to use other pins for your PWM, there are four more on a Uno. Or use a processor with more timers like a Mega.

You can change the pin mappings on that board with a little surgery described here Pololu - 6.a. Remapping the Arduino Connections

Or maybe use the ServoTimer2 library http://arduino.cc/forum/index.php/topic,21975.0.html and lose PWM on pins 3 &11 instead of 9 & 10 if that helps.

UKHeliBob:
Or maybe use the ServoTimer2 library http://arduino.cc/forum/index.php/topic,21975.0.html and lose PWM on pins 3 &11 instead of 9 & 10 if that helps.

I actually just found that and it would work out perfectly, but I'm still unable to find the download link.

Copy the .cpp and .h files from the link I gave or follow the link on this page Creative Robotics – Creating unique machines
Put them in a folder called ServoTimer2 in the libraries folder where your sketches are saved. Don't forget to shut down and restart the IDE to make the library available.

UKHeliBob:
Copy the .cpp and .h files from the link I gave or follow the link on this page Creative Robotics – Creating unique machines
Put them in a folder called ServoTimer2 in the libraries folder where your sketches are saved. Don't forget to shut down and restart the IDE to make the library available.

It doesn't seem to compile (same as the files from previous links), giving me the following error:

In file included from sketch_mar30a.ino:1:
C:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:71: error: 'byte' does not name a type
C:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:72: error: 'byte' does not name a type
C:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:86: error: 'boolean' does not name a type
C:\Program Files\Arduino\libraries\ServoTimer2/ServoTimer2.h:106: error: 'boolean' does not name a type

Edit:

  • This is from the following code, btw:

#include <ServoTimer2.h>

void setup() {}

void loop() {}

It would also help if there were any examples, thanks.

Try putting this in the .h file

#include <Arduino.h>

UKHeliBob:
Try putting this in the .h file

#include <Arduino.h>

It then gives me the following error:

C:\Program Files\Arduino\libraries\ServoTimer2\ServoTimer2.cpp:24:26: error: WConstants.h: No such file or directory

It fixed this by deleting: " #include "WConstants.h" in the .cpp file. It seems to compile now, but i'll let you know if it works.

I managed to get it to work, thanks for all the help. For anyone in the future that needs the library, I compiled it into a zip file with all the modifications and created an example sketch that should work (at least for me it does).

(I personally hate it when people fix a problem and don't include a final fix), Enjoy...

Dm.

Instructions:

  • Unzip folder and place into "libraries" folder of arduino.

ServoTimer2.zip (5.55 KB)

Thanks used it and it works
i searched google for hours till i found this post

dmor574:
I managed to get it to work, thanks for all the help. For anyone in the future that needs the library, I compiled it into a zip file with all the modifications and created an example sketch that should work (at least for me it does).

(I personally hate it when people fix a problem and don't include a final fix), Enjoy...

Dm.

Instructions:

  • Unzip folder and place into "libraries" folder of arduino.