Stepper Motor and A4988 Driver

Over the long weekend I decided to start hooking up stepper motors. The first step was to find some stepper drivers. I had four A4988 drivers sitting around and some old stepper motors. I found a datasheet with the pinout for the 16 pin board.

The motor is controlled by outputting a HIGH logic level to the STEP pin on the A4988. LOW stops the step of the motor. The direction is controlled by outputting a LOW or HIGH logic level to the DIR pin.

Windings on a stepper motor are in pairs. To find the pairs, I look at four wires and just connect two of them together. Then I spin the shaft of the motor. If the motor has much more resistance suddenly, I have found one of the pairs. Since only two wires are left, they are the other pair. These pairs can be assigned 1A/1B and 2B/2A.

Getting to this point is a challenge due to a set of bad drivers that were damaged on a board with a stray hot wire. So far, hooking up the A4988 and getting it to run with basic commands in Arduino C++ is not very difficult. Looking back, this is kind of amusing because I really didn’t have any idea how stepper motors worked or how to control them. It was sorcercry.

A larger challenge is waiting. Controlling the motor so that movement is smooth and timed properly. There is literally no software for controlling a 5/6 axis robotic arm with servo motor attachments, sensors, encoders, and limit switches. One major problem I have already identified with a smaller servo controlled robotic arm is jerk. The motor will quickly move and quickly stop. The arm would lurch and jerk to a stop.Even a gradual linear speed increase and decrease is subject to unstable starts and stops. I have an idea to use a curved acceleration and deceleration model. To test this I might have a stepper motor moving a glass of water at different speeds. The idea being that the water should remain stable and not have visible or mininimal disturbance.

This made me think about developing an algorithim to control the arm using time instead of speed to set movement after I solve smooth movement and a lot of angles for positioning. More on that later…

Latest build progress:

img_0103

The new TB6560 stepper driver(s) and they WORK!

img_01071

A quick code I wrote for testing the motor and driver.
/*  Todd Brown
*  Jan 18, 2017
*  Simple Stepper Test Code
*/

//Arduino Uno
const int stepPin=9;
const int dirPin=8;

// waiting variable sets speed
const int waiting=2;

void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {

digitalWrite(dirPin,HIGH); // HIGH sets a direction LOW sets reverse direction
// Makes 200 steos for one rotation
for(int i = 0; i < 200; i++) {
digitalWrite(stepPin,HIGH);
delay (waiting);
digitalWrite(stepPin,LOW);
delay (waiting);
}
delay(2000); // Two seconds delay

digitalWrite(dirPin,LOW); //Reverse and two rotations

for(int i = 0; i < 400; i++) {
digitalWrite(stepPin,HIGH);
delay (waiting);
digitalWrite(stepPin,LOW);
delay (waiting);
}
// 2 second delay for observation before change of direction
delay(2000);
}

 

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements