I'm trying to control a NEMA 17 stepper motor with my UNO, and I am using an A4988 driver to do so. The motor will step about half as much as I would expect to when it kinda works with one motor that turns at 400 steps/rev, and it will also step the wrong direction towards the end of the loop. With another motor I have that turns at 200 steps/rev, it only takes a few steps initially before dying. With both motors, the amount of noise will decrease the longer the UNO is plugged in until they both go silent after about 20 seconds. There's a decrease in torque associated with this decrease in noise.
I'm currently pulling 12V from the Vin pin to power the motor, and there's a 68 micro Farad capacitor between the 12V input and ground. I also tried powering it with a 240W 24V power supply I have. I've tried two different drivers and widely varied the delay constant I'm using for steps only to get similar results.
Below is my arduino code:
const int stepPin = 2;
const int dirPin = 5;
const int del = 500;
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
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(del);
digitalWrite(stepPin,LOW);
delayMicroseconds(del);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(del);
digitalWrite(stepPin,LOW);
delayMicroseconds(del);
}
delay(1000);
}
Since changing out the drivers and motors didn't seem to make a huge difference, I'm afraid my board may be bad in some way. Has anyone else had similar issues? Does anyone have any advice?
It makes life much easier if all the "speed" is in one place.
If that does not help then please make a pencil drawing showing how everything is connected and post a photo of the drawing. Please note that Fritzing diagram and photos of your hardware are usually useless for showing wiring connections clearly.
Have you set the A4988 current correctly for your motor (s)? You can set the current a little lower than nominal to reduce heat issues.
The 24V supply is the one to use. Higher voltage will give faster max speed.
68uF is nothing for a motor. 4700uF might make a difference though.
A4988's probably need active cooling with a fan if using higher range of current (1A and above),
or they will thermally cut out
You need to ramp the step rate, motors cannot respond to an instantaneous change in step rate,
so use the AccelStepper library and experiment to find the max step rate and max acceleration for
your motor/load combination. Use microstepping(*) if the motor has no load or you'll get bad resonance
issues (you can get bad resonance with a load when full-stepping, but you certainly will with no load).
I plugged in the 24V supply and couldn't get the motor to even turn. I double checked all of my connections with no luck. I tried using the Vin pin again afterwards, and I was able to at least get some noise of of the motor but no rotation.
I had set the potentiometer on the driver to the correct voltage in earlier testing and remeasured it again to make sure it was at a good value. I changed my code to decrease the delay in between the high and low outputs from the arduino and included an LED blink to verify that it was running.
The specific motor I am using is model 42BYGHM809 from the link I previously posted. I'll post a wiring diagram in a little bit.
const int stepPin = 2;
const int dirPin = 5;
const int del = 10;
int led = 13;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(led, 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);
digitalWrite(led, HIGH);
delayMicroseconds(del);
digitalWrite(stepPin,LOW);
delayMicroseconds(2*del);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
digitalWrite(led, HIGH);
delayMicroseconds(del);
digitalWrite(stepPin,LOW);
delayMicroseconds(2*del);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
delay(1000);
}
The Pololu A4988 web page has a good wiring diagram.
I think you misunderstood my code suggestion. You cannot expect the motor to move with a step interval as short as 20 microseconds.
I was trying to differentiate between the necessary duration of the pulse (10 µsecs) and the step interval which bears no relationship to the pulse duration. Look at my code examples.
Start with a step interval of 200 millisecs. If that works, then experiment with shorter intervals to see what max can be achieved.
For high maximum speeds you may need to accelerate from stationary - but leave that for later.
I finally got the motor working after I connected the sleep and reset pins as some tutorials suggest. I didn't do anything with them in the past since I thought they were unnecessary.
Read the datasheet, you should never assume anything - read the docs, double check your connections, only
then apply power. Over eagerness to power something up will lead to expensive mistakes.