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

