Homing a stepper with AccelStepper

I have a stepper moving a small tube up and down into bottles via a worm gear.

I have mounted a microswitch at the top of the mount in order to find 0 (home).

This works well, but the stepper speed is very slow like this. Is there a better way to speed it up a bit? I tried doing more steps at a time, which works fine up to about 10 before it jams, but then there is a tolerance of 10 steps.

  stepper.setMaxSpeed(500);
  stepper.setAcceleration(10000);
  while(digitalRead(buttonPin)  == LOW){ //run while the switch isn't pressed
    stepper.runToNewPosition(stepper.currentPosition() - 1); //Move up
  } 
  stepper.setCurrentPosition(0);
  stepper.setMaxSpeed(800);
  stepper.setAcceleration(400);

Need to see complete pgm, do you really need to home stepper on every stroke?

Don't use runToNewPosition(). Use run(). That will take a step if it's time for a step. Then you can check the switch again.

For more accurate homing, go home fast until it hits the switch, then back up until the switch releases and go home slowly.

MorganS: For more accurate homing, go home fast until it hits the switch, then back up until the switch releases and go home slowly.

That is good advice ONLY if the motor can go past the switch without causing damage. And it is a good idea to arrange the switch so that the motor can go past it safely.

...R

My 3D printer does that same homing algorithm. It doesn't go past the switch but it may bend the lever a bit more the first time.