Stepper motor steps not counting up

For some reason, my stepper motor is rotating only half the number of steps that it should be, and I am confused as to why.

I'm using a NEMA 23 (Moon ML23HS8P418B) on a Kamoer KDS3000.pdf (4.3 MB) peristaltic pump; I'm running it on a DRV8825 stepper motor driver carrier from Pololu and wired for the minimal wiring diagram; I have M0, M1, and M2 pulled low (I connected them to ground trying to solve the problem, even though they have internal pull-down resistors); I am using AccelStepper.h to operate the motor (motor interface type 1 because of the stepper driver); and I'm running this on an Arduino Giga. The DRV8825 sleep and reset pins are connected to 3.3V and the motor is powered with 24V (there is a 1000µF electrolytic capacitor bridging the positive and negative; it's overkill, but it's what I had available); the step and dir pins have added 10 kOhm pull-down resistors (they also have internal ones in the DRV8825 carrier, but I was troubleshooting). I did switch the black and green wires on the XHP-4 connector coming from the motor because I was pretty sure that this is what was required with the DRV8825 pinout. I also added a cooling fin to the DRV8825 chip and added a PC fan as a precaution (I set the current limit using VREF, and VREF is 0.9V as the rated current of the stepper motor is 1.8A)

With this setup, there should be 200 full steps per revolution (step angle 1.8°). For some reason, the stepper motor is rotating only 180° instead of 360°, and I am confused as to why.

Here is my code:

  // Define stepper motor interface for AccelStepper libary
  const int motorInterfaceType = 1;

  // Create a new instance of the AccelStepper class:
  AccelStepper pumpMotor = AccelStepper(motorInterfaceType, stepperStepPin, stepperDirectionPin);

void testPumpMotor(){
    // Initialize stepper motor on pump
  append_text_to_label(label_startup, "Starting pump motor.");
  nonblockingTimer = millis();
  while(millis() - nonblockingTimer < 500){
    lv_timer_handler();
    delay(5);
  }
  
  append_text_to_label(label_startup, "Motor turning clockwise.");
  nonblockingTimer = millis();
  while(millis() - nonblockingTimer < 100){
    lv_timer_handler();
    delay(5);
  }  

  pumpMotor.setCurrentPosition(0);
  pumpMotor.moveTo(200);
  pumpMotor.setSpeed(50);
  while (pumpMotor.distanceToGo() != 0) {  
    pumpMotor.run();  // Non-blocking movement
    lv_timer_handler();
  }

  append_text_to_label(label_startup, "Motor turning counterclockwise.");
  nonblockingTimer = millis();
  while(millis() - nonblockingTimer < 500){
    lv_timer_handler();
    delay(5);
  }
  
  pumpMotor.setCurrentPosition(0);
  pumpMotor.moveTo(-200);
  pumpMotor.setSpeed(50);
  while (pumpMotor.distanceToGo() != 0) {  
    pumpMotor.run();  // Non-blocking movement
    lv_timer_handler();
  }

  pumpMotor.setSpeed(0);  
}

It's not a great view, but here's a picture of my setup.

HI, @littlejohn657
Sorry but I had to spread it out ot make it easy to read.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

The DRV8825 has a relatively long min pulse width (1.9 us according to data sheet), and the Giga has a fast Cortex M7 CPU. For this combo, I suspect the step pulse time may be too short. AccelStepper appears to default to 1us, but in practice I get pulses < 1us.

I suggest calling pumpMotor.setMinPulseWidth(5);. May be a red herring, but worth a try.

Otherwise I don't see anything wrong with your code, but often the error is in the code not posted.

I think that this solved my issue, though I went with pumpMotor.setMinPulseWidth(2); (I figured that it's just a bit more than the 1.9 ms, and I don't want to take up extra time unnecessarily). Thanks, bobcousins!