CNC shield with A4988 and MEGA 2560

I am using AccelStepper library but my steppers are not working. Seem like trying to change the step but don't have enough power. I hear the step noise with a frequency like 2-3/second but the best case is when is doing 2 or 3 chaotic steps forward and the same back. I am using A4988 with CNC shield on Arduino Mega2560. I have two NEMA 17 and one NEMA 23 connected. The rated current is 1.68A and 2A. The NEMA 23 I connected in parallel to Y and A axes. I set the current in the beginning. I tested putting it to maximum. I am using full step. Please advise until I break it all!

// Define some steppers and the pins they will use
AccelStepper stepper1(AccelStepper::FULL2WIRE, 2, 5);
AccelStepper stepper2(AccelStepper::FULL2WIRE, 3, 6);
AccelStepper stepper3(AccelStepper::FULL2WIRE, 4, 7);
//////////////////
void setup() {
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(1000000);

stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(1000000);

stepper3.setMaxSpeed(1000.0);
stepper3.setAcceleration(100.0);
stepper3.moveTo(1000000);
}
/////////////
void loop() {
stepper1.run();
stepper1.setSpeed(100);
stepper1.runSpeedToPosition();
stepper2.run();
stepper2.setSpeed(100);
stepper2.runSpeedToPosition();
stepper3.run();
stepper3.setSpeed(100);
stepper3.runSpeedToPosition();
}

Which CNC shield ? (pic needed)

If it is the standard V3 then BEWARE that the pin assignments are different to its usage on a UNO !

Also reduce the VREF rating as running at max can also cause the drivers to pop without heatsinks and additional cooling !

Also mixing stepper sizes on the same driver may not be the best idea.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

As well as a potential power problem (what are the specs of the power supply?):

AccelStepper stepper1(AccelStepper::FULL2WIRE, 2, 5);

The constructor for AccelStepper with A4988 drivers is:

AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);

From the AccelStepper reference:

[in] interface Number of pins to interface to. Integer values are supported, but it is preferred to use the MotorInterfaceType symbolic names. AccelStepper::DRIVER (1) means a stepper driver (with Step and Direction pins).

Many of those CNC shields have the stepper enable pin tied HIGH, disabling the steppers by default. Pin 8 is the enable pin for the steppers so set it as pinMode OUTPUT in setup() and digitalWrite it LOW to enable the steppers.

Robin2's stepper basics may be of interest.

And his simple stepper code is good for testing.

Thank you gentlemen, you are most helpful!
I managed to move the steppers with a code quite simple, without libraries. Now my problem is that this three steppers are just accessories of my droid. When I put the stepper control code in the main sketch doesn't work anymore. The main sketch includes DC motors UART connected, 6 axes accelerometer I2C connected, temperature sensor Analog connected, Anakin Andee control board. The stepper control code has a loop which I would expect to repeat itself until the movement is done, but somehow something wrong is happening. Indeed the drivers seem like going quite hot. I have heat sinks and I will add active cooling when the MOSFET transistor for control will be supplied.I will put the cooler now directly connected.

Stepper_shield_test_2-200712a.zip (886 Bytes)

Not many members will download a zip file. Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code. If the code is too long to post you may attach it. Better yet, provide a minimal verifiable sketch that demonstrates the problem.

A schematic is always welcome. In this case a picture actually is worth a thousand words.

Post images in line so we don't have to download them.
Posting images
How to post an image.
Another page on posting images.

This is working stand alone but still don't work included in a much bigger sketch. 700mV for the current control. I have heatseanks and active cooling.

// Define some steppers and the pins the will use

define EN 8 // stepper motor enable , active low

define X_DIR 5 // X -axis stepper motor direction control

define Y_DIR 6 // y -axis stepper motor direction control

define Z_DIR 7 // z axis stepper motor direction control

define X_STP 2 // x -axis stepper control

define Y_STP 3 // y -axis stepper control

define Z_STP 4 // z -axis stepper control

// Function : step . function: to control the direction of the stepper motor , the number of steps .
// Parameters : dir direction control , dirPin corresponding stepper motor DIR pin , stepperPin corresponding stepper motor " step " pin , Step number of step of no return value.
void stepX (boolean dir, byte dirPin, byte stepperPin, int steps, int steplength)
{
digitalWrite (dirPin, dir);
delay (500);
for (int i = 0; i <steps; i++)
{
digitalWrite (stepperPin, HIGH);
delayMicroseconds (steplength);
digitalWrite (stepperPin, LOW);
delayMicroseconds (800);
}}

void stepY (boolean dir, byte dirPin, byte stepperPin, int steps, int steplength)
{
digitalWrite (dirPin, dir);
delay (1000);
for (int j = 0; j <steps; j++)
{
digitalWrite (stepperPin, HIGH);
delayMicroseconds (steplength);
digitalWrite (stepperPin, LOW);
delayMicroseconds (2000);
}}

void stepZ (boolean dir, byte dirPin, byte stepperPin, int steps, int steplength)
{
digitalWrite (dirPin, dir);
delay (500);
for (int z = 0; z <steps; z++)
{
digitalWrite (stepperPin, HIGH);
delayMicroseconds (steplength);
digitalWrite (stepperPin, LOW);
delayMicroseconds (800);
}}

void setup() {
// put your setup code here, to run once:
// The stepper motor used in the IO pin is set to output
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() {
// put your main code here, to run repeatedly:
stepX (true, X_DIR, X_STP, 400, 800); // X axis motor reverse 1 ring, the 200 step is a circle.
stepY (true, Y_DIR, Y_STP, 400, 3000); // y axis motor reverse 1 ring, the 200 step is a circle.
stepZ (true, Z_DIR, Z_STP, 400, 800); // z axis motor reverse 1 ring, the 200 step is a circle.
delay(5000);

stepX (false, X_DIR, X_STP, 400, 800); // X axis motor reverse 1 ring, the 200 step is a circle.
stepY (false, Y_DIR, Y_STP, 400, 3000); // y axis motor reverse 1 ring, the 200 step is a circle.
stepZ (false, Z_DIR, Z_STP, 400, 800); // z axis motor reverse 1 ring, the 200 step is a circle.
delay(5000);
}

@Adrian_SAM

I gave you those links so you would know how to use the forum and post code properly.
Please use code tags and the links I gave you.

For some reason AcceslStepper library doesn't work with this shield.
I declared it like this in the MultiStepper sketch and is not working.
AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);
AccelStepper stepper2(AccelStepper::DRIVER, 3, 6);
AccelStepper stepper3(AccelStepper::DRIVER, 4, 7);

I tested with the Robokits example and all steppers are working fine with a pulse HIGH of 800 microseconds and LOW the same. The example from Robokits without a library but the problem is the cycle time. I need it in a much bigger sketch and I don't want to interrupt the whole thing when the steppers are moving. I would need a parallel cycle. I change it to move less steps at every cycle but still seem broken. The solution would be to add another Uno but I want to avoid it if is possible. This was a useful source of information:

(mod edit)


'

See all those shields ?

Are you sure none of them use pins that are used by any of the others ?

And PLEASE use those links I gave you, more so for posting code.
I certainly dont post them to look pretty !