Correct use of an a4988

Hi.

As I'm brand new to the subject and I've come to a point with my project where I just don't know what to do next.

I'm trying to build a robot to solve a Rubik's Cube and since I'm probably the 1000th to do so, there seems to be an abundance of material. But I just can't find what I'm doing wrong.

I planed to use the following parts:

5x Nema 17 stepper 1.5A
5x a4988 driver
1x Arduino mega
1x 12V 10A Power Supply

I've used the following schematic as a guide:

I wired everything up and literally nothing worked.

would be great if someone could give me a few tips what you could screw up as a complete beginner. :wink:

Thanks in advance

what did you use there?

image

The first thing to do is to set the coil current limit on the A4988 stepper driver. The coil current should be found in the motor data sheet. Set the current to less than or equal to the spec current. To set the current limit you will need to know the value of the sense resistor on the A4988 driver board. Then enter the value of the resistor and the required coil current into the formula Vref = Imot x 8 x Rsen where Imot = the coil current and Rsen = the value of the sense resistor. The Pololu A4988 page covers how to set the Vref but you must use the sense resistor value on YOUR board. This page shows how to locate the sense resistor.

Then load and run this (slightly modified) simple stepper test code from Robin2's simple stepper code tutorial.

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

const byte directionPin = 5;  // **** change to suit
const byte stepPin = 2;       // **** change to suit
const byte enablePin = 8;     // **** change to suit
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 100; // milliseconds - or try 1000 for slower steps


void setup()
{

   Serial.begin(9600);
   Serial.println("Starting StepperTest");
   digitalWrite(ledPin, LOW);

   delay(500);

   pinMode(directionPin, OUTPUT);
   pinMode(stepPin, OUTPUT);
   pinMode(stepPin, OUTPUT);
   pinMode(enablePin, OUTPUT); 
   digitalWrite(enablePin, LOW);
   pinMode(ledPin, OUTPUT);


   digitalWrite(directionPin, HIGH);
   for (int n = 0; n < numberOfSteps; n++)
   {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
      digitalWrite(stepPin, LOW);

      delay(millisbetweenSteps);

      digitalWrite(ledPin, !digitalRead(ledPin));
   }

   delay(3000);

   digitalWrite(directionPin, LOW);
   for (int n = 0; n < numberOfSteps; n++)
   {
      digitalWrite(stepPin, HIGH);
      // delayMicroseconds(pulseWidthMicros); // probably not needed
      digitalWrite(stepPin, LOW);

      delay(millisbetweenSteps);

      digitalWrite(ledPin, !digitalRead(ledPin));
   }
}

void loop()
{
}

The motor should rotate 1/2 turn one way (200 step/revolution motor) wait 3 seconds and rotate 1/2 turn the other direction.

Robin2's stepper motor basics may also be of interest.

Capacitor 100uF 35V WH105°C

Thank you for the advice and Code. I already set the current of the a4988 and used basically the same Code. I haven't had any better results.

How secure are the motor to driver connections? If one disconnects the motor from the driver while the driver is powered there is a very good chance that the driver is destroyed. Just a momentary bad connection can do it.

When the motor is powered and the code is running, can you, easily, turn the motor shaft?

I tested it with more then one driver and the connection was tasted and secure. And yes, I can turn the motor shaft easily

Are you writing a low to the enable pin like in the simple test code?

Post your test code. Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post photos of your wiring.

int stepCounter;
int steps = 2000;
void setup() {
  pinMode(6, OUTPUT); // Enable
  pinMode(5, OUTPUT); // Step
  pinMode(4, OUTPUT); // Richtung
  digitalWrite(6, LOW);
}
void loop() {
  digitalWrite(4,HIGH); // im Uhrzeigersinn
  for(stepCounter = 0; stepCounter < steps; stepCounter++) {
    digitalWrite(5,HIGH);
    delayMicroseconds(500);
    digitalWrite(5,LOW);
    delayMicroseconds(500);
  }
  
  delay(1000);
  digitalWrite(4,LOW); // gegen den Uhrzeigersinn
  for(stepCounter = 0; stepCounter < steps; stepCounter++) {
    digitalWrite(5,HIGH);
    delayMicroseconds(500);
    digitalWrite(5,LOW);
    delayMicroseconds(500);
  }
  delay(1000);
}

Sorry I meant the power. is it the 12V 10A Power Supply or did you use that to power the Arduino through the Jack and took the 12V then on Vin ?

The code you posted works fine with my setup though I had to change pin numbers because my setup is hard wired (on a CNC shield).

Post photos of your wiring, please.


Sorry. Now the correct pictures (the others were old ones)

You have to connect 5V and ground from the Mega to the driver pins opposite to step and dir.

a4988 logic

I had them disconnected because I wanted to test if something is wrong with my Arduino. It doesn’t work even if I connect them like it is shown in the schematic.

yes it is the power supply

seems the GND is not connected ?

image

Breadboards are for low power logic circuitry and cannot handle typical motor currents. The tracks will burn, leading to unstable connections and destruction of the motor driver. NEVER change any wiring while the circuit is powered.

You really need to solder motor leads directly to the motor driver, or use secure screw terminals if provided.

Thank you for the advice!
I know that a Breadboard is not the ideal for it. I wanted to try it out before soldering it. And that probably isn't a valid point, but a lot of people used them like that.
Is there a way to test the system without the need to solder everything in?

Thank you

I am not sure, but I think I answered it already.

Not safely with high current circuits like steppers.

Soldering is easily reversible, and if you intend to continue in this hobby, it is something you should learn to do. There are excellent tutorials on line at Adafruit and Sparkfun, etc.