Homing stepper motors within Accelstepper library

Hi There,

I've been unable to find any information out there that will cleared up the issues I'm having. Hopefully someone will have some tips to share. Thanks in advance. I am using four stepper motors with a driver (Gecko G540) and have been programming them through the Accelstepper library. I have the motors operating as I'd like within the Void Loop. The issue I am having is with the homing and zeroing of the motors at the beginning of the program, which I think would be best located within the Void Setup?

I've included a paired down version of the code I have going at the moment. I've tried many variations in the coding of this - changing the Controlling Structures, values, and other parts. What I am looking to do is to start everything by sending the motors back to homing switches (one at a time or if possible at the same time). Once the motor moves the assembly and triggers the switch it should read home, stop the motor, and reset the currentPosition to 0.

The motors jitter and/or don't move at all depending on the code I've had. With some attempts I've grounded the switch and the program does move into the Void Loop but the motor never did move before triggering the switch.

Here's what I've got. Suggestions would be appreciated.

// AccelStepper.h Copyright (C) 2009 Mike McCauley
// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper1(1,2,3); // driver, step 2, dir 3
int homePin = 10;

void setup()

{
pinMode(homePin, INPUT); // limit switch to GND
digitalWrite(homePin, HIGH); // pullup on Pin

stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);

while(digitalRead(homePin) == HIGH){ // switch not yet triggered/home
stepper1.move(-stepper1.currentPosition()); // then continue to move in anticlockwise directio
}
stepper1.setCurrentPosition(0); // once homePin == LOW, reset currentPosition to 0

}

void loop()
{
if (stepper1.distanceToGo() == 0)
stepper1.move(100);
delay(500);

stepper1.run();
}

Homing is something you might want to do at any time - crash into something... Would be better to have it as a function that can be called as needed.

There are 2 choices for homing a stepper motor -

#1 - make a move long enough to traverse the whole length of travel and run into a stop. When the stop is hit the it just sits there and hums ubtil the move times out. You Are at HOME.

#2 - have a limit switch - travel at high speed until the limit trips. revers some fixed number of steps. Move back towards the limit at low speed and stop when the limit trips. either this is home or some offset from home. It can be useful to have the home position some number of steps back from the home switch and keep track of position in software, using the switch as a limit. Writing the code to do this is fairly trivial, rapid steps until the limit. reverse some arbitrary amount. step slow until the limit. HOME!