I would like to home my stepper without using a limit switch. I have tested this by setting the current on my TB6600 driver down low at 0.5A. Then when the stepper hits a hard stop point, it continues to buzz until the commanded step move runs out. My thought would be to, as example stepper_1.doSteps(-5000);
then let it hit the hard stop. After this happens, then pause for 2 seconds Pause.setTime(2000);
, move forward a little bit stepper_1.doSteps(100);
then stepper_1.setZero();
. My attempts are not working out as I'm sure that I am missing something. I've added the MoToTimer Pause;
at the beginning.
Here is the problem area -
void toRefPoint() { // Homing: move all steppers to ref point and set zeropoint
Serial.println("homing buffer tank..."); { // buffer tank start homing...
stepper_1.setSpeedSteps( 10000, 200 );
stepper_1.doSteps(-5000);
Pause.setTime(2000);
stepper_1.doSteps(100);
stepper_1.setZero();
Serial.println("end point reached - set zero");
while (stepper_1.moving()){
Serial.println(stepper_1.readSteps());
}
}
Serial.println("buffer tank homing finished!");
}
Here is my complete code -
// trying to home without use of limit switch. cw ccw buttons go same way.
#define MAX8BUTTONS // saves RAM because only 4 switches are used
#define MAX_STEPPER 6
#include <MobaTools.h>
const int STEPS_PER_REV = 800;
const int POS_MAX = 20000;
const int FORTY_METER_POSITION = 5000;
const int EIGHTY_METER_POSITION = 10000;
const int ONESIXTY_METER_POSITION = 16000;
//create stepper object ( 800 steps / rev - 1/4 microstep )
// Stepper 1 buffer tank
const byte stepper1_pul = 2;
const byte stepper1_dir = 3;
MoToStepper stepper_1( STEPS_PER_REV, STEPDIR );
// Stepper 2 IPA tank
const byte stepper2_pul = 4;
const byte stepper2_dir = 5;
MoToStepper stepper_2( STEPS_PER_REV, STEPDIR );
const byte enaPin = 7;
MoToTimer Pause;
// buttons must switch to Gnd
enum { buttonZero, buttonCW, buttonCCW, forty_meter_button, eighty_meter_button, onesixty_meter_button } ; // create names for the buttons
const byte buttonPins[] = {22, 23, 24, 26, 27, 28 }; // assign pins to the buttons
const byte buttonCnt = sizeof(buttonPins);
MoToButtons myButton( buttonPins, buttonCnt, 20, 500 );
// limit switch at refpoint
const byte refPin1 = 25; // limit pin stepper 1 homing
const byte refPin2 = 29; // limit pin stepper 2 homing
const byte atRefpoint = LOW; // dependig wether it is a NO or NC switch
void setup() {
Serial.begin(115200); while (!Serial);
// Stepper 1
stepper_1.attach( stepper1_pul, stepper1_dir );
stepper_1.attachEnable( enaPin, 10, LOW ); // Enable active
// Stepper 2
stepper_2.attach( stepper2_pul, stepper2_dir );
stepper_2.attachEnable( enaPin, 10, LOW ); // Enable active
pinMode(LED_BUILTIN, OUTPUT);
pinMode(refPin1, INPUT_PULLUP );
pinMode(refPin2, INPUT_PULLUP );
Serial.println("Starting loop");
}
void loop()
{
myButton.processButtons(); // reading and processing the buttons ( e.g. debouncing and state change detection)
digitalWrite( LED_BUILTIN, digitalRead( refPin1 ) );
// check buttons and react accordingly
if ( myButton.pressed(buttonZero) ) { // home all steppers to zero position
Serial.println(" Find ref point");
toRefPoint();
}
if ( myButton.pressed(buttonCW) ) { // jog slow clockwise direction
Serial.println("Jog CW towards end");
toCWdirection();
}
if ( myButton.pressed(buttonCCW) ) { // jog slow counter clockwise direction
Serial.println("Jog CCW back to 0 ");
toCCWdirection();
}
if ( myButton.pressed(forty_meter_button) ) { // move to 40m position
Serial.println("Move towards the 40M position");
toFortyPoint();
}
if ( myButton.pressed(eighty_meter_button) ) { // move to 80m position
Serial.println("Move towards the 80M position");
toEightyPoint();
}
if ( myButton.pressed(onesixty_meter_button) ) { // move to 160m position
Serial.println("Move towards the 160M position");
toOnesixtyPoint();
}
if ( myButton.released(buttonCW) || myButton.released(buttonCCW) ) {
Serial.println("Stop the stepper");
stepper_1.rotate(0);
}
}
void toRefPoint() { // Homing: move all steppers to ref point and set zeropoint
Serial.println("homing buffer tank..."); { // buffer tank start homing...
stepper_1.setSpeedSteps( 10000, 200 );
stepper_1.doSteps(-5000);
Pause.setTime(2000);
stepper_1.doSteps(100);
stepper_1.setZero();
Serial.println("end point reached - set zero");
while (stepper_1.moving()){
Serial.println(stepper_1.readSteps());
}
}
Serial.println("buffer tank homing finished!");
}
void toFortyPoint() { // buffer tank 40 meter position
stepper_1.setSpeedSteps( 40000, 500 );
stepper_1.moveTo( FORTY_METER_POSITION );
}
void toEightyPoint() { // buffer tank 80 meter position
stepper_1.setSpeedSteps( 40000, 500 );
stepper_1.moveTo( EIGHTY_METER_POSITION );
}
void toOnesixtyPoint() { // buffer tank 160 meter position
stepper_1.setSpeedSteps( 40000, 500 );
stepper_1.moveTo( ONESIXTY_METER_POSITION );
}
void toCWdirection() { // buffer tank jog CW
stepper_1.setSpeedSteps( 5000, 0 );
stepper_1.moveTo(20000);
}
void toCCWdirection() { // buffer tank jog CCW
stepper_1.setSpeedSteps( 5000, 0 );
stepper_1.moveTo(0);
}