Why can't I run a Servo and Motor shield at the same time?

Hello,
My Arduino project consists of an Arduino Uno with a Pololu Dual VNH5019 Motor Driver Shield for Arduino (this one specifically, if you are interested: 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 smiley

If it helps solve the problem here is my code:

#include "DualVNH5019MotorShield.h"
#include "Servo.h"

DualVNH5019MotorShield md; //Motor Driver instance
Servo servie; //Servo instance

void stopIfFault()
{
  if (md.getM1Fault())
    while(1);
  if (md.getM2Fault())
    while(1);
}

void setup()
{
  md.init(); // init motor driver
  servie.attach(3); // init servo & attach to PWM pin 3

}

void loop()
{
  /* Set servo to angle 0, set motor speed to 100 (minimum speed) */
  servie.write(0);
  md.setM1Speed(100);
  md.setM2Speed(100);
  
  delay(3000); // wait 3 seconds
  
 /* Set servo angle to 180, set motor speed to 400 (max speed) */
  servie.write(180);
  md.setM1Speed(400);
  md.setM2Speed(400);

  delay(3000) // wait 3 seconds
}

Hello.

Both the Arduino servo library and the VNH5019 motor driver shield library use timer 1 when connected to an Arduino UNO, so they cannot be used together. We ran into a similar problem when adding a servo on our Zumo robot. You might try using the code found in the “Controlling a servo” section of the Zumo Shield User’s Guide.

- Jeremy

Thank you very much for your help! I have found a Servo Library that uses Timer 2 so I will give that a shot.
Once again thanks for replying.