Multiple Stepper Motor Circuit Issue

I am using an Arduino and a Pi to control two stepper motors connected to DRV8825 drivers. The Pi communicates with the Arduino through serial, telling the Arduino which motor to move and how far. In the code, my motors are called A and B(the driver connected to pins 2 and 3 is A and the driver connected to pins 4 and 5 is B).

I believe my issue is both a code and hardware problem. Whichever motor is designated as B moves very little, and the driver gets really hot. When the driver on the far left is motor A, there are no issues with it, but when the driver in the middle is motor A, it only works well for a short time before it starts to stall, and it's always hot. Because of this, I believe there is an issue with my code that makes whichever motor designated as B stall, but the driver in the middle has low performance regardless.

I want to eventually create a circuit with up to 10 drivers, so I was hoping that I could get some insight into what I'm doing wrong so that every motor gets close to equal performance. Thank you!

Here is my code:

#include <AccelStepper.h>

#define dirPin 2
#define stepPin 3
#define dirPin2 4
#define stepPin2 5
#define motorInterfaceType 1

int SPEED=200;

AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
AccelStepper stepper2 = AccelStepper(motorInterfaceType, stepPin2, dirPin2);

//Steps the motor
// Stepper object, number of steps, previous position of stepper motor
void stepMotor(AccelStepper myMotor, String motorSteps, long int previousPosition){
while (myMotor.currentPosition() != previousPosition+motorSteps.toInt()){
if (motorSteps.toInt()<0){
myMotor.setSpeed(-SPEED);
} else {
myMotor.setSpeed(SPEED);
}

myMotor.runSpeed();
}
}

void setup()
{
//Open serial communication
Serial.begin(9600);
// Setting the positions and max speeds of the two steppers
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(1000);
stepper2.setCurrentPosition(0);
stepper.setMaxSpeed(1000);
}

void loop() { 
long int prevPos=stepper.currentPosition();
long int prevPos2=stepper2.currentPosition();
String motor="";

//Stalls the program until new serial data comes in
while (Serial.available()<=0){}

if (Serial.available() > 0) {
motor = Serial.readStringUntil('\n');
Serial.println(motor);
if (motor=="A" || motor=="B") {
Serial.println("Motor received.");
} 
}
//Motor end

//Stalls the program until new serial data comes in
while (Serial.available()<=0){}

if (Serial.available() > 0) {
String steps = Serial.readStringUntil('\n');
Serial.println(steps);
if(motor=="A"){
stepMotor(stepper, steps, prevPos);
} else if (motor=="B"){
stepMotor(stepper2, steps, prevPos2);
}
}
//Steps end

Serial.println("Finished!");
}

Please read the sticky entries on top of the forum, in detail how to present code enclosed in Code Tags </>.

You either have an inappropriate driver for your steppers, or you apply a too high voltage, or you missed to adjust the current appropriately. Hot stepper motors are normal, they produce most heat when standing still.

For further assistance please provide data sheets for your steppers and driver modules and their power supply.

I can't imagine how different code could affect the temperature of the motor. That normally depends on the current flowing in the motor coils which is set by the DRV8825.

Please post links to the datasheet for your motors - two datasheets if the motors are not identical.

Please describe your stepper motor power supply (volts and amps).

...R
Stepper Motor Basics
Simple Stepper Code

Hi,
What are the specs of the steppers?
Have you set the current limit on the DRV modules?
What are you using for a power supply for the steppers.

Have you made a basic test code for the Arduino to check the correct operation of your stepper drivers and motors?

Can you post a circuit diagram of the Arduino, stepper driver, stepper motor and power supply please?

Thanks. Tom... :slight_smile: