// defines pins numbers
const int stepPin = 4;
const int dirPin = 5;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
}
But I find so many issues!
-The power supply gets shortcuted every second
-The motor, at microcontoller restart, shortly turns many times in both directions, before starting with the full cycle turns every second.
-Sometimes it juts gets locked, and won't turn every second
-The turning direction changes every time I restart the microcontroller
Start off with a simple test using the AccelStepper library with modest acceleration and speed settings first,
you certainly cannot expect a motor to go from stationary to 1000 steps/sec immediately, it will simply stall/miss-step as motors obey the laws of physics, not impossible demands.
You should add a physical pull-down resistor (1k to 10k range) to pin 4 so that the stepper behaves
during power-up and reset.
Thanks for your answers guys. Well, even though I still cannot see how from my code I should tell the motor to move 1000 times per second, I started to troubleshoot by uploading Robin2's basic stepper code from his stepper basics thread (really helpful).
Well it did not work either! I started thinking that my bench power supply would be the problem, so I used a laptop converter at 19V.
It did not work.
But by accident when trying to read the voltage at the current limitor on the A4988, it worked! Simply by shortcutting GND and the current limitor I got the codes working. I do not know what this is due to. But I've ordered a new driver and I'll try again
ivino:
Thanks for your answers guys. Well, even though I still cannot see how from my code I should tell the motor to move 1000 times per second, I started to troubleshoot by uploading Robin2's basic stepper code from his stepper basics thread (really helpful).
Thank you for your kind words.
In my examples I have a variable to hold the value of the interval between steps. That is what determines the motor speed.
I don't know what you mean by " shortcutting GND and the current limitor"
Each of those delayMicrosecond functions wait for 1/2 millisecond. Total time for a cycle = 1 millisecond, result is 1000 pulses (steps) per second.
I see now Groundfungus Thanks.
And Robin2, by
" shortcutting GND and the current limitor"
I mean stablishing galvanic connection between the screw on the A4988 board where the current is adjusted and the A4988 GND pin. That really something I have not seen on any tutorial.
ivino:
And Robin2, by I mean stablishing galvanic connection between"
Is that what I would describe as "soldering a wire between"?
If so, it is certainly not something I ever contemplated. Have you studied the schematic for the A4988 board to figure out the effect of such a connection?