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 Pinstepper1.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();
}