Last active
January 8, 2023 09:34
-
-
Save fxprime/b32f2d72c8f4450365a065e9621d3c18 to your computer and use it in GitHub Desktop.
Control single stepper motor using DRV8825 with library AccelStepper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AccelStepper.h> | |
const int StepPin = 9; | |
const int DirPin = 8; | |
const int EnablePin = 7; | |
AccelStepper stepper(AccelStepper::DRIVER, StepPin, DirPin, 0, 0, true); | |
void setup() | |
{ | |
stepper.setEnablePin(EnablePin); | |
stepper.setPinsInverted(false, false, true); | |
stepper.enableOutputs(); | |
stepper.setMaxSpeed(1000); | |
stepper.setAcceleration(300); | |
} | |
void loop() | |
{ | |
//360 is angle that we want to move to | |
//1.8 is motor step resolution | |
//1/32 is stepSize, configured by dip switch 1(full step), 1/2(half step), 1/4, 1/8, 1/16, 1/32 | |
//steps is how much step that driver should drive the stepper to obtain that angle | |
int desiredAngle = 360; | |
int steps = desiredAngle/(1.8*(1.0/32)); | |
stepper.moveTo(steps); | |
while (stepper.currentPosition() != steps) // Full speed up to 300 | |
stepper.run(); | |
stepper.runToNewPosition(0); // Cause an overshoot then back to 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment