I think I found the problem
// — Motor control —
// DRV8871 logic (IN1 = PWM, IN2 = direction):
// Based on your last test:
// Forward: IN1 = PWM, IN2 = HIGH
// Reverse: IN1 = PWM, IN2 = LOW
// Standstill (freewheel): IN1 = 0% PWM (LOW), IN2 = LOW
void controlMotor(int pwmValue, bool forward) {
Serial.p
IN2 IS NOT THE DIRECTION CONTROLLER
it does not work that way
You basicly want to do a push-pull motion on these pins
SO
Lets Call
IN1=INF (Forward)
IN2-INR (Reverse)
Forward is INF=Pull Up (Duty Cycle), INR=Pull Down (100%)
Reverse is INF=Pull Down (100%), INR=Pull Up (Duty Cycle)
Standstill (Freewheel): INF=Low (100%), INR=Low (100%)
Standstill (Break): INF=High (100%), INR=High (100%)
I would totally forget the idea of PWM and think more of Duty Cycle
so write your code to have a Duty Cycle Loop
what you are trying to do is varry the voltage being applied to the motor
you could test with a multimeter to verify… you also may want to design a feedback system to sense the voltage