Back in Nov 2014 Robin2 gave a basic Arduino program to run a stepper motor through the A4988 driver, Simple Stepper Program. Program works fine but I have one question. In the void setup() section there is a delay(2000) instruction. During this period on my setup the motor is energised and turning, then at the end of the delay period the body of the code kicks in and motor rotates as programmed.
I have experimented with adding the delay into my working programs and it always has same affect, once power gets to the motor it rotates until Arduino code kicks in and takes control. A consequence of this is that even when the delay is removed there is still a fraction of second delay (in the code I assume) when the motor can move momentarily, enough to a make a small but noticeable start up kick.
Web searches suggest I am alone in seeing this activity. I use a NEMA17, A4988 and Arduino Uno. Has anyone experienced this or able to duplicate it?
Apologies thought included hyperlink would be sufficient.
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing
byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20; // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps
void setup() {
Serial.begin(9600);
Serial.println("Starting StepperTest");
digitalWrite(ledPin, LOW);
delay(2000);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(directionPin, HIGH);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
delay(3000);
digitalWrite(directionPin, LOW);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
// delayMicroseconds(pulseWidthMicros); // probably not needed
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
void loop() {
}
It would confirm that activity was not some quirk unique to my setup and it would confirm that Arduino code did not have immediate, total control over A4988 and motor.
It would help me refine my approach to how I thought about programs. If there are things out of my control I might need to make allowances for them.
If You dig deeper in Arduino documentation You can find out what happens to the I/O pins from reset until execution starts. They might be put in tristate, with or without pullup etc. For jerk free starts the peripherals have to be selected/designed accordingly.