Running two Nema 17 motors through two different drivers

Hey everyone,

I'm trying to power two Nema 17 stepper motors via an Arduino Uno board, one DM332T digital stepping driver, and an L298N motor driver. When testing them, I was able to get them to run individually utilizing two different sets of code. However, when I plug them both into the Uno board and try running a single program, I can't get either to work. Any help or guidance would be greatly appreciated!

Here's the code:

#define PUL1_PIN    2 
#define DIR1_PIN    3
#define PUL2_PIN    5
#define DIR2_PIN    6
#define PUL3_PIN    8
#define DIR3_PIN    9
  
class stepperMotor{
  public:
     
     // function to stop motor, value of 0 is the "off" signal
  void stop(void){
    enable = 0;
  }
  
  //function to start motor, value of 1 is the "on" signal
  void start(void){
    enable = 1;
  }
  
  void init(int _pulsePin, int _dirPin, unsigned long _delayTime, bool _direction){
    pulsePin      = _pulsePin;
    dirPin        = _dirPin;
    delayTime     = _delayTime;
    direction     = _direction;
      
    togglePulse   = LOW;
    enable        = 0;
      
    pinMode(pulsePin, OUTPUT);  //sets pulsePin variable as a digital output, motorTwo pin 8
    pinMode(dirPin, OUTPUT);  //sets dirPin variable as digital output, motorTwo pin 9
  }
  
 void init2(int _pulsePin1, int _dirPin1, int _pulsePin2, int _dirPin2, unsigned long _delayTime1, bool _direction1) {
    pulsePin1      = _pulsePin1;
    dirPin1        = _dirPin1;
    pulsePin2      = _pulsePin2;
    dirPin2       = _dirPin2;
    delayTime     = _delayTime1;
    direction     = _direction1;
      
    togglePulse   = LOW;
    enable        = 0;
      
    pinMode(pulsePin1, OUTPUT);  //motorOne pin 2
    pinMode(dirPin1, OUTPUT);  //motorOne pin 3
    pinMode(pulsePin2, OUTPUT);  //motorOne pin 5
    pinMode(dirPin2, OUTPUT);  //motorOne pin 6
  }

  void control(void){
    currentTime = micros();  //saves the amount of microseconds since the program started within variable currentTime
    digitalWrite(dirPin, direction);  //
    if(enable == 1){
      if( (currentTime - deltaTime) > delayTime ){
        pulseCount++;
 
        // Each HIGH or LOW is a "pulse"
        // But each step of the motor requires two "pulses"
        if(pulseCount % 2 == 0){
          stepCount++;
        }
  
        togglePulse = togglePulse == LOW ? HIGH : LOW;
        digitalWrite(pulsePin, togglePulse);
        deltaTime = currentTime;
      }
    }
  }
  
  void changeDirection(bool _direction){
    direction = _direction;
  }
  
  unsigned long steps(void){
    return stepCount;
  }
  
  void changeSpeed(unsigned long _speed){
    delayTime = _speed;
  }
    
  private:
  unsigned long delayTime, deltaTime, currentTime;
  unsigned long pulseCount = 0;
  unsigned long stepCount = 0;
  int pulsePin, pulsePin1, pulsePin2, dirPin, dirPin1, dirPin2;
  bool direction, togglePulse, enable;
};
  
stepperMotor stepperOne, stepperTwo;  //declares variables stepperOne and Two as users of class function
  
void setup() {
  stepperOne.init2(PUL1_PIN,DIR1_PIN,PUL2_PIN,DIR2_PIN,1000,HIGH);  //turns on digital pins and sets to 1 second delay
  stepperTwo.init(PUL3_PIN,DIR3_PIN,1000,HIGH);  //turns on digital pins and sets 1 second delay
  stepperOne.start();  
  stepperTwo.start();  
}
  
void loop() {
  stepperOne.control();
  stepperTwo.control();
  
  if(stepperOne.steps() == 2000){
    stepperOne.changeDirection(LOW);
    stepperOne.changeSpeed(600);
  }
}

The ancient, extremely inefficient L298 is not a stepper motor driver and won't work well or at all with modern, low impedance stepper motors.

Please post a complete wiring diagram, and links to the product pages for the stepper driver, motors and the motor power supply.

2 Likes

If you search the forum for L298 or ULN2003 you will often find that they are not recommended for stepper motors except in very basic use.

Post an annotated schematic, frizzy pictures do not count. Be sure to show all connections, power, ground, interconnections and power supply(s). Also post links to technical information on each of the hardware devices. Market place links are generally useless.

Fritzing pics DO COUNT !
You may not like them personally but they are still valid.

Okay so I've taken some time to think about what I'm trying to do here and I'm having trouble answering these questions:

I'm a ME major and nobody on our team is an Electrical engineer nor a systems engineer, so please bear with me

1.) This is the NEMA 17 motor I'm using, it says it has a current per winding rate of 3A - I don't know what that means. Does that mean it is using 6A since it is a bipolar motor?
1a.) If that is the case, since I'm using two of these motors, are they then drawing 12A total from my power supply?
1b.) My L298n is rated at a max of 3A and continuous current of 2A - is the motor too much for this driver?
1c.) Is my stepper motor drawing the 3A-6A always? or just when it is in motion?
1d.) I also have a DM332T stepping driver, is that correctly rated to drive my stepping motors?

2.) I want to connect a parabolic dish antenna to my arduino board to detect signal gain. I was thinking of using the NRF24L01+PA+LNA in conjuction with the antenna to interpret the antenna signal and interact with my arduino Uno rev3. Will that work or do I need another middle component?

3.) I need a way to determine the position of the motors which will be in the x and y axis. Any recommendations?

That means that the maximum continuous coil current is 3 Amperes per winding, which gives the rated torque. If you need the rated torque, you MUST use a current limiting stepper driver that can handle 3 Amperes/winding, but you can set the stepper driver to less than that, to save power at less torque.

Again, the L298 is not a stepper motor driver. It can handle only 1 Ampere per channel and will not work with that motor.

My L298n is rated at a max of 3A and continuous current of 2A

Either you misunderstand the seller's specs, or the seller is misleading you.

No. As @jremington pointed out, you need a current control driver for your motors. These drivers work similar to a buck converter, so the current from the PSU is less then the coil current - depending on the voltage of the PSU.

The other important specification is the winding resistance, in this case 1.1 Ohms. That means that the motor will draw power P = I^2R = 10 Watts per winding, 20 Watts total per motor, if used at full rated torque/power.

The motor power supply voltage can be anywhere between about 12V and 48V (depending on the motor driver) and for a safety margin, the power supply should be rated at over 60 Watts, for two motors operating.

Higher motor power supply voltages lead to faster maximum step rates and a more responsive system.

Okay so here's another update: replaced the L298 with another DM332T microstepper and decided to utilize the accelstepper library. However, we have run into another problem, this time it is with the motors and trying to reverse the direction. They'll run CW but refuse to go CCW unless we manually swap the polarity of the wires. I'll attach the most recent code I've been using.

I have also run into an issue with having the motor move to a specified position, but I think it is a user error. For example, if I have our microstepper set to 400 pulses/rev, and I specify moveTo(400);, in my mind, that should be one full rotation, however, the motor will either rotate just shy of one rotation or go over.

// Include the AccelStepper Library and elapsed time library
#include <AccelStepper.h>
#include <elapsedMillis.h>

//look at where the wire on uno plugs into driver
//pul and dir pins on driver should match code
#define dir1Pin 2  //direction pin for step mtr 1 
#define pul1Pin 3  //pulse pin for stepper motor 1 (azimuth)
#define pul2Pin 8  //pulse pin for stepper motor 2 (elevation)
#define dir2Pin 9  //direction pin for stp mtr 2

// azStepper= azimuth stepper = horizontal axis; elStepper = elevation = vertical axis
AccelStepper azStepper = AccelStepper(1, pul1Pin, dir1Pin);
AccelStepper elStepper = AccelStepper(1, pul2Pin, dir2Pin);

//elapsedMillis printTime;

//int azCount = 0;
//int elCount = 0;

/*void azTimeKeeper()
{
  float azSpeed;
    if (printTime >= 1000) {    // reports speed and position each second
      printTime = 0;
      azSpeed = azStepper.speed();
      Serial.println("azStepper speed:");
      Serial.println(azSpeed);
      Serial.print("  ");
      Serial.print(azStepper.currentPosition());
      Serial.print("  ");
      Serial.println("Seconds passed:");
      Serial.println(azCount);
      azCount++;
      if (azCount++ == 4){      // uncomment an action to see the response in the serial monitor
        azStepper.moveTo(100);
        //azStepper.move(100);
        //azStepper.stop(); 
    } 
  }
}*/

/*void elTimeKeeper()
{
  float elSpeed;
    if (printTime >= 1000) {    // reports speed and position each second
      printTime = 0;
      elSpeed = elStepper.speed();
      Serial.print("elStepper Speed:");
      Serial.print(elSpeed);
      Serial.print("  ");
      Serial.print(elStepper.currentPosition());
      Serial.print("  ");
      Serial.print("Seconds passed:");
      Serial.println(elCount);
      elCount++;
      if (elCount++ == 4){      // uncomment an action to see the response in the serial monitor
        elStepper.moveTo(100);
        //elStepper.move(100);
        //elStepper.stop(); 
    } 
  } 
}*/

void setup()
{
	// initialize the serial port:
	Serial.begin(9600);
  Serial.println("Program Initializing");

  //Sets speed of associated motor; pulse(steps) per second
  azStepper.setMaxSpeed(1000);
  azStepper.setSpeed(400);
  elStepper.setMaxSpeed(1000);
  elStepper.setSpeed(500);

  azStepper.moveTo(10000);
  elStepper.moveTo(-10000);

  azStepper.runToPosition();
  elStepper.runToPosition();
 
}

void loop() 
{
  //azTimeKeeper();
  //elTimeKeeper();



  //Serial.print(azStepper.currentPosition());
  //Serial.println("  ");
  //Serial.print(elStepper.currentPosition());
  //Serial.println("  ");
  
 // Change direction once the motor reaches target position
  /*
    if (azStepper.distanceToGo() == 0)   // this form also works
    azStepper.moveTo(-azStepper.currentPosition());

    // Move the motor one step
    azStepper.run();
  
  if (!azStepper.run()) {   // run() returns true as long as the final position has not been reached and speed is not 0.
    azStepper.moveTo(-azStepper.currentPosition());
  } */

}

Update: managed to get both motors to go both CW and CCW. Our driver required a wire in the opto pin

Floating wire often makes the system unstable.
In this case, OPT-pin disconnection makes PUL and DIR floating.
It is expected that not only the direction of motor rotation but also the amount of rotation is improved.

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