Issue using ESP32 and VNH5019 to drive motor

Hello,
I’m trying to use esp32(NodeMcu-32s) along with VNH5019 motor driver and <DualVNH5019MotorShield.h> to control a DC linear actuator, but i keep getting md.getM1Fault() and the motor doesn’t move, can anyone suggest what the issue might be and how to solve it.
the code I use is posted belbow, and the electric layout is provided.

#include <DualVNH5019MotorShield.h>

#define LA_POSITION_PIN 36   // Your actuator potentiometer analog pin (ESP32 example: GPIO36)

DualVNH5019MotorShield md(
    23, 21, 16, 22, 255,     // M1INA, M1INB, EN/DIAG, M1PWM, M1CS
    255,255,255,255,255      // M2 unused
);

const float Kp = 10.0;
const int MIN_EFFORT = 30;
const int MAX_EFFORT = 400;
const float STOP_TOLERANCE = 2.5;

int targetPosition = -1;
bool running = false;

void setup() {
  Serial.begin(115200);
  delay(2000);

  md.init();

  int initialPos = analogRead(LA_POSITION_PIN);
  Serial.print("Initial LA Position = "); Serial.println(initialPos);

  Serial.println("Type target ADC value (e.g. 567) and press Enter.");
  Serial.println("Actuator will move to that position and hold it.");
}

void loop() {
  // Serial input: parse target position
  if (Serial.available() > 0) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();
    if (cmd.length() > 0 && cmd.toInt() >= 0) {
      targetPosition = cmd.toInt();
      running = true;
      Serial.print("New target position: "); Serial.println(targetPosition);
    }
  }

  // --- Fault check ---
  if (md.getM1Fault()) {
    md.setM1Brake(400);
    Serial.println("M1 FAULT detected! Motor STOPPED.");
    running = false;
    while (1) {
      // Optionally, continue reporting fault or add blink, etc.
      delay(500);
    }
  }

  if (targetPosition >= 0) {
    int currentPosition = analogRead(LA_POSITION_PIN);
    int error = targetPosition - currentPosition;
    int effort = int(Kp * error);

    // Deadzone compensation
    if (abs(effort) > 0 && abs(effort) < MIN_EFFORT)
      effort = (effort > 0) ? MIN_EFFORT : -MIN_EFFORT;
    effort = constrain(effort, -MAX_EFFORT, MAX_EFFORT);

    Serial.print("Target: "); Serial.print(targetPosition);
    Serial.print(" | Position: "); Serial.print(currentPosition);
    Serial.print(" | Error: "); Serial.print(error);
    Serial.print(" | Effort: "); Serial.print(effort);

    Serial.print(", INA: ");  Serial.print(digitalRead(23) == HIGH ? "H" : "L");
    Serial.print(", INB: ");  Serial.print(digitalRead(21) == HIGH ? "H" : "L");
    Serial.print(", PWM: ");  Serial.print(digitalRead(22) == HIGH ? "H" : "L");
    Serial.println();

    if (abs(error) > STOP_TOLERANCE) {
      md.setM1Speed(effort);
    } else {
      md.setM1Speed(0);
      if (running) {
        Serial.println("Target reached. Motor stopped.");
        running = false;
      }
    }
  } else {
    md.setM1Speed(0);
  }

  delay(50);
}

Hello.

Please note that we have not tested that library with ESP32 modules, but I don’t see any immediate reasons why it wouldn’t work.

Your connections seem fine. However, I noticed in your code that the order of the pins in your constructor are wrong: you have the EN/DIAG and M1PWM pins swapped. M1PWM should be the third argument and EN/DIAG should be the fourth. There is also a lot of extra stuff going on in your code, so if fixing that doesn’t work, I recommend simplifying your code as much as possible. For example, you could try adding the constructor to the Demo.ino example and taking out the code relating to M2.

If you continue having problems, could you also post some pictures showing all of your physical connections as well as close-up pictures of both sides of your board, as well as your updated code?

Brandon