Using two stepper motor drivers with one arduino mega2560_

Hi, I'm trying to operate two of my stepper motor drivers using Arduino Mega2560. It requires pulse, direction and enable pins I am using LabVIEW as GUI to control the direction and steps of the stepper motor. Only one stepper motor operates in both the directions. There are no issues in wiring. I do not know if i have coded the arduino correctly. Can anyone tell me where I am going wrong?

/*
 * Stepper_bipolar sketch
 *
 * stepper is controlled from the serial port.
 * a positive numeric value steps in one direction.
 * a negative numeric value steps in the opposite direction.
 *
 */

#include <Stepper.h>

// change this to the number of steps per revolution for your motor
#define STEPS 200
#define pulse 10
#define dir 9
#define enable 11
#define pulse_1 12
#define dir_1 12
#define enable_1 7

// create an instance of the stepper class, specifying
// the number of steps per revolution for the motor and 
// the pins it's attached to
Stepper stepper(STEPS, 9,10);
Stepper stepper1(STEPS, 1,0);

int steps = 0;
int steps1 = 0;

void setup()
{
  // set the speed of the motor to 20 RPM
  stepper.setSpeed(20);
  stepper1.setSpeed(20);
  pinMode(enable, OUTPUT);
  pinMode(enable_1, OUTPUT);
  pinMode(pulse, OUTPUT);
  pinMode(pulse_1, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(dir_1, OUTPUT);
  Serial.begin(9600);
}

void driver_1(){
  //driver_1
  digitalWrite(enable, HIGH);
  digitalWrite(dir, HIGH);
  digitalWrite(pulse, HIGH);
  digitalWrite(pulse, LOW);
  digitalWrite(dir, LOW);
  digitalWrite(pulse, HIGH);
  digitalWrite(pulse, LOW);
  if (Serial.available()>0){
    steps = Serial.parseInt();
    }
    if( steps != 0){
      stepper.step(steps);
      }
      steps=0;
}

void driver_2(){
  driver_2
  digitalWrite(enable_1, HIGH);
  digitalWrite(dir_1, HIGH);
  digitalWrite(pulse_1, HIGH);
  digitalWrite(pulse_1, LOW);
  digitalWrite(dir_1, LOW);
  digitalWrite(pulse_1, HIGH);
  digitalWrite(pulse_1, LOW);
  if (Serial.available()>0){
    steps1 = Serial.parseInt();
    }
    if( steps1 != 0){
      stepper1.step(steps1);
      }
      steps1=0;
}

void loop(){
  driver_1();
  driver_2();
}

What happends?
Does that code compile?
Check first line in Driver.

Hi,

stepper1 uses pins 1 and 0, they are the programming pins for the 2560.
Try using another pair.

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

[quote="div01, post:1, topic:930623"]

#define pulse_1 12
#define dir_1 12

  digitalWrite(pulse_1, HIGH);
  digitalWrite(pulse_1, LOW);
  digitalWrite(dir_1, LOW);
  digitalWrite(pulse_1, HIGH);
  digitalWrite(pulse_1, LOW);

The pin for pulse_1 and for dir_1 are the same number (12). How are the motor drivers actually connected? Post a schematic, please. What are the motor drivers and motors?

You assign pins for step and dir (9, 10 & 0, 1) in the constructors but use different pins in the driver functions code. Why?

And what @TomGeorge said.

Thank you for all the help! I changed the pins and it works sequentially now