Running 2 steppers at the same time but not simultaneously

There seems to be a fundamental problem here. You should follow Robin's advice. Good Luck.

Robin2:
We are now at Reply #39 and very little progress seems to have been made - if anything success seems to further away. I think the most productive thing now is to put all your existing code to one side and start again - seriously.

Write a very short program to make one stepper move at the speed you require - use the second example in the link I gave you in Reply #1 as your starting point.

When that is working (and only then) add the code for a second motor so it moves at a different speed - to prove that it is being controlled separately, but at the same time.

...R

Ok, you've right.. I'll try to restart by basic movements.. Thank you!

DKWatson:
There seems to be a fundamental problem here. You should follow Robin's advice. Good Luck.

Sure it is.. it is my first time coding.. anyway thank you for your help..

I tryed to start again by your tutorial example, Robin, and then, after i moved both motors, the temptation to take a look again at the program that nearly worked last evening was too much.. Sorry.

So i did it and, it works! Every 1512 Xsteps, Y makes 88 steps, simultaneously. Now i only need to make the CCW function and find out how to call it in the right way to make all work fine.

#define EN        8 

//Direction pin
#define X_DIR     5
#define Y_DIR     6

//Step pin
#define X_STP     2
#define Y_STP     3


int StepperPosX = 0; // How far we've traveled on X
int StepperPosY = 0; // How far we've traveled on Y

int Delay = 200;
int StepperDestinationX = 1600;
int StepperDestinationY = 88;
int StepperDestinationXB = 1512;

void pulse_X_CW(int steps) {

  for (int i = 0; i < steps; i++) {
    digitalWrite(X_DIR, HIGH);
    digitalWrite(X_STP, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(X_STP, LOW);
    delayMicroseconds(Delay);
}
}

void pulse_Y_CW(int steps) {

  for (int i = 0; i < steps; i++) {
    digitalWrite(Y_DIR, HIGH);
    digitalWrite(Y_STP, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(Y_STP, LOW);
    delayMicroseconds(Delay);
  }
  }


void setup(){

pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);

pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);

pinMode(EN, OUTPUT);

digitalWrite(EN, LOW);


Serial.begin(9600);

}

void loop(){

StepperPosX ++;
if (StepperPosX < StepperDestinationX) {
pulse_X_CW (StepperDestinationX);
StepperPosX = StepperPosX +1;                // Record X step
if (StepperPosX = StepperDestinationXB) {
pulse_Y_CW (StepperDestinationY);
 if (StepperPosX == StepperDestinationX) {
   
   StepperPosX = 0;                
 }
 
}
}
}

Glad you have it working.

...R

Robin2:
Glad you have it working.

...R

Actually i realized that steppers weren't at sync, i thought that they were just slowing down when both were timing because of the sum of delays, but at higher delays i seen that the X was totally stopped meanwhile the Y was doing its movements.
So i made this correction to the program functions:

void pulse_Y_CW(int steps) {

  for (int i = 0; i < steps; i++) {
    digitalWrite(Y_DIR, HIGH);
    digitalWrite(X_DIR, HIGH);
    digitalWrite(Y_STP, HIGH);
    digitalWrite(X_STP, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(Y_STP, LOW);
    digitalWrite(X_STP, LOW);
    delayMicroseconds(Delay);
  }
  }

void pulse_Y_CCW(int steps) {

  for (int i = 0; i < steps; i++) {
    digitalWrite(Y_DIR, LOW);
    digitalWrite(X_DIR, HIGH);
    digitalWrite(Y_STP, HIGH);
    digitalWrite(X_STP, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(Y_STP, LOW);
    digitalWrite(X_STP, LOW);
    delayMicroseconds(Delay);
  }
  }

A big thank you for your and DKWatson's precious help (:

So everything is good?