Trouble Running x stepper motors on x drivers simultaneously

Hi Arduinocomunity,

i would like to introduce myself before presenting my problem. My Name is FrankSteel i am 32 years of age, a mechanical engineer and new to arduino.
I searched on google for a solution for my problem but i could not find what i was looking for, thats the reason why i am starting a new topic.

I would like to run in total 15 stepper motors (nema17) simultaneously, 5 at speed x and direction y, 5 at speed y and direction y and 5 at speed y and direction x. I plan to use 6 drivers tb6600, that max. 3 motors are on 1 driver.

The part of my code, which is not working is displayed below:
Triggerd by pushing S1 the while loop is entered. if the limit switch is not active the stepper drivers are supposed to run by changeing the pulse signal of the driver.

while (digitalRead(S1) == HIGH) //Hochfahren
{
if (digitalRead(S3) == HIGH) //Endschalter oben
{ digitalWrite(Ena, HIGH);//Motor1 Ausschalten
digitalWrite(Ena2, HIGH);//Motor2 Ausschalten
digitalWrite(Ena3, HIGH);//Motor2 Ausschalten
Serial.println("Endschalter Oben");
break;
}
else {
//Antrieb 1
digitalWrite(Ena, LOW);
digitalWrite(Ena2, LOW);
digitalWrite(Ena3, LOW);

  digitalWrite(Dir, HIGH);
  digitalWrite(Dir2, HIGH);
  digitalWrite(Dir3, LOW);
  
  digitalWrite(Pul, HIGH);
  delayMicroseconds(800); // Schneller Lauf
  digitalWrite(Pul, LOW); // Step low
 
  digitalWrite(Pul2, HIGH);
  delayMicroseconds(800); // Schneller Lauf
  digitalWrite(Pul2, LOW); // Step low
  
  digitalWrite(Pul3, HIGH);
  delayMicroseconds(800); // Schneller Lauf
  digitalWrite(Pul3, LOW);

  digitalRead(S1);
  Serial.println("Rechts");
  if (digitalRead(S1) == LOW)
  { Serial.println("Abbruch");
    break;
  }

What is happening is shown in the video:

For some reason i cant get, the one stepper motor attached is slower then the other, despite the fact that they have the same set up on the driver.
Does anyone have a solution at hand?

You cannot use 3 steppers with one driver. You need one driver per stepper.

Please show the complete sketch, no fragments. And post your sketch in code tags.

  • right click into the code window of the ide
  • select 'Copy for forum' in the pop up menue
  • paste into your post.

int Index;
//Motor 1 - Antrieb
int Pul = 1;
int Dir = 2;
int Ena = 3;
//Motor2 - Aufwicklung
int Pul2 = 4;
int Dir2 = 5;
int Ena2 = 6;

//Motor3 - Antrieb
int Pul3 = 11;
int Dir3 = 12;
int Ena3 = 13;

int S1 = 7; //Runterfahren
int S2 = 8;// Hochfahren
int S3 = 9; // endschalter oben
int S4 = 10;// Endschalter unten


void setup()
{
  Serial.begin(9600);
  pinMode(Ena, OUTPUT); //Enable
  pinMode(Pul, OUTPUT); //Puls
  pinMode(Dir, OUTPUT); //Direction
  pinMode(Ena2, OUTPUT); //Enable
  pinMode(Pul2, OUTPUT); //Puls
  pinMode(Dir2, OUTPUT); //Direction
  pinMode(Ena3, OUTPUT); //Enable
  pinMode(Pul3, OUTPUT); //Puls
  pinMode(Dir3, OUTPUT); //Direction
  pinMode(S1, INPUT); //Schalter
  pinMode(S2, INPUT); //Schalter
  pinMode(S3, INPUT); //Schalter
  pinMode(S4, INPUT); //Schalter
  digitalWrite(Ena, HIGH);
  digitalWrite(Ena2, HIGH);
  digitalWrite(Ena3, HIGH);
  digitalWrite(S1, LOW);
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  digitalWrite(S4, LOW);
  Serial.println("Setup");
  Serial.println(digitalRead(S1));
}

void loop()
{
  digitalRead(S3);
  digitalRead(S2);
  digitalRead(S1);
  digitalRead(S4);
  Serial.println("Loop");
  Serial.println(digitalRead(S1));
  Serial.println(digitalRead(S2));
  Serial.println(digitalRead(S3));
  Serial.println(digitalRead(S4));
  digitalWrite(Ena, HIGH);
  digitalWrite(Ena2, HIGH);
  digitalWrite(Ena3, HIGH);

  while (digitalRead(S1) == HIGH) //Hochfahren
  {
    if (digitalRead(S3) == HIGH) //Endschalter oben
    { digitalWrite(Ena, HIGH);//Motor1 Ausschalten
      digitalWrite(Ena2, HIGH);//Motor2 Ausschalten
      digitalWrite(Ena3, HIGH);//Motor2 Ausschalten
      Serial.println("Endschalter Oben");
      break;
    }
    else {
      //Antrieb 1
      digitalWrite(Ena, LOW);
      digitalWrite(Ena2, LOW);
      digitalWrite(Dir, HIGH);
      
      digitalWrite(Dir2, HIGH);
      digitalWrite(Ena3, LOW);
      digitalWrite(Dir3, LOW);
      
      digitalWrite(Pul, HIGH);
        delayMicroseconds(800); // Schneller Lauf
      digitalWrite(Pul, LOW); // Step low
      digitalWrite(Pul2, HIGH);
        delayMicroseconds(800); // Schneller Lauf
      digitalWrite(Pul2, LOW); // Step low
       digitalWrite(Pul3, HIGH);
       
      // Step high
      delayMicroseconds(800); // Schneller Lauf
      //delay(1); // Langsammer Lauf
      
      
      digitalWrite(Pul3, LOW);
      

      digitalRead(S1);
      Serial.println("Rechts");
      if (digitalRead(S1) == LOW)
      { Serial.println("Abbruch");
        break;
      }
    }

  }
  while (digitalRead(S2) == HIGH) //Runterfahren
  { if (digitalRead(S4) == HIGH) //Endschalter unten
    { digitalWrite(Ena, HIGH);
      digitalWrite(Ena2, HIGH);
      digitalWrite(Ena3, HIGH);
      Serial.println("Endschalter Unten");
      break;
    }
    else {

      //Antrieb 1
      digitalWrite(Ena, LOW);
      digitalWrite(Dir, LOW);
      digitalWrite(Pul, HIGH); // Step high
      delayMicroseconds(800); // Schneller Lauf
      //delay(10); // Langsammer Lauf
      digitalWrite(Pul, LOW); // Step low
      delayMicroseconds(800); // Schneller Lauf
      //Abwicklung
      digitalWrite(Ena2, LOW);
      digitalWrite(Dir2, HIGH);
      digitalWrite(Pul2, HIGH); // Step high
      delayMicroseconds(800); // Schneller Lauf
      //delay(1); // Langsammer Lauf
      digitalWrite(Pul2, LOW); // Step low
      delayMicroseconds(800); // Schneller Lauf
      //delay(1); // Langsammer Lauf

      //Antrieb 2
      digitalWrite(Ena3, LOW);
      digitalWrite(Dir3, HIGH);
      digitalWrite(Pul3, HIGH); // Step high
      delayMicroseconds(800); // Schneller Lauf
      //delay(1); // Langsammer Lauf
      digitalWrite(Pul3, LOW); // Step low
      delayMicroseconds(800); // Schneller Lauf
      //delay(1); // Langsammer Lauf

      digitalRead(S2);
      Serial.println("Links");
      if (digitalRead(S2) == LOW)
      { Serial.println("Abbruch2");
        break;
      }
    }
  }
  delay(1000);




}

Why not do all the steps at the same time rather than one after the other?

int Index;
//Motor 1 - Antrieb
int Pul = 1;
int Dir = 2;
int Ena = 3;
//Motor2 - Aufwicklung
int Pul2 = 4;
int Dir2 = 5;
int Ena2 = 6;

//Motor3 - Antrieb
int Pul3 = 11;
int Dir3 = 12;
int Ena3 = 13;

int S1 = 7; //Runterfahren
int S2 = 8;// Hochfahren
int S3 = 9; // endschalter oben
int S4 = 10;// Endschalter unten


void setup()
{
  Serial.begin(9600);
  pinMode(Ena, OUTPUT); //Enable
  pinMode(Pul, OUTPUT); //Puls
  pinMode(Dir, OUTPUT); //Direction
  pinMode(Ena2, OUTPUT); //Enable
  pinMode(Pul2, OUTPUT); //Puls
  pinMode(Dir2, OUTPUT); //Direction
  pinMode(Ena3, OUTPUT); //Enable
  pinMode(Pul3, OUTPUT); //Puls
  pinMode(Dir3, OUTPUT); //Direction
  pinMode(S1, INPUT); //Schalter
  pinMode(S2, INPUT); //Schalter
  pinMode(S3, INPUT); //Schalter
  pinMode(S4, INPUT); //Schalter
  digitalWrite(Ena, HIGH);
  digitalWrite(Ena2, HIGH);
  digitalWrite(Ena3, HIGH);
  digitalWrite(S1, LOW);
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  digitalWrite(S4, LOW);
  Serial.println("Setup");
  Serial.println(digitalRead(S1));
}


void stop()
{
  digitalWrite(Ena, HIGH);//Motor1 Ausschalten
  digitalWrite(Ena2, HIGH);//Motor2 Ausschalten
  digitalWrite(Ena3, HIGH);//Motor2 Ausschalten
  Serial.println("Endschalter Oben");

}

void step( int state)
{
  int other_state = state == HIGH ? LOW : HIGH;

  //Antrieb 1
  digitalWrite(Ena, LOW);
  digitalWrite(Dir, state);

  digitalWrite(Ena2, LOW);
  digitalWrite(Dir2, state);

  digitalWrite(Ena3, LOW);
  digitalWrite(Dir3, other_state);

  digitalWrite(Pul, HIGH);
  digitalWrite(Pul2, HIGH);
  digitalWrite(Pul3, HIGH);
  delayMicroseconds(800); // Schneller Lauf
  digitalWrite(Pul, LOW); // Step low
  digitalWrite(Pul2, LOW); // Step low
  digitalWrite(Pul3, LOW);
  delayMicroseconds(800); // Schneller Lauf
  //delay(1); // Langsammer Lauf
}

void loop()
{
  Serial.println("Loop");
  Serial.println(digitalRead(S1));
  Serial.println(digitalRead(S2));
  Serial.println(digitalRead(S3));
  Serial.println(digitalRead(S4));
  stop();
  while (digitalRead(S1) == HIGH) //Hochfahren (boot up)
  {
    if (digitalRead(S3) == HIGH) //Endschalter oben (limit switch up)
    {
      stop();
      break;
    }
    else {
      step( HIGH );
      Serial.println("Rechts");
      if (digitalRead(S1) == LOW)
      {
        Serial.println("Abbruch");  // cancel
        break;
      }
    }
  }

  while (digitalRead(S2) == HIGH) //Runterfahren (turn off)
  { if (digitalRead(S4) == HIGH) //Endschalter unten (limit switch down)
    {
      stop();
      break;
    }
    else {
      step( LOW );
      Serial.println("Links");
      if (digitalRead(S2) == LOW)
      {
        Serial.println("Abbruch2");
        break;
      }
    }
  }
  delay(1000);
}

Also, how are your switches wired up? You have them as INPUT so they will need a pull-up or pull-down resistor. Are they installed?

On most Arduino boards, pin 1 is the hardware serial TX pin. The analog pins (Ax) are really digital pins with analog input as a special function. Use an analog pin instead of pin 1.

How are the microstep switches set on each driver. Are they all the same?

that does not make a different in the result in my case, i tried that already.

i have pull-up resistors installed.

okay, so this actually changed something, it looks like this:

int Index;
//Motor 1 - Antrieb
int Pul = A0;
int Dir = A1;
int Ena = A2;
//Motor2 - Aufwicklung
int Pul2 = 4;
int Dir2 = 5;
int Ena2 = 6;

//Motor3 - Antrieb
int Pul3 = 11;
int Dir3 = 12;
int Ena3 = 13;

int S1 = 7; //Runterfahren
int S2 = 8;// Hochfahren
int S3 = 9; // endschalter oben
int S4 = 10;// Endschalter unten

and now they move at the same speed, no matter the delay in between the pulse change...

If you make a change to your code (even a small one), post the new version in its entirety so that we can keep up.

Do the drivers trigger a step on the low to high transition or the high to low transition. That will effect which delay changes the step rate.