Are array accesses slow enough to mess with stepper motor timings?

I am trying to drive multiple stepper motors in what will hopefully become a CNC machine one day. I first got one spinning using this driver and some NEMA-17 stepper motors. (the step pulses are low active on this controller) Here is the working code for a single motor which is a slightly modified version of the code I found here:

byte directionPin = 4;
byte stepPin = 3;
int maxSpeed = 400;
int steps = 400;    //steps in a full rotation
bool dir = true;

unsigned long curMicros;
unsigned long prevStepMicros = 0;
unsigned long microsBetweenSteps = 2000; // microsecond pulse width

void setup() {

     Serial.begin(9600);
     Serial.println("Starting Stepper Demo with micros()");
     if (microsBetweenSteps < maxSpeed){                      //check if max speed has been exceeded
      Serial.print("Max Speed Exceeded, speed set to ");
      Serial.println(maxSpeed);
      microsBetweenSteps = maxSpeed;
     }

     pinMode(directionPin, OUTPUT);
     pinMode(stepPin, OUTPUT);
}

void loop() {
    curMicros = micros();
    if (steps >= 0){                                  //if a full rotation has not yet been achieved
      if (singleStep(microsBetweenSteps,dir)){        //try to turn the motor
        steps = steps - 1;                            //if successful, decrement steps left
      }
    }
    else{                                            //after a full rotation, wait 1 second and switch directions
      steps = 400;
      dir = !dir;
      delay(1000);
    }
   
}

bool singleStep(int stepspeed, bool direct) {
    if (curMicros - prevStepMicros >= stepspeed) {  //check if enough time has passed since last movement

        prevStepMicros = curMicros;
        if (direct){                                //set motor direction pin
          digitalWrite(directionPin,LOW);
        }
        else{
          digitalWrite(directionPin,HIGH);
        }
        digitalWrite(stepPin, LOW);               //pulse the pin low
        digitalWrite(stepPin, HIGH);
        return true;                              //return true if motor moved
    }
    else{
      return false;                               //return false if the motor did not move
    }
}

However, after making some of the variables into arrays, the motor slows down substantially. Here is the code that I am trying to get running:

byte directionPin[2] = {4,7};
byte stepPin[2] = {3,6};
int maxSpeed = 400;
int steps[2] = {400,200};
bool dir[2] = {true,true};
int motorToAdress = 0;
bool currentState[2] = {true,true};
unsigned long curMicros;
unsigned long prevStepMicros[2] = {0,0};
unsigned long microsBetweenSteps[2] = {2000,200}; // microseconds

void setup() {

     Serial.begin(9600);
     Serial.println("Starting Stepper Demo with micros()");
     pinMode(3,OUTPUT);
     pinMode(4,OUTPUT);
     pinMode(6,OUTPUT);
     pinMode(7,OUTPUT);
     
     if (microsBetweenSteps[0] < maxSpeed){
      Serial.print("Max Speed Exceeded on motor 0, speed set to ");
      Serial.println(maxSpeed);
      microsBetweenSteps[0] = maxSpeed;
     }
     else{
      Serial.print("Motor 0 speed: ");
      Serial.println(microsBetweenSteps[0]);
     }
     if (microsBetweenSteps[1] < maxSpeed){
      Serial.print("Max Speed Exceeded on motor 1, speed set to ");
      Serial.println(maxSpeed);
      microsBetweenSteps[1] = maxSpeed;
     }
     else{
      Serial.print("Motor 1 speed: ");
      Serial.print(microsBetweenSteps[1]);
      Serial.println();
     }

     Serial.print("Talking to Motor ");
     Serial.println(motorToAdress);
     pinMode(directionPin, OUTPUT);
     pinMode(stepPin, OUTPUT);
}

void loop() {
    curMicros = micros();
    if (steps[motorToAdress] >= 0){
      if (singleStep(microsBetweenSteps[motorToAdress],dir[motorToAdress])){
        steps[motorToAdress] = steps[motorToAdress] - 1;
        Serial.println("move");
      }
      else{
        Serial.println("no move");
      }
    }
    else{
      steps[motorToAdress] = 400;
      dir[motorToAdress] = !dir[motorToAdress];
      delay(1000);
    }
   
}

bool singleStep(int stepspeed, bool direct) {
    if (curMicros - prevStepMicros[motorToAdress] >= stepspeed) {
      
        prevStepMicros[motorToAdress] = curMicros;
        
        if (direct){
          digitalWrite(directionPin[motorToAdress],LOW);
        }
        else{
          digitalWrite(directionPin[motorToAdress],HIGH);
        }

        digitalWrite(stepPin[motorToAdress],LOW);
        digitalWrite(stepPin[motorToAdress],HIGH);
        return true;
    }
    else{
      return false;
    }
}

Are the array accesses simply taking too long or is there something else that I am missing? Should I switch to an object-oriented approach? Thanks for any light you can shed on this mystery.

This is the line that's slowing it down:

popyd10:

        Serial.println("move");

Although the HardwareSerial code does implement asynchronous transmissions, this only occurs when there is space in the transmit buffer. Once the buffer is full, Serial.println() will block until enough characters have been sent out of the buffer to hold the data.

To test, change the baud rate to something reasonable, like 115200 or 250000, to see if things go faster.

9600 baud is so mid-80's.

If you want to drive a CNC machine you would be way better off just using something like GRBL. It is widely used and tested. You will have to use interrupts to drive the number of steps per second you will need to run the motors at, even with 8 micro steps per step. You got acceleration, deceleration, arcs, G-code support, limits, e-stop, homing, etc to worry about.

pert:
This is the line that's slowing it down

I commented out the serial prints and it works perfectly. Thanks for the help.

ToddL1962:
If you want to drive a CNC machine you would be way better off just using something like GRBL.

I looked into GRBL a little bit, but I am still confused as to how to get it running and what exactly it is. Are there any specific tutorials that you would recommend? Thanks for everyone who helped!

popyd10:
I looked into GRBL a little bit, but I am still confused as to how to get it running and what exactly it is.

GRBL is a GCODE interpreter that runs on an Arduino UNO. It can drive four (X, Y, Z, A) Step/Direction stepper drivers. You configure it with the config.h file in the sources. You install it as a library and upload the example sketch to install it on an Arduino.
To save bother with wiring you can get a "CNC Shield" that wires up the stepper drivers and other connectors. You can get an Arduino UNO clone, CNC Shield, and four stepper drivers from Amazon for $17.99: