I followed this excellent tutorial on how to set the current limit on the A4988 driver:
I connected the driver to my Arduino Uno R3 board per the minimum connection diagram on the A4988 page, including the 100 uF cap (16V) across the motor inputs. I’m using the same 12VDC regulated power supply for the motors as for the Uno (the 12VDC is connected to the Uno via the Vin pin).
After setting the current limiting pot to roughly 38mA (using the formula on the A4988 page with 100mA I get 40mV but I want to go slightly lower if it means the board will be cooler and use less power) I loaded the sketch from the same tutorial link above to the Uno and connected my 20M020D2B Portescap bipolar motor (12V operating voltage, 100mA rated current per phase) with the red/gray wires connected to 1A/1B and the yellow/black wires connected to 2A/2B. While the motor appears to behave according to the sketch, I see that when I first plug in the power the motor spins wildly in both directions before settling down - is this expected? In the video from the tutorial the motors don’t do that and for my project it’s vital that the motor just does what the code says it should do.
Am I doing something wrong? I’ve uploaded a YouTube video to show what’s happening: https://youtu.be/k8RYxDdxBFY
Post the code, using code tags.
/* Simple step test for Pololu stepper motor driver carriers
This code can be used with the A4988, DRV8825, DRV8824, and
DRV8834 Pololu stepper motor driver carriers. It sends a pulse
every 500 ms to the STEP pin of a stepper motor driver that is
connected to pin 2 and changes the direction of the stepper motor
every 50 steps by toggling pin 3. */
#define STEP_PIN 2
#define DIR_PIN 3
dirHigh = true;
For Portescap 20M020D2B steppers (bipolar, 12V operating voltage, 100mA rated current per phase):
DIR = LOW > CCW (Looking from above)
DIR = HIGH > CW
Red wire > 1A
Gray wire > 1B
Yellow wire > 2A
Black wire > 2B
// Toggle the DIR pin to change direction.
dirHigh = false;
dirHigh = true;
// Step the motor 50 times before changing direction again.
for(int i = 0; i < 50; i++)
// Trigger the motor to take one step.
The code looks OK. I suspect bad connections. Have you soldered the pins into the motor driver board and reseated all breadboard connections?
Also, breadboards are not good for high currents, so you should solder the motor leads to the motor driver.
[quote=“Jim Remington”]The code looks OK. I suspect bad connections. Have you soldered the pins into the motor driver board and reseated all breadboard connections?
Also, breadboards are not good for high currents, so you should solder the motor leads to the motor driver.[/quote]
Thanks for the quick reply, Jim. I’ve soldered pin headers to the driver board for use in my breadboard, but for the motor wires I’m just inserting them into the breadboard while I test it out.
I’ll try reseating everything.
EDIT: reseated all connections and still the same behaviour. Could it be that I need a bigger voltage cap? I’m using a 100uF 16V electrolytic.
This is not normal behavior and strongly suggestions intermittent connections. I would double check, and even resolder especially the STEP and DIR pin connections.
Another possibility is that the power supply is noisy. Try powering the Arduino separately, connecting all the grounds together.
Maybe this isn’t so uncommon - more googling and I found some recommendations to add 10k pull-up resistors to the STEP & DIR lines (resistors connected to +5V and the corresponding pin on the A4988) and that seems to work - the stepper at most turns one step CW before executing the code. That’s acceptable.
What’s interesting, though, is while the connections remain the same (and the code) it now starts moving CW rather than CCW as it did yesterday, with or without the pull-ups.
Come to think of it, I’ll bet the erratic behavior was during program uploading. Most pins are defined as input during that time and are essentially open circuits. That would explain why the pullups worked.
Behavior of external circuitry during uploads can be erratic and should be discounted.