[ALMOST SOLVED] CNC Shield didn't work, A4988 alone didn't work, solved by connecting wrong(?) the wiring of the nema17

Based on a connection diagram that works and a code that works, I am now trying to connect 2 NEMA17s, but all I can get is this right-and-left movement.

I am suspecting the power supply (should suffice, though, 12V 2A) or the nema's, but ... I am sure is neither of these two.

What can be the problem?

This is the photo of the connections

https://freeimage.host/i/img-2367.UNXZhP

This is the video of the nema's

https://files.fm/f/qktqn9vmm

This is the code

const int DirPin_A = 4;
const int DirPin_B = 8;
const int StepPin_A = 2;
const int StepPin_B = 7;

void setup()
{
    pinMode(StepPin_A, OUTPUT);
    pinMode(StepPin_B, OUTPUT);
    pinMode(DirPin_A, OUTPUT);
    pinMode(DirPin_B, OUTPUT);

    digitalWrite(DirPin_A, HIGH);
    digitalWrite(DirPin_B, HIGH);
    digitalWrite(StepPin_A, LOW);
    digitalWrite(StepPin_B, LOW);

    Serial.begin(9600);
    Serial.println("GO");

    delay(1000);
}


void move_A(int n, int d)
{
    for (int x = 0; x < n; x++)
    {
        digitalWrite(StepPin_A, HIGH); // Enables the motor to move in clockwise direction
        delay(1);
        digitalWrite(StepPin_A, LOW); // Enables the motor to move in clockwise direction
        delay(d);
    }
}
void move_B(int n, int d)
{
    for (int x = 0; x < n; x++)
    {
        digitalWrite(StepPin_B, HIGH); // Enables the motor to move in clockwise direction
        delay(1);
        digitalWrite(StepPin_B, LOW); // Enables the motor to move in clockwise direction
        delay(d);
    }
}

void loop()
{
    Serial.println("-> A");
    move_A(1000, 10);
    Serial.println("-> B");
    move_B(1000, 10);
}

Hi,
What are you using for a power supply?

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

The setup in the photo looks right.

I tried your code with 2 of my steppers and it works as expected. One motor rotates about 1/3 of a turn then the other. I can't exactly match your setup as I have a CNC shield and DRV8825 drivers set to 16x microstep, but it should behave the same as your setup. Don't know what your trouble is.

Have you, properly, set the coil current limits on the stepper drivers?

Please post a link to the step motors, and state the value that you set for the current limit on the driver.

Right now I have the usb connected from the laptop to the arduino and a 12V 2A supply to the breadboard, I'll post the diagram in few minutes.

The arduino is a az-delivery clone https://www.amazon.es/gp/product/B074SB6PBW, the nema17 are these ones (17HD40005-22B) https://www.amazon.es/esfuerzo-torsi%C3%B3n-motores-impresora-conector/dp/B08HWGPQHH?th=1, and the drivers are regular A4988 ones (cannot find where I bought them).

The power supply is also a common one, I see model CY-1220, AC/DC with an output of DC12V-2A.

*I cannot measure the intensity of the driver, but just moving the intensity makes no change to the movement.

The motors are rated for 1.5 A/winding, but the A4988 driver can handle at most 1 A/winding, so set the current limit to less than 1 A.

You need a large capacitor close to the A4988 driver to dampened voltage spikes in the power supply leads (typically 100 - 470 uF).

Keep in mind that breadboards are for low power logic circuits and the tracks will burn when subjected to motor currents. Don't expect that setup to work for long!

You must properly adjust the coil current limit pot. You risk damage to the motors and/or the drivers by mindlessly twiddling the coil current limit. The motor 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. Set the coil current limit before connecting the motor.

How to find the Rsense resistors. Most Chinese clone boards are 0.1Ω (R100), but they could be 0.05Ω or 0.068Ω.
A4988 shunt resistors

Hi,
The steppers are 1.5A each and you have a 2A power supply.
2 x 1.5 = 3A

Tom... :smiley: :+1: :coffee: :australia:

It is not quite that simple. The stepper driver + motor act like a switching buck converter, so with a 24V power supply, the average current draw from the supply will be considerably less than the maximum motor current.

Thanks to all, it means a lot to me :pray:

So, first of all, a dumb question, I don't have a multimeter to measure the intensity (yet), but, the question is, the potentiometer of the A4988 is a loop, meaning that if I turn it left all the way I will reach the minimum and then start at the maximum again (without me knowing)? Or I can go all the way to the left and then move it to the right until I see it right?

Then, second question, can I use a 12V 5A and power the breadboard with that intensity? Or current in excess is not a good idea? It is not a good idea from what jremington says about the A4988 driver. But is there any other reason why this is a bad idea?

Third question, using motors of 0.4 A would be a good fix then?

About the capacitor and the breadboard, I understand than by using a cnc shield I would be good to go? This was my first attempt but I have tried to get it simpler by using this setup since nothing was working.

If you want your project to work, you really, really need to set the motor current properly. ALWAYS.

Buy a multimeter, follow the Pololu video linked above (post #7), and DON'T use a breadboard for the motor power or motor lead connections. Wire and solder those connections directly, or use screw terminals if provided.

I really like the CNC shield V3 for Uno. It will accept up to 4 A4988 or DRV8825 drivers, has inputs for limit switches and more. Makes interfacing and using steppers much easier and safer than a solderless breadboard or protoboard. They are available from Amazon and many other sellers.

image

Here is the pin mapping between the CNC shield and Uno so that you can do your own programming (the shield is meant to be used with Grbl firmware).

cnc shield Uno pins

Ok, now I am with a CNC shield.

I have the nema17s 17HS4401S datasheet with 1.7A phase current and a 17HD40005-22B datasheet with 1.3A rated current.

The A4988 drivers have a R10 label there, so this means that I should put in each driver
=1.7 *8 * 0.1 * 0.7 = 0.952
=1.3 *8 * 0.1 * 0.7 = 0.728

Real values with a multimeter are 0.98 and 0.77, respectively

The connections are much simpler, the only thing is that I have soldered the shield to the arduino to use the plug from arduino (see the photo below).

The code

#define EN 8 // pin 8 controls enable of all drivers on the CNC shield

//Direction pin
#define X_DIR 5
#define Y_DIR 6
#define Z_DIR 7

//Step pin
#define X_STP 2
#define Y_STP 3
#define Z_STP 4

void setup()
{
  pinMode(X_DIR, OUTPUT); pinMode(X_STP,OUTPUT);
  pinMode(Y_DIR, OUTPUT); pinMode(Y_STP,OUTPUT);
  pinMode(Z_DIR, OUTPUT); pinMode(Z_STP,OUTPUT);
  pinMode(EN, OUTPUT); 
  digitalWrite(EN,LOW);
}
void loop()
{
  digitalWrite(X_DIR, HIGH);
  for (int i = 0; i< 800; i++)
  {
    digitalWrite(X_STP, HIGH);
    delayMicroseconds(500);
    digitalWrite(X_STP, LOW);
    delayMicroseconds(500);
  }
  delay(1000);
  digitalWrite(Y_DIR, HIGH);
  for (int i = 0; i< 800; i++)
  {
    digitalWrite(Y_STP, HIGH);
    delayMicroseconds(500);
    digitalWrite(Y_STP, LOW);
    delayMicroseconds(500);
  }
delay(1000);
  
  }
  

And the results are that the nemas do noise, vibrate, then one of them starts turning fast while the other goes on, so everything very irregular and chaotic. I've kept changing the code to make sense of the movement but without luck. Also I have physically disconnected one of the nema's but nothing improves.

Are you even bothering to read the posts?

The A4988 drivers can handle only 1 Ampere per winding, maximum.

Get ONE motor working, before connecting two.

Hi there, yes, I have already said that connecting only 1 nema makes no difference.

Also, if both drivers have below 1A, doesn't that mean that I satisfy this condition?

Try it and see. The settings you described above will not work.

Ok, then I have taken a nema17 of 0.4A 17HS13-0404S datasheet

I've put on the driver the value of 0.29 (0.4 *8 * 0.1 * 0.7 = 0.224)

Only this nema connected, the nema makes noises, makes a small rotation to a side and to the other (like 1 microstep)

#define EN 8 // pin 8 controls enable of all drivers on the CNC shield

//Direction pin
#define X_DIR 5
#define Y_DIR 6
#define Z_DIR 7

//Step pin
#define X_STP 2
#define Y_STP 3
#define Z_STP 4

void setup()
{
  pinMode(X_DIR, OUTPUT); pinMode(X_STP,OUTPUT);
  pinMode(Y_DIR, OUTPUT); pinMode(Y_STP,OUTPUT);
  pinMode(Z_DIR, OUTPUT); pinMode(Z_STP,OUTPUT);
  pinMode(EN, OUTPUT); 
  digitalWrite(EN,LOW);
}
void loop()
{
  digitalWrite(X_DIR, HIGH);
  for (int i = 0; i< 8000; i++)
  {
    digitalWrite(X_STP, HIGH);
    delayMicroseconds(50);
    digitalWrite(X_STP, LOW);
    delayMicroseconds(50);
  }
  delay(1000);
  
//  digitalWrite(Y_DIR, HIGH);
//  for (int i = 0; i< 800; i++)
//  {
//    digitalWrite(Y_STP, HIGH);
//    delayMicroseconds(500);
//    digitalWrite(Y_STP, LOW);
//    delayMicroseconds(500);
//  }
//delay(1000);
  
  }

This is WAY, WAY too fast for the stepper to move. Try delay(1) (one millisecond) instead of 50 us.

I have been trying higher values without luck, with delay(1) I see that during the loop the rotor moves right and left 1 microstep for the 8000 iterations (at least it looks like it).

However, I have just seen that the ground 12v soldered cable is broken, I think it has broken now but I'm not sure. Now I'm making sure there is contact (manually) when the current is connected, but could this be the problem?

I'll fix it asap (don't have the tools here).

Start with full steps, with a delay(100) (that is, 5 or 10 steps/second) until you get the setup working.

Disconnecting the power or the motor leads while the setup is powered is one of the very fastest ways of destroying a motor driver.

All connections must be either securely soldered, or secured with screw terminals if provided.

Breadboards cannot handle motor currents -- the tracks will burn, destroying the motor driver.