beautypg.com

Pololu Dual VNH5019 User Manual

Page 27

background image

#include "DualVNH5019MotorShield.h"

// configure library with pins as remapped for single-channel operation

// this lets the single motor be controlled as if it were "motor 1"

DualVNH5019MotorShield md(2, 7, 6, A0, 2, 7, 12, A1);

void setup()

{

md.init();

// remaining setup code goes here

...

}

void loop()

{

// loops endlessly; main loop goes here

// the following code is a simple example:

md.setM1Speed(400); // single-channel motor full-speed "forward"

delay(2000); // wait for 2 seconds

md.setM1Speed(0); // single-channel motor stop (coast)

delay(500); // wait for 0.5 s

md.setM1Speed(-400); // single-channel motor full-speed "reverse"

delay(2000); // wait for 2 seconds

md.setM1Speed(0); // single-channel motor stop (coast)

delay(500); // wait for 0.5 s

}

When the library object is initialized this way, you can treat your single motor as if it were motor 1 (i.e. all of the “M1”
library functions will work on the single motor channel). However, note that the

getM1CurrentMilliamps()

method

will not return a meaningful result since current sense feedback is not available in single-channel mode. Also, you
will need to check both M1 and M2 faults in order to get an accurate picture of the driver’s fault status:

getM1Fault()

effectively only returns the fault status of half-bridge A and

getM2Fault()

effectively returns the fault status of half-

bridge B. You could conceivably connect the two fault lines together into a single fault line, but you would want to do
so before the 1k protection resistors (such as by connecting them together via the “MxEN/DIAG A=B” pins, which
give you access to the lines before the protection resistors).

Pololu Dual VNH5019 Motor Driver Shield User’s Guide

© 2001–2014 Pololu Corporation

7. Using the Driver in Single-Channel Mode

Page 27 of 28