I'm trying to use the VNH5019 dual motor driver without the library. The following sample code works as expected.
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
void stopIfFault()
{
if (md.getM1Fault())
{
Serial.println("M1 fault");
while(1);
}
if (md.getM2Fault())
{
Serial.println("M2 fault");
while(1);
}
}
void setup()
{
Serial.begin(115200);
Serial.println("Dual VNH5019 Motor Shield");
md.init();
}
void loop()
{
for (int i = 0; i <= 400; i++)
{
md.setM1Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
}
delay(2);
}
for (int i = 400; i >= -400; i--)
{
md.setM1Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
}
delay(2);
}
for (int i = -400; i <= 0; i++)
{
md.setM1Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
}
delay(2);
}
for (int i = 0; i <= 400; i++)
{
md.setM2Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
for (int i = 400; i >= -400; i--)
{
md.setM2Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
for (int i = -400; i <= 0; i++)
{
md.setM2Speed(i);
stopIfFault();
if (i%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
}
I would like to use the motor driver without the library. I used the attached truth table on pg 14 of the data sheet for this code:
int M1INA = 2;
int M1INB = 4;
int M1EN = 6;
int M2INA = 7;
int M2INB = 8;
int M1PWM = 9;
int M2PWM = 10;
int M2EN = 12;
void setup() {
pinMode(M1INA, OUTPUT);
pinMode(M1INB, OUTPUT);
pinMode(M1EN, OUTPUT);
pinMode(M2INA, OUTPUT);
pinMode(M2INB, OUTPUT);
pinMode(M1PWM, OUTPUT);
pinMode(M2PWM, OUTPUT);
pinMode(M2EN, OUTPUT);
}
void loop() {
digitalWrite(M2EN, HIGH); //enable left motor
digitalWrite(M1EN, HIGH); //enable right motor
digitalWrite (M1INA, HIGH); //forward
digitalWrite (M1INB, LOW);
analogWrite(M1PWM, 255);
digitalWrite (M2INA, HIGH); //forward
digitalWrite (M2INB, LOW);
analogWrite(M2PWM, 255);
}
Unfortunately the result is that the motors don't turn and sound like they are stalled out even though there is no load on them.
I have looked for sample code without using the library on the data sheet, user guide, this forum, google, instructables, and Pololu's forum. Anybody used this or something similar without the library? I attached the truth table from the data sheet.
I'm using 6 AA NiMH batteries for the motor power supply and a 9V battery for the arduino supply.