Having difficulty with 2 Stepper Motors on a single Arduino Uno

I'm using two Nema 17 Motors (bipolar) each on a separate MP6500 driver to rotate a platform in azimuth and broadside. This results in a DIR pin and a STEP pin for each of the stepper motors (4 pins total). I have configured my code as below. I can use this code successfully to drive only one stepper motor at a time (if I block out the other stepper code). I cannot figure out why the program won't work if I have both steppers in the code. I don't need to drive both at the same time, I just want to run both using one program. It's a pain to go back and forth. Why can't I run both of the stepper motors using this one program?

#include <Stepper.h>
Stepper azimuth(200, 3, 5);
//Stepper broadside(200, 9, 10);

void setup() {

  // Setup the pins as Outputs
  azimuth.setSpeed(100);
  //broadside.setSpeed(60);
  Serial.begin(9600);
  Serial.println("setup");
}
void loop() {
  while (!Serial.available()) {}
  char val = Serial.read();
  while (val == 'a') {
    azimuth.step(400);
    Serial.println(val);
    val = "";
    delay(300);
  }
  while (val == 'q') {
    azimuth.step(2);
    Serial.println(val);
    val = "";
    delay(300);
  }
  while (val == 'w') {
    //broadside.step(200);
    Serial.println(val);
    val = "";
    delay(300);
  }
  while (val == 'e') {
    //broadside.step(2);
    Serial.println(val);
    val = "";
    delay(300);
  }
}

Thanks

How are you powering your stepper motors? You can not drive them directly from Arduino pins.

what kind of behaviour do you see if both stepper-motors are "active" in your code?

The Stepper library doesn't work with Step & Direction stepper drivers. It does two-wire (quadrature?) and four-wire (four phase?) stepper motors. I would recommend the AccelStepper library for running a stepper with a Step & Direction driver.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.