# Nema34 and driver MA860H

Hello,
Someone help me.
I want to drive 12 motors: (6 left CW and 6 right CCW) at the same time and the opposite too. (using arduino Mega 2560). I used stepper motor Nema34 (MA860 as driver).
I tried with my program
Because I used 12 motors I found that it will be a big program for that, in order to not repeat each instruction, I used loop function “for” define the dirPins of driver but I found a problem with stepPins.
could you help me for that?
MA860H.ino (3.5 KB)

post the code inline with code tags so that we can read it directly in the post.

``````/*
This is a program which controls the steps and direction of the stepper motor.
As the stepper motor I am using has the step angle of 1.8 degrees and
as I am using the  MA860H/ DA860D stepper motor driver in the full step configuration,
so, for 1/2  revolution I will need 100 steps as 1.8 x 100 = 180.
As you can see in the programming I am using 400, so it will complete two revolutions.
Program for controlling two stepper motors:

/*
Stepper motor
Demonstrates NEMA34 Bipolair Steppers with MA860H Driver

*/
// Define constants

// Connection to MA860H
const int MotorCount = 12;
const int PinsPerMotor = 2;
const int MotorPins1[MotorCount][PinsPerMotor] =
{
{2, 3}, {4, 5}, {6, 7}, {8, 9}, {10, 11}, {12, 13}
}; // 6 MOTORS RIGHT , first pin is the directionPin and the second is the stepPin

const int MotorPins2[MotorCount][PinsPerMotor] =
{
{14, 15}, {16, 17}, {18, 19}, {20, 21}, {22, 23}, {24, 25}
}; // 6 MOTORS LEFT

void setup()
{
for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++)
for (int thisPin = 0; thisPin < PinsPerMotor; thisPin++)
{
pinMode(MotorPins1[thisMotor][thisPin], OUTPUT);
pinMode(MotorPins2[thisMotor][thisPin], OUTPUT);
}
}

void loop() {

for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++)
for (int thisPin = 0; thisPin < PinsPerMotor/2; thisPin++)
{
digitalWrite(MotorPins1[thisMotor][thisPin],HIGH); // Enables the motor to move in a particular direction
digitalWrite(MotorPins2[thisMotor][thisPin],LOW); // Enables the motor to move in a particular direction
}

// Makes 100 pulses for making a half cycle rotation
for(int x = 0; x < 100; x++){

digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);
digitalWrite(15,HIGH);
digitalWrite(17,HIGH);
digitalWrite(19,HIGH);
digitalWrite(21,HIGH);
digitalWrite(23,HIGH);
digitalWrite(25,HIGH);
delayMicroseconds(500);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
digitalWrite(13,LOW);
digitalWrite(15,LOW);
digitalWrite(17,LOW);
digitalWrite(19,LOW);
digitalWrite(21,LOW);
digitalWrite(23,LOW);
digitalWrite(25,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay

for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++){
for (int thisPin = 0; thisPin < PinsPerMotor/2; thisPin++)
{
digitalWrite(MotorPins1[thisMotor][thisPin],LOW); // Enables the motor to move in a particular direction
digitalWrite(MotorPins2[thisMotor][thisPin],HIGH); // Enables the motor to move in a particular direction
}
}
// Makes 400 pulses for making 2 FULL cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);
digitalWrite(15,HIGH);
digitalWrite(17,HIGH);
digitalWrite(19,HIGH);
digitalWrite(21,HIGH);
digitalWrite(23,HIGH);
digitalWrite(25,HIGH);
delayMicroseconds(500);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
digitalWrite(13,LOW);
digitalWrite(15,LOW);
digitalWrite(17,LOW);
digitalWrite(19,LOW);
digitalWrite(21,LOW);
digitalWrite(23,LOW);
digitalWrite(25,LOW);
delayMicroseconds(500);
}
delay(1000);
}
``````

Hi,
I think it should be like this;

``````/*
This is a program which controls the steps and direction of the stepper motor.
As the stepper motor I am using has the step angle of 1.8 degrees and
as I am using the  MA860H/ DA860D stepper motor driver in the full step configuration,
so, for 1/2  revolution I will need 100 steps as 1.8 x 100 = 180.
As you can see in the programming I am using 400, so it will complete two revolutions.
Program for controlling two stepper motors:

/*
Stepper motor
Demonstrates NEMA34 Bipolair Steppers with MA860H Driver

*/
// Define constants

// Connection to MA860H
const int MotorCount = 12;
const int PinsPerMotor = 2;
const int MotorPins1[MotorCount][PinsPerMotor] =
{
{2, 3}, {4, 5}, {6, 7}, {8, 9}, {10, 11}, {12, 13}
}; // 6 MOTORS RIGHT , first pin is the directionPin and the second is the stepPin

const int MotorPins2[MotorCount][PinsPerMotor] =
{
{14, 15}, {16, 17}, {18, 19}, {20, 21}, {22, 23}, {24, 25}
}; // 6 MOTORS LEFT

void setup()
{
for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++)
for (int thisPin = 0; thisPin < PinsPerMotor; thisPin++)
{
pinMode(MotorPins1[thisMotor][thisPin], OUTPUT);
pinMode(MotorPins2[thisMotor][thisPin], OUTPUT);
}
}

void loop() {

for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++)
for (int thisPin = 0; thisPin < PinsPerMotor/2; thisPin++)
{
digitalWrite(MotorPins1[thisMotor][thisPin],HIGH); // Enables the motor to move in a particular direction
digitalWrite(MotorPins2[thisMotor][thisPin],LOW); // Enables the motor to move in a particular direction
}

// Makes 100 pulses for making a half cycle rotation
for(int x = 0; x < 100; x++){

digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);
digitalWrite(15,HIGH);
digitalWrite(17,HIGH);
digitalWrite(19,HIGH);
digitalWrite(21,HIGH);
digitalWrite(23,HIGH);
digitalWrite(25,HIGH);
delayMicroseconds(500);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
digitalWrite(13,LOW);
digitalWrite(15,LOW);
digitalWrite(17,LOW);
digitalWrite(19,LOW);
digitalWrite(21,LOW);
digitalWrite(23,LOW);
digitalWrite(25,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay

for (int thisMotor = 0; thisMotor < MotorCount; thisMotor++){
for (int thisPin = 0; thisPin < PinsPerMotor/2; thisPin++)
{
digitalWrite(MotorPins1[thisMotor][thisPin],LOW); // Enables the motor to move in a particular direction
digitalWrite(MotorPins2[thisMotor][thisPin],HIGH); // Enables the motor to move in a particular direction
}
}
// Makes 400 pulses for making 2 FULL cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);
digitalWrite(15,HIGH);
digitalWrite(17,HIGH);
digitalWrite(19,HIGH);
digitalWrite(21,HIGH);
digitalWrite(23,HIGH);
digitalWrite(25,HIGH);
delayMicroseconds(500);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
digitalWrite(13,LOW);
digitalWrite(15,LOW);
digitalWrite(17,LOW);
digitalWrite(19,LOW);
digitalWrite(21,LOW);
digitalWrite(23,LOW);
digitalWrite(25,LOW);
delayMicroseconds(500);
}
delay(1000);
}

``````

I could not figure your suggested. it is the same as mine

how to add arduino code on this new forum

Hi,
If you look in the EDIT tab of the IDE,
you SELECT ALL
then
COPY FOR FORUM

This will put your code on the clipboard with code tags already inserted.

You then paste it into your post.

Tom,

1 Like

thank you. I know I copy it but how to insert post the code inline with code tags

ok it works with me so sorry.

Did you have a look around to see if there are motor libraries for these motors? I’ve not dealt with steppers much but I know there are libraries for this.

Here is a good starting point https://www.arduino.cc/en/Reference/Stepper

See if this’ll help.

-jim lee

Hi,
A link to @rezahmed stepper driver.

Tom…

Thank you
I used this manual it is the same.

thank you