5921Views5Replies

# Problem driving a stepper motor using the A4988 reprap driver board and an Arduino? Answered

Hi guys

I am having a problem driving a stepper motor using the A4988 reprap driver board and an Arduino
I have set up the wiring using an example I found online (Diagram attached: A4988 wiring) https://www.youtube.com/watch?v=5CmjB4WF5XA.. However the motor does not seem to turn.

The motor I am using is from an old Hitachi printer which I took apart a while back. Printed on it is 0.9A/ph. It has six wires however I am using it as a bipolar stepper by just leaving the center tap of each winding unconnected.

I have adjusted the VREF on the A4988 board to insure that the current is limited bellow the 0.9A. To do this I used the data sheet of the A4988. As I wanted to run the motor at full step mode, the A4988 data sheet specifies that the winding current could only reach 70 percent of the current limit.

consequently:
Current limit = 0.9 * 0.7 = 0.63A

Current limit = Vref * 2, Therefor Vref = 0.63/2 = 0.315V or 315mV

I have therefor set the current limit using the potentiometer on the A4988 to aprox 315mV

Once the wiring was set up, I applied power and measured the Vref to confirm it is still the same and it was.

Next I disconnected the Power to both the Arduino and the driver and connected in the stepper motor. I then connected the power and uploaded the following code:

// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;

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 < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(5000); // five second delay

digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(5000);
}

Nothing happened... started off with 5 volts on the power supply and ramped it up to aprox 12vs however still nothing happened. I can feel the heat sink heating up on the A4988 which means power was reaching it. I measured the voltages from the Arduino to the A4988 and the power supply to the driver and the voltages matched the input. I started shaking about the power connections to and suddenly the motor made one step, but that was it. So i thought it was a problem with the breadboard. I checked the connections on the breadboard and all where connected. To be safe i decided to use another breadbord. Again nothing happened. I checked the Aarduino using the 28byj48 and UNL203 driver and stepper that came with it and they worked fine. I confirmed the wiring sequences and layout multiple times and they all matched the tutorial I followed.

My inital thinking was that the stepper motor was broken, so i disconnected it and tried running it using the power supple (5V) by connecting and disconnecting each coil in manually one by one, and it turned one step at a time, which meant that the stepper was working. Finally i decided to see if current was reaching the stepper, I therefore connected the Altimeter in series with one of the coils and it did not read any current, which meant that current was not reaching the coils.

Now I am unsure what to do, or what has gone wrong. The vref still reads aprox 310 - 320 mV, this makes me assume that driver is not fried. I do have another A4988 driver however I started working on that one and now the Vref does not go above 62mV so I'm guessing that it is burnt, however the second one reads fine.

I have tried using the enable button with the following code (Attached; A4988 wiring 2) however it still didnt' make in difference. The following code is what i used for when I set the enabled to low (Note that the pin numbers have been changed)

int Index;

void setup()
{
pinMode(4, OUTPUT); //Enable
pinMode(2, OUTPUT); //Step
pinMode(3, OUTPUT); //Direction

digitalWrite(4,LOW);
}

void loop()
{
digitalWrite(3,HIGH);

for(Index = 0; Index < 2000; Index++)
{
digitalWrite(2,HIGH);
delayMicroseconds(500);
digitalWrite(2,LOW);
delayMicroseconds(500);
}
delay(1000);

digitalWrite(3,LOW);

for(Index = 0; Index < 2000; Index++)
{
digitalWrite(2,HIGH);
delayMicroseconds(500);
digitalWrite(2,LOW);
delayMicroseconds(500);
}
delay(1000);
}

Why did the motors initially step (only one step upon each shake) when I shook the power supply leads? I am afraid to try that again as I think this is what damaged the first driver I was using. And why is there no current reaching the coils?

I would really appreciate an opinion on this issue as I have no idea what to do

Many thanks for you time.

Tags:

The forums are retiring in 2021 and are now closed for new topics and comments.

From the Arduino Playground:

//simple A4988 connection
//jumper reset and sleep together
//connect VDD to Arduino 3.3v or 5v
//connect GND to Arduino GND (GND near VDD)
//connect 1A and 1B to stepper coil 1
//connect 2A and 2B to stepper coil 2
//connect VMOT to power source (9v battery + term)
//connect GRD to power source (9v battery - term)
int stp = 13; //connect pin 13 to step
int dir = 12; // connect pin 12 to dir
int a = 0; // gen counter
void setup()
{
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
}
void loop()
{
if (a < 200) //sweep 200 step in dir 1
{
a++;
digitalWrite(stp, HIGH);
delay(10);
digitalWrite(stp, LOW);
delay(10);
}
else
{
digitalWrite(dir, HIGH);
a++;
digitalWrite(stp, HIGH);
delay(10);
digitalWrite(stp, LOW);
delay(10);

if (a>400) //sweep 200 in dir 2
{
a = 0;
digitalWrite(dir, LOW);
}
}
}

Sorry the tabs for the formatting did not survive the pasting.
This code definately works.
Also interesting the current regulation that is badly designed on some driver boards:

http://reprap.org/wiki/Pololu_stepper_driver_board

Another intersting read for the beginner:

http://www.lucidtronix.com/tutorials/24

Firstly, a very very well crafted question, we don't see that often !

Personally I would definitely GROUND /Sleep and /reset, if I'm not using them. Also I don't leave pins floating, like MS1,MS2 and MS3. Either tie them high or low, but don't leave them to float.

If you haven't a scope to watch the signals in step and dir, try measuring DC volts on STEP, and you should see it change as you change the motor speed.

I like a significantly bigger cap than 47uF on the input to the board, say 470 or even 1000uF would be good.

I agree with, inputs should not be left floating..

If I had a Sleep input and wanted not to Sleep it would be set low.

This is a Not_Sleep so by that thinking it should be set high !

Can we agree ?

Oops. Yes. You're right ! its late....

Reverse my previous comment, tie /reset and /sleep HIGH

I think your not_sleep and not_reset need VDD