Hi, every time I run a simple code to run a stepper motor I get different outcomes. Here is the code I've been using.
#define STEP_PIN 54
#define DIR_PIN 55
#define ENABLE_PIN 38
int i = 0;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW);
}
void loop(){
delay(1);
if ( i < 3230){ //it appears that for i = 3230 is for one rotation
digitalWrite(DIR_PIN, HIGH);
i++;
}
else{
digitalWrite(ENABLE_PIN, HIGH);
//digitalWrite(DIR_PIN, LOW);
}
digitalWrite(STEP_PIN , HIGH);
digitalWrite(STEP_PIN , LOW);
}
when I try to run it for multiple rotations, it starts to sputter through the steps and is never consistent!
The motor that I'm using is a 1.8 degree stepper motor controlled with a RAMPS 1.4 and A4988 Pololu Stepper Motor Driver Carrier with and Mega 2560 arduino.
Please let me know how I can have complete, consistent, and precise control on this stepper motor! If you have any sample code I would greatly appreciate it!!!!!!