AccelStepper setSpeed(- "Value") struggling

Motor: Nema14
Driver: DRV8825

Hello, my project goal is to rotate a stepper motor at a constant speed to a set position and then reverse back to the starting point. Repeating this cycle hundreds of times. I am using the AccelStepper library, when the speed is set to a positive value the motor operates as expected at the constant speed. However, when the speed is set to a negative value to return back to the original location the motor operates at a much slower rate and vibrates heavily. To try and trouble shoot I attempted just sending the motor in the negative direction to simplify my code. Still running into the same problem though.

#include <AccelStepper.h>
int enPin = 8;
AccelStepper stepper(AccelStepper::DRIVER, 2, 4);
void setup() {
 
    pinMode( enPin ,OUTPUT);
  //digitalWrite( enPin , HIGH); // Deactivates Motor
   digitalWrite( enPin , LOW); // Activates Motor

stepper.setMaxSpeed(4000);
stepper.setSpeed(-800); 
}

void loop() {
stepper.runSpeed();

}

The final goal is to use something more along these lines:

#include <AccelStepper.h>
int enPin = 8;
int Position = 800;
AccelStepper stepper(AccelStepper::DRIVER, 2, 4);
void setup() {
 
    pinMode( enPin ,OUTPUT);
  //digitalWrite( enPin , HIGH); // Deactivates Motor
   digitalWrite( enPin , LOW); // Activates Motor

  // put your setup code here, to run once:
stepper.setMaxSpeed(4000);
stepper.setSpeed(800); 

}

void loop() {
stepper.moveTo(10000);
stepper.setSpeed(800);
stepper.runSpeedToPosition();
stepper.moveTo(-10000);
stepper.setSpeed(-800);
stepper.runSpeedToPosition();
}

Try not changing speed, just direction..
Example 2 motors back and fourth..
In the above example we were actually trying to get them to be out of sink slightly..
Also uses non-blocking routines..

good luck.. ~q

Same issue unfortunately, I tried using my second posted code but changing the speed to positive since it is going to a 'negative' position. But yah same issue

Speed is not a vector. It's zero or more. Use direction for changing rotation.

???????? What is negative speed? Never heard of reverse?

Use position, "goto position". AccelStepper will figure it out.

Are you using a CNC shield? With the CNC shield V3 and V4, the X axis motor is pins 2 (step) and 5 (dir).

The sign of 'speed' in Accelstepper::setSpeed( speed ) defines the direction of rotation.

@asayrews : I tried your first sketch and it works fine on my hardware. So I suppose a problem with your hardware.

Problem with hardware? Could it be the wiring?

I am using a DRV8825 expansion board with the dir pin on 2 and step pin on 4

Please show a schematic and a picture of your actual setup. How is the motor powered? What motor (datasheet, Nema14 tells nothing about the electrical data)? Did you setup the motor current accordingly?

image

Motor is power using a 9V supply.

A schematic is still missing. And the picture doesn't show your complete setup. A link to the full datasheet would be more helpful. Are you sure the coils are connected correctly?
9V is a minimum for your stepper and board - more would be better. How many amps can your PSU deliver.

2.5A, I just reversed the coils and it looks to be helping but the motor is struggle a bit still

Your code and statement from post #8 disagree.

To what value have you set the DRV8825 current limit?

Current limit is set at 2.2A

That is a problem. The DRV8825 can handle at most 1.5A without forced air or other additional and effective cooling.

It has a heat sink and it is not heating up at all. Is it still receiving too much current?

Something is very wrong if the driver is set to 2.2A and not heating up. Normally, the driver would simply overheat and shut down. It is completely unrealistic to expect 2.2A/winding from a hobby DRV8825 module, and the little heat sink shown in the photo is just for show.

You definitely have problems with your stepper setup. Please provide a wiring diagram (hand drawn is preferred), with pins, connections and part clearly labeled.

As a test, carefully follow the instructions in the DRV8825 data sheet to set the current limit to 1.0A/winding, and test the operation with no load on the motors.

Finally, keep in mind that it is unrealistic to expect any motor to instantly reverse direction while turning. Stop it completely before changing direction.

Do you have a DMM to check the wiring of the coils and that they are connected correctly to the DRV8825 ( A1/A2 to one coil and B1/B2 to the other and not crossed)?

I do not unfortunately, if I just flip them and test will this damage the motor?