Why is my homing so slow? Accelstepper

I’ve done something wrong and screwed up the speed at which the homing function operates. It just crawls, yet I set it to the same speed as main movement, which is much quicker.

[code]
// Start #1 for parsing serial

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing
// variables to hold the parsed data
float XCoordinate = 0;
float YCoordinate = 0;
float ZCoordinate = 0;
float R, S, T;
float AngleThetaOne;
float AngleThetaTwo;
float AngleThetaThree;
char messageFromPC[numChars] = {0};

int StepsPerDegreeOne = 88; //calibrate steps per degree of Theta One
int StepsPerDegreeTwo = 88; // calibrate steps per degree for Theta Two
int StepsPerDegreeThree = 88; // calibrate steps per degree for Theta Three

float J1position = 0;
float J2position = 0;
float J3position = 0;

int J1move = 0;
int J2move = 0;
int J3move = 0;

int X = 0;
int Y = 0;
int Z = 0;


float J1newPosition = 0;
float J2newPosition = 0;
float J3newPosition = 0;

int F = 0, f;
float Q1, W1, E1;
float Q0, Q4, W0, W4, E2;
float Q3, W3, E3;

boolean newData = false;

// end #1


// MultiStepper.pde
// -*- mode: C++ -*-
// Use MultiStepper class to manage multiple steppers and make them all move to
// the same position at the same time for linear 2d (or 3d) motion.

#include <AccelStepper.h>
#include <MultiStepper.h>

// EG X-Y position bed driven by 2 steppers
// Alas its not possible to build an array of these with different pins for each :-(
AccelStepper J1axis(1, A0, A1);
AccelStepper J2axis(1, A6, A7);
AccelStepper J3axis(1, 46, 48);

// Up to 10 steppers can be handled as a group by MultiStepper
MultiStepper steppers;

// Define the Pins used

// limit switches

// J1/x limit min on ramps 1.4
const int J1calPin = 3;

// J2/y limit min on ramps 1.4
const int J2calPin = 14;

// J3/z limit min on rmaps 1.4
const int J3calPin = 18;

// Stepper Travel Variables

int J1move_finished = 1; // Used to check if move is completed
long J1initial_homing = -1; // Used to Home Stepper at startup

int J2move_finished = 1; // Used to check if move is completed
long J2initial_homing = -1; // Used to Home Stepper at startup

int J3move_finished = 1; // Used to check if move is completed
long J3initial_homing = -1; // Used to Home Stepper at startup


void setup() {
  Serial.begin(9600);

  // my addition to set x,y, z enable pins to output
  pinMode (38, OUTPUT); // x enable pin
  pinMode (56, OUTPUT); // y enable pin
  pinMode (62, OUTPUT);  // z enable pin

  digitalWrite (38, LOW);  // x enable
  digitalWrite (56, LOW);  // y enable
  digitalWrite (62, LOW);  // z enable

  pinMode(J1calPin, INPUT_PULLUP);
  pinMode(J2calPin, INPUT_PULLUP);
  pinMode(J3calPin, INPUT_PULLUP);


  // end of my addition

  // Configure each stepper
  J1axis.setMaxSpeed(3000);
  J2axis.setMaxSpeed(3000);
  J3axis.setMaxSpeed(3000);

  J1axis.setCurrentPosition(0);
  J2axis.setCurrentPosition(0);
  J3axis.setCurrentPosition(0);

  // Then give them to MultiStepper to manage
  steppers.addStepper(J1axis);
  steppers.addStepper(J2axis);
  steppers.addStepper(J3axis);


  //  Set Max Speed and Acceleration of each Steppers at startup for homing

  J1axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J1axis.setAcceleration(3000.0);  // Set Acceleration of Stepper

  J2axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J2axis.setAcceleration(3000.0);  // Set Acceleration of Stepper

  J3axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J3axis.setAcceleration(3000.0);  // Set Acceleration of Stepper


  // Start Homing procedure of Stepper Motor at startup

  Serial.println("Stepper is Homing . . . . . . . . . . . ");

  while (digitalRead(J1calPin)) {  // Make the Stepper move CCW until the switch is activated
    J1axis.moveTo(J1initial_homing);  // Set the position to move to
    J1initial_homing++;  // increase by 1 for next move if needed
    J1axis.run();  // Start moving the stepper
    delay(5);
  }

  J1axis.setCurrentPosition(0);  // Set the current position as zero for now
  J1axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J1axis.setAcceleration(3000.0);  // Set Acceleration of Stepper
  J1initial_homing = 1;

  while (!digitalRead(J1calPin)) { // Make the Stepper move CW until the switch is deactivated
    J1axis.moveTo(J1initial_homing);
    J1axis.run();
    J1initial_homing--;
    delay(5);
  }

  J1axis.setCurrentPosition(0);
  Serial.print("J1 Homing Completed   ");
  J1axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Faster for regular movements)
  J1axis.setAcceleration(3000.0);  // Set Acceleration of Stepper

  //J2 homing

  while (digitalRead(J2calPin)) {  // Make the Stepper move CCW until the switch is activated
    J2axis.moveTo(J2initial_homing);  // Set the position to move to
    J2initial_homing--;  // Decrease by 1 for next move if needed
    J2axis.run();  // Start moving the stepper
    delay(5);
  }

  J2axis.setCurrentPosition(0);  // Set the current position as zero for now
  J2axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J2axis.setAcceleration(3000.0);  // Set Acceleration of Stepper
  J2initial_homing = 1;

  while (!digitalRead(J2calPin)) { // Make the Stepper move CW until the switch is deactivated
    J2axis.moveTo(J2initial_homing);
    J2axis.run();
    J2initial_homing++;
    delay(5);
  }

  J2axis.setCurrentPosition(0);
  Serial.print("J2 Homing Completed   ");
  J2axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Faster for regular movements)
  J2axis.setAcceleration(3000.0);  // Set Acceleration of Stepper

  // J3 homing

  while (digitalRead(J3calPin)) {  // Make the Stepper move CCW until the switch is activated
    J3axis.moveTo(J3initial_homing);  // Set the position to move to
    J3initial_homing--;  // Decrease by 1 for next move if needed
    J3axis.run();  // Start moving the stepper
    delay(5);
  }

  J3axis.setCurrentPosition(0);  // Set the current position as zero for now
  J3axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  J3axis.setAcceleration(3000.0);  // Set Acceleration of Stepper
  J3initial_homing = 1;

  while (!digitalRead(J3calPin)) { // Make the Stepper move CW until the switch is deactivated
    J3axis.moveTo(J3initial_homing);
    J3axis.run();
    J3initial_homing++;
    delay(5);
  }

  J3axis.setCurrentPosition(0);
  Serial.print("J3 Homing Completed");
  J3axis.setMaxSpeed(3000.0);      // Set Max Speed of Stepper (Faster for regular movements)
  J3axis.setAcceleration(3000.0);  // Set Acceleration of Stepper

  //addition

  // after homing, move off home position
  J1newPosition = 9680;
  J2newPosition = 500;
  J3newPosition = 500;

  // message for input

  Serial.println();
  Serial.println("Input the Coordinates of X,Y,Z in format of <X,Y,Z>");

  // end addition

}

[/code]

EDIT: I believe I have found the answer. It was the delay (5) at the end of each homing loop.

    delay(5);

There's your problem.

AccelStepper manages its own timing. You set speed, acceleration and a target position and call run() very frequently. It will takes steps as needed to reach the destination within the speed and acceleration limits you gave it.

By telling it to move one step, it starts accelerating towards that position. You call run() once and it will probably take a step. But then you tell it to move another step. It must acccelerate again. So it's always starting at the slowest speed.

For homing, tell it to move a million steps. Cal run() then check the switch. Do that a few thousand times. When the switch is hit, then call for stop() and keep calling run() so it can decellerate to a smooth stop. If you want to find the home switch more precisely, then start taking slow steps until the switch releases. If it steps all the way to negative one million, then you know there's a problem with the switch.

Hard to believe but this is the problem, I guess

"Serial.begin(9600);"

Keep serial port speed as high as possible because low serial port speed slowdown everything indirectly.

"Serial.begin(115200);"

works fine for me (I'm working with the 17HS3430 stepper motor)

P.S. Do not forget to change the speed also in the monitor window