Motor does not turn when running the VNH5019 demo program using an Arduino Nano ESP32

Hello, I have used this motor controller with Arduino Mega 2560 in a project many years ago. I am now trying to use it with an Arduino Nano ESP32. I tried the Demo program in DualVNH5019MotorShield but it does not work. Motor does not turn at all and I can turn it by hand. Perhaps due to compatibility issue with the ESP32? Could you pleae have a look?
All the components are working and the LED on the VNH5019 is on. I could use another program to turn it but the official demo program about 10 years old does not work.

For your convenience, here is the program:

#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);

  }

}

The Nano ESP32 was introduced 2 years ago.

The library code you are trying to use was last updated 7 years ago.

5 years before the Nano ESP32 existed.

It's hardly surprising that the library code doesn't work with a board that didn't exist when it was written.

2 Likes

This is anoher program that I tried and could turn the motor. However, there is a problem. At lower speeds (e.g. i = 50), the torque also gets lower and I could stop the motor easily by hand. It is not the motor problem because if I connected it directly to the power source, it had much higher torque and I could not stop it by hand. Kow how to fix that? Any sample program that works without this issue?


int motor2Pin_A = 2;
int motor2Pin_B = 3;
int PWM2   =  21;
int i = 50;

void setup(){
  pinMode(motor2Pin_A, OUTPUT);
  pinMode(motor2Pin_B, OUTPUT);
  ledcAttachPin(PWM2, 0);
  ledcSetup(0, 490, 8); 
}

void loop() {
  digitalWrite(motor2Pin_A, LOW);
  digitalWrite(motor2Pin_B, HIGH);
  ledcWrite(0, i);
  delay(100);
}

Reduce the delay by 1/2 and try again. Then do it again and again until you get the rotation speed you want.

Rather then guess I would like you to post an annotated schematic showing exactly how you have wired it. Also include links to each of the hardware parts.

Why reducing the i value not only slows down the turning but also reduces the torque?

That would increase the pulse rate and increase the motor speed, but your setup obviously does not work that way. So, how does your setup attempt to power the motor?

Sorry I don’t quite understand what you mean. What setup are you talking about? I have an external power source to power the VNH5019 and the motor.

If the (loop) part of your program is not controlling the motor, what is it doing?

I didn’t write it. I found it on the internet. It was working but not anymore. Anybody has a sample program that works?

That’s like choosing from a box of unlabeled cans and hoping you don’t pick dog food. Without clear details, all we can do is guess.