DualVNH5019MotorShield.cpp bug?

I have a Pololu Dual VNH5019 Motor Driver Shield for Arduino and noticed M2 was not fully turning-off when setting setM2Speed(0).

I checked the DualVNH5019MotorShield lib and there appears to be an issue in the setM2Speed method. See below. I made the changes and am now geting the behavior I expect on M2.


// Set speed for motor 2, speed is a number betwenn -400 and 400
void DualVNH5019MotorShield::setM2Speed(int speed)
  unsigned char reverse = 0;
  if (speed < 0)
    speed = -speed;  // make speed a positive quantity
    reverse = 1;  // preserve the direction
  if (speed > 400)  // Max 
    speed = 400;
  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
  OCR1B = speed;
  analogWrite(_PWM2,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
  if (speed == 0)

//BUG HERE.  Should not be controlling motor 1 from a method for motor 2.
    //digitalWrite(_INA1,LOW);   // Make the motor coast no
    //digitalWrite(_INB1,LOW);   // matter which direction it is spinning.

//Should be this:
    digitalWrite(_INA2,LOW);   // Make the motor coast no
    digitalWrite(_INB2,LOW);   // matter which direction it is spinning.
  else if (reverse)

Hello, Aaron.

Thank you for taking the time to report this bug to us! I have fixed it. However, I am not sure why it would cause your motor to not fully turn off. The line that sets the PWM duty cycle to 0% should fully turn off the motor, and the lines that set INA2 and INB2 should control whether it brakes or coasts while it is decelerating.