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
}