Can't run Servo and Motor Shield at the same time!

Hello, My Arduino project consists of an Arduino Uno with a Motor Shield stacked on top (this one specifically, if you are interested: http://www.pololu.com/catalog/product/2502). It uses these ports: 2 4 6 7 8 9 10 12

The motor shield works fine as it has been tested and used to control some DC motors successfully. I decided to plug in a Servomotor to PMW pin 3, using the Arduino 5V pin as power, and therefore attempt to have both the shield and Servomotor running at the same time.

However I could not get the Motor Shield and Servo to work at the same time. I found that the one you initialized last in the code works, but not the one you initialize first! (for example, if you initialize motor shield last, motor shield works and not servo; and vice-versa).

Thank you very much in advance for any help, I know there is a lot of talent on this forum :)

Well you shouldn't run the servo from the Uno's 5v supply ever anyway: I wonder if this is a current related thing? (I assume the motor shield supplies the motors from an external supply, not through the Uno?)

First thing I'd try is to hook the servo to a 5v of its own, with that ground to the Uno's ground.... you never know, it might fix the problem, and it's the right thing to do anyhow 8)

You can't use the servo lib with a motor shield as they both use the same timer. Find a different servo lib or some other way of controlling the servo.

Mark

The servo library uses a hardware timer which is also required to provide PWM output on some pins, so when you use the servo library pwm on those pins is disabled. The reference for the servo library tells you which pins are affected. I don't know whether the motor driver shield uses the same pins (and it's not obvious from a quick skim of the site you linked to) but if it does it would explain your symptoms.

The web site included this note, which makes me think it may be possible to configure the shield to work around the conflict:

Arduino pin mappings can be customized if the default mappings are not convenient