Go Down

Topic: How to use servo library without disabling PWM pins 9 & 10? (Read 5043 times) previous topic - next topic

dmor574

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:
- Motor Controller: www.pololu.com/catalog/product/2502
- Library: https://github.com/pololu/Dual-VNH5019-Motor-Shield
- User Manual: www.pololu.com/docs/0J49
- Arduino Servo Library: arduino.cc/en/Reference/Servo (states pins 9 & 10 are disabled when in use)

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.

Grumpy_Mike

Quote
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.

UKHeliBob

You can change the pin mappings on that board with a little surgery described here http://www.pololu.com/docs/0J49/6.a
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dmor574


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.

UKHeliBob

Copy the .cpp and .h files from the link I gave or follow the link on this page http://www.creative-robotics.com/?q=protoshield1
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dmor574

#6
Mar 30, 2013, 09:56 pm Last Edit: Mar 30, 2013, 10:00 pm by dmor574 Reason: 1

Copy the .cpp and .h files from the link I gave or follow the link on this page http://www.creative-robotics.com/?q=protoshield1
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:

Code: [Select]


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.

UKHeliBob

Try putting this in the .h file
Code: [Select]
#include <Arduino.h>
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dmor574


Try putting this in the .h file
Code: [Select]
#include <Arduino.h>


It then gives me the following error:

Code: [Select]

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.

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.

marco_o

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



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.

Go Up