Hello all, I am using a NEMA14 in conjugation with a DRV8825 driver and a 9V power supply. The code below runs perfectly fine when I set the microstepping to a 1/4. However when I change to a full step the motor just buzzes and doesn't move. I have posted my code below, thanks in advance!
#include <AccelStepper.h>
int enPin = 8;
AccelStepper stepper(AccelStepper::DRIVER, 2, 4);
void setup() {
Serial.begin(115200);
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(-8000); //need 85663 steps to travel whole rail 340mm length, 0.003969mm/step
stepper.setSpeed(800);
stepper.runSpeedToPosition();
digitalWrite( enPin , HIGH); // Deactivates Motor
digitalWrite( enPin , LOW); // Activates Motor
stepper.moveTo(160000); //need 85663 steps to travel whole rail 340mm length, 0.003969mm/step
stepper.setSpeed(800);
stepper.runSpeedToPosition();
}
You forgot to set the acceleration!
NEMA14 is a mechanical specification, not electrical. 9 volt supply make me nervous. Tell more, closer data, please.
I think this could be a programming problem. There is no big issue but I see a few small things that could be confusing the motor. In setup, only set maxSpeed. In loop, moveTo sets target, but you don't need to run to position twice. Do something like .moveTo(-8000) then setSpeed(800) then only call runSpeedToPosition at the very end. You can still stop the motor at specific spots by using the function if (distanceToGo() == 0) -> do whatever. Then you can set new target position with moveTo and new speed.
I made a project similar to this with a robotic arm controlled with constant speed to positions. the repo is here, feel free to reference it. No need to set acceleration either if you plan to only use constant speed. https://github.com/RoboticWorx/ERA-Chess-Robot/blob/main/ERA_Chess
I tried setting the speed to "stepper.setSpeed(200)" the motor still just buzzes without rotating the lead screw (full step configuration). But if I change to a 1/4 step it moves the screw