New A4988 and erratic stepper motor movement

OK, after searching for everything posted about the A4988 and reading for over 5 hours now, pooring over the FAQ’s on Pololu’s website, numerous Google searches and the datasheets for the A4988, I still cannot find the fix for my stepper not responding correctly. It’s just basically twitching erratically when powered up.

Yesterday it was semi working OK, but changing the delay after the “digitalWrite(stepPin, HIGH)” in the code below did nothing to change the rate of rotation. But when the values for “j” on the Serial Monitor window were below 10, it would rotate faster. Now I cannot get it to do anything but twitch erractically. I have been careful not to make or break connections with the power applied.

-I’m using an Anaheim Automation 8 wire bi-polar stepper that the sticker says is 1A/Phase
-Seeeduino Mega (ATMega1280 chip with Arduino interface) (I’ll just call it an Arduino for future reference)
-Pololu A4988 driver
-30V / 5A variable power supply

-I have the 5v input to power the A4988 hooked up to the Adruino and ground as well
-I’ve tried 8 to 28v into the Vmot with the cooresponding ground from the power supply hooked up
-SLEEP and RESET are jumped together, I’m reading 4.75v on these
-There’s nothing hooked up to the MS1, MS2 and MS3 so I should be running in full step mode

-I have adjusted the Ref voltage to .597v (initially) and then down to .37v with no change. This was measured from the Ref pin to the common Arduino/A4988 ground.

I have the motor hooked up in series configuration per the FAQ page diagram with the appropriate wires tied together, and this cooresponds with the connections given by the motor datasheet located here: http://www.anaheimautomation.com/manuals/stepper/L010164%20-%2023Y%20Series%20Spec%20Sheet.pdf
Note: I tried parallel as well with no change, I’m still working with it hooked up in series.

ENABLE, DIR and STEP are hooked up to the Arduino and I’m trying to use the following to get this sucker to run right…

#define stepPin 7
#define dirPin 6
#define enablePin 8

void setup()
{
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
Serial.begin(9600);
Serial.println("Starting stepper exerciser.");
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
int j;
digitalWrite(enablePin, LOW);
delayMicroseconds(2);
digitalWrite(dirPin, HIGH);
for(j=0; j<=250; j++) 
{
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
Serial.println(j);
}
for(j>250; j<=500; j++) 
{
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
Serial.println(j);
}
}

Not sure if there’s enough detail to help, but here’s the settup:

Thanks in advance for any help!

Hi,

Your setup mostly looks okay. Can you try changing your low pulse width to be longer than 2 microseconds? You are pretty close to the minimum width of the low pulse (1 microsecond). If that doesn’t help, can you try reducing your pulses per second? Try something like no more than 100 pulses per second to start. Can you draw a schematic or say all the wiring connections you’ve made?

- Ryan

-Arduino Pin 6 to A4988 DIR
-Arduino Pin 7 to A4988 STEP
-Arduino Pin 8 to A4988 ENABLE

-Stepper motor lead A to A4988 Pin 1A
-Stepper motor lead /A to A4988 Pin 1B
-Stepper motor lead B to A4988 Pin 2A
-Stepper motor lead /B to A4988 Pin 2B
-The other leads are appropriately tied together on the far part of the breadboard in the picture above per the FAQ page instructions and these correspond with the datasheet wiring config for the motor in series.

-Motor Power in from the power supply going to Vmot and gnd right below Vmot (input is kept at >8v)
-5v and ground from the arduino to the Vdd and gnd pins on the same side as the stepper motor out pins on A4988

-SLEEP and RESET are jumper’d together

I will try and extend the timing in the program as suggested and see if I get any change or results later this afternoon/evening and post back.

Thanks for your reply!

Your connections sound good. The connection between sleep and reset is unnecessary (though not problematic) on the board with voltage regulators. Just to confirm, you are not jumpering either of the voltage regulator outputs to Vdd, right?

- Ryan

I missed that it looks like you have your motor connections wrong. On the A4988, one coil is 1A to 1B and one coil is 2B to 2A.

- Ryan

Yes sir, you are correct, I mistyped it. That is the way the motor is hooked up and I ammended the post to reflect correctly. :blush:

To answer your question, no, the VDD is not jumper’d to the either regulated output.

For an update, as you requested, I changed the delay to 10 and then 100 and then 1000 microseconds after turning the stepPin low in both directions and changed the delay after turning the stepPin high to 2000 microseconds and no change in motor behavior.

I also got ahold of another bipolar stepper to try and got the same results.

So, what is next for me to try?

Here is the updated code. Note, the ENABLE was moved to pin 5.

#define stepPin 7
#define dirPin 6
#define enablePin 5

void setup()
{
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
Serial.begin(9600);
Serial.println("Starting stepper exerciser.");
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
int j;
digitalWrite(enablePin, LOW);
delayMicroseconds(1000);
digitalWrite(dirPin, HIGH);
for(j=0; j<=250; j++) 
{
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
Serial.println(j);
}
for(j>250; j<=500; j++) 
{
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
Serial.println(j);
}
}

Here is a pic of the same settup cleaned up so it should be easier to follow.

Hello.

Have you tried verifying with a multimeter or some LEDs (with appropriate current-limiting resistors) that the driver outputs are at least following the expected sequence when the stepper motor is disconnected? Right now it’s hard to tell if the problem is with the driver, your connections, or your motor.

- Ben

I have not yet, I will tonight or tomorrow put some LEDs in and slow the sequence down enough to verify that it is firing in an expected order. More to come…

Thanks.

Hooked up LEDs to the 4 motor connections, code and video below. This is 3 loops through from 0 to 10 as displayed on the Serial Monitor Window and mentioned in the exciting video.

Just FYI, there is a different color for each lead:
Pin 1B (/A) is RED
Pin 1A (A) is White
Pin 2A (B) is Blue
Pin 2B (/B) is Green

http://youtu.be/5-g8DgFsdM8

And the code used for this is as follows

#define enablePin 5
#define stepPin 6
#define dirPin 7

void setup() {
  // set the digital pin as output:
 
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);

Serial.begin(9600);
Serial.println("Starting Stepper Exerciser.");

pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);


}

void loop()
{

   int j;
   digitalWrite(enablePin, LOW);
   delay(10);
   digitalWrite(dirPin, HIGH);
  
   for(j=0; j<=10; j++)
   {
     digitalWrite(stepPin, LOW);
     delay(750);
     digitalWrite(stepPin, HIGH);
     delay(1500);
     Serial.println(j);
   }
    /*for(j>5; j<=10; j++)
   {
     digitalWrite(dirPin, LOW);
     digitalWrite(stepPin, LOW);
     delay(750);
     digitalWrite(stepPin, HIGH);
     delay(1500);
     Serial.println(j);
   }*/
  
  }

I’m far from an expert, but this doesn’t look right according to the sequencing I could find online.

That is definitely wrong. You should only see the LED states change when you step; the video makes it look like you are stepping much faster than the code would indicate. Please double-check that your connections really are what you think they are (5 -> enable, 6 -> step, 7 -> dir, Arduino ground -> driver ground, etc), and then try a program that doesn’t step (or, even better, only steps when you push a button). If you are holding everything constant, and everything is connected properly, you should see one LED solidly on and all others off, assuming all of your LEDs are connected properly in a circuit that goes from the driver output to ground. Then, when you push the button to make it take one step, you should see the lit LED turn off and a different LED turn solidly on.

Can you tell me what value resistors you used in series with your LEDs? Also, I can’t tell from the video: did the white LED ever turn on? You don’t happen to have access to an oscilloscope, do you?

- Ben

I probly could get access to an O’scope in the next couple days, but my knowledge and experience with one of them is very minimal.

The grounds for the LEDs are all tied together and then to the Arduino ground port next to the one grounding the A4988. The white LED does turning on, usually very dim, but if the sequence/program is allowed to run for an extended period of time it will eventually come on brightly.

The resistors are all 510 Ohm

Varying the voltage from the power supply from 10 to 13 volts made significant amounts of difference in the rate and whether or not the flashing sequences changed. When you saw the video it was running on 13v and .3A from the power supply.

I will try and get a switch in there, I ordered another Driver board to drop in place of this one, as I am thinking something is wrong with it.

OK, got some more troubleshooting in. Worked in a switch to step it one step at a time and the LEDs don’t change. 2B is on constant and when I hit the switch 1B comes on dimly until the switch is released and in the meantime, 2A is on really dim as well. Following are pictures of the settup and the code used with the switch connected to pin 13

In the following picture, the arrows that are white around the outside and black in the middle are all common ground to the arduino/A4988.

The White/Blue arrow is the line between pin 5 and ENABLE
The White/Green arrow is between pin 6 and STEP
The White/Yellow arrow is between pin 7 and DIR

The 5v in from the Arduino is labeled as are the LEDs, their colors and the motor output pins they are connected to.
Just to clearify, the Black wire is 1A
the Yellow wire is 1B
the Blue wire is 2A and
the Green wire is 2B

the switch is to turn the 5v from the arduino to the A4988 off is all. The serial monitor window verifies when the switch is pressed and that the “j” counter increases each time.

following the labeled picture is a closer one of the A4988 just for gee whiz.

#define enablePin 5
#define stepPin 6
#define dirPin 7
const int buttonPin = 13;
int buttonState = 0; // variable for reading button status
int j;


void setup() {
  // set the digital pin as output:

pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);

pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);

Serial.begin(9600);
Serial.println("Starting Stepper Exerciser.");

pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);


}

void loop()
{
   buttonState = digitalRead(buttonPin);

   if (buttonState == HIGH)
	{
	digitalWrite(enablePin, LOW);
	Serial.println("Button Pressed");
	digitalWrite(stepPin, LOW);
        delay(500);
        digitalWrite(stepPin, HIGH);
        delay(1000);
      	Serial.println(j);
	j++;
		if (j > 4)
		{j=1;} //this keeps count of series of 4 puches representing steps
   	}
    else
	{
	digitalWrite(enablePin, HIGH);
	}
  
  }

so I tried is again, without the else statement and now 2B and 1A are the ones staying on then they start flashingon and off at the same time with no change from the switch input…

so does this seem legit, other than the fact that the board does not seem to be stepping the motor?

Well, after posting that and thinking about it, I figured that I ought to control each coil energizing instead of series of 2. I amended the code as follows so that one click of the button would only advance 1 step. No change though, it’s still not responding and acting as stated above.

#define enablePin 5
#define stepPin 6
#define dirPin 7
const int buttonPin = 12;
int buttonState; // variable for reading the pushbutton status
int j;
int i;

void setup()
{
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, HIGH);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

  Serial.begin(9600);
  Serial.println("Starting Stepper Exerciser.");

  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  digitalWrite(dirPin, HIGH);
}

void loop()
{
 buttonState = digitalRead(buttonPin);
     if (buttonState && i<=1)
    {
     delay(15);
     digitalWrite(enablePin, LOW);
      
     Serial.println("Button Pressed");
     digitalWrite(stepPin, LOW);
     delay(250);
     i=2;
     Serial.println("i ");
     Serial.println(i);
    }  
   else if (buttonState && i>1)
         {
          delay(15);
          digitalWrite(enablePin, LOW);
          Serial.println("Button Pressed Again");
          digitalWrite(stepPin, HIGH);
          delay(250);
          i=1;
          Serial.println("i2 ");
          Serial.println(i);
      
          Serial.println("j ");
          Serial.println(j);
          j++;
             if (j > 4)
              {j = 1;}
    }     
  }

I won’t have time to look over your pictures or code closely until tomorrow, but you seem to be getting inconsistent results that make this sound more like a software or connection problem than a driver problem. Can you post a high-res, close-up, in-focus picture of the solder joints between the header pins and the motor driver?

- Ben

hows this?

A little more resolution would have allowed me to see the solder joints better (you can just attach pictures directly to your forum post rather than using an image hosting site that is probably resizing them), but the joints look pretty good as far as I can tell.

I can’t tell if you are using a pull-up or pull-down resistor to give your switch a default value in the NC state. I also can’t see your pictures clearly enough to really trace which wires are going where, so it’s hard to determine if there is a problem there.

Ultimately, it might be best to just wait for your replacement driver to arrive to see if the problems go away. However, if you want to keep trying to test your current driver, I think you should simplify things down further.

  1. Connect one side of your switch to ground and the other to pin 12, and use the Arduino’s internal pull-up to give it a default high NC state. Then simplify your code to:
#define enablePin 5
#define stepPin 6
#define dirPin 7
#define buttonPin 12

void setup()
{
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);  // enable internal pull-up 

  pinMode(stepPin, OUTPUT);
  digitalWrite(stepPin, LOW);
  pinMode(dirPin, OUTPUT);
  digitalWrite(dirPin, LOW);
}

void loop()
{
  while (digitalRead(buttonPin));  // wait here while button is not pressed
  delay(10);  // debounce button press
  while (!digitalRead(buttonPin));  // wait here while button is pressed
  
  digitalWrite(stepPin, HIGH);
  delay(10);
  digitalWrite(stepPin, LOW);
}

Now every every time you push and release the button, the Arduino will generate a single 10 ms high pulse on the step pin, advancing the driver by one step. What happens if you run this code without pushing the button at all? What changes whenever you push and release the button?

  1. Remove the Arduino from the system entirely and see if you get a different result. You can use the onboard 5V regulator to power the logic, and jumper wires to set the approriate states for the enable, reset, and sleep pins. You can jumper the dir pin to ground, put a pull-up resistor on the step pin, and then manually step the driver outputs by tapping a grounded wire to the step pin. Note that because the wire will probably physically bounce when you touch it to the pin, you will probably trigger multiple steps with each tap, but this test could still help you determine if your problems are related to the Arduino or your connections between the Arduino and your driver.

- Ben

Well, I’d upload the pictures directly, but the forum keeps telling me they are invalid. It won’t accept .JPG?

Anyway, I’ll try your other suggestions with the button code and such tonight and report my findings.

Thanks for your time and assistance.

With no push of the button, Pin 2B was on bright with 1B on dim for about 2 seconds, then 1B and 2B are bright, then flashing off with 2A coming on dim then back to 2B and 1B bright then 2A on dim when they go off and back and forth every 1/2 second or so…

Pushing the button changes nothing from above…

Doing this I am getting nothing. There is power to the board, I verified that, but none of the LEDs are turning on.

It should work with .JPG. The attachment file size limit is 1 megabyte. Is your picture larger than that?

- Ryan

Yes, that must be the problem, you wanted high res, they are over 2mb each! So, the new board should be delivered whenever USPS drops by… I’ll post up what I discover later on today.

Thanks again for your time and assistance up to this point.

Here’s a better pic of the solder joints… never mind, got the pic under 1mb and now I get “Sorry, the board attachment quota has been reached.”