Arduino Mega limit switches

Hello,

I have a ramps 1.4 board connected to a 2650. I want to create a homing routine for 3 NEMA 17 stepper motors. Basically, on the first run, I want to drive the motor all the way until the limit switch is made, and then move to the "zero" position. The part I need help with is the first one, creating a loop to drive until the limit switch is made, and then stopping, so i can execute the rest of my code. Anyone have advice?

We can't see your code, or what kind of stepper drivers you are using. So, we can only offer advice.

You move until a limit switch is pressed using a while loop that terminates when the switch is pressed. In the body of the while statement, you step once, in the direction that moves whatever towards the limit switch.

I am using a Ramps 1.4 control panel on my 2650 with A4988 drivers, 3 pin limit switches, I don't yet have any code to do this. I have some code that's just generally moving the motors, but nothing to do this yet

Where are you going with this? What is going to be the core library driving the steppers? AccelStepper? GRBL?

I'd just use a variant of a button-turns-on-LED sketch to ensure that the switches are wired correctly, then dive into the big library that's going to be doing the real work.

This is the code I am using, just simply telling steppers to rotate certain degrees. Id like to create a loop that rotates a stepper until the end stop is made, but I do not know how to set up the endstop in the code so i could use it.

/*

  • Simple demo, should work with any driver board
  • Connect STEP, DIR as indicated
  • Copyright (C)2015-2017 Laurentiu Badea
  • This file may be redistributed under the terms of the MIT license.
  • A copy of this license has been included with this distribution in the file LICENSE.
    */
    #include <Arduino.h>
    #include "BasicStepperDriver.h"

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 50

// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 2
#define MICROSTEPS_2 1

// All the wires needed for full functionality
#define DIR_x 55
#define STEP_x 54
//Uncomment line to use enable/disable functionality
#define ENABLE_x 38

// All the wires needed for full functionality
#define DIR_y 61
#define STEP_y 60
//Uncomment line to use enable/disable functionality
#define ENABLE_y 56

// All the wires needed for full functionality
#define DIR_z 48
#define STEP_z 46
//Uncomment line to use enable/disable functionality
#define ENABLE_z 62

// All the wires needed for full functionality
#define DIR_e0 28
#define STEP_e0 26
//Uncomment line to use enable/disable functionality
#define ENABLE_e0 24

// All the wires needed for full functionality
#define DIR_e1 34
#define STEP_e1 36
//Uncomment line to use enable/disable functionality
#define ENABLE_e1 30

// 2-wire basic config, microstepping is hardwired on the driver
//BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);

//Uncomment line to use enable/disable functionality
BasicStepperDriver stepper_x(MOTOR_STEPS, DIR_x, STEP_x, ENABLE_x);
BasicStepperDriver stepper_y(MOTOR_STEPS, DIR_y, STEP_y, ENABLE_y);
BasicStepperDriver stepper_z(MOTOR_STEPS, DIR_z, STEP_z, ENABLE_z);
BasicStepperDriver stepper_e0(MOTOR_STEPS, DIR_e0, STEP_e0, ENABLE_e0);
BasicStepperDriver stepper_e1(MOTOR_STEPS, DIR_e1, STEP_e1, ENABLE_e1);

void setup() {
stepper_x.begin(RPM, MICROSTEPS_2);
stepper_y.begin(RPM, MICROSTEPS);
stepper_z.begin(RPM, MICROSTEPS);
stepper_e0.begin(RPM, MICROSTEPS);
stepper_e1.begin(RPM, MICROSTEPS);
}

void loop() {

// energize coils - the motor will hold position
stepper_x.enable();
stepper_y.enable();
stepper_z.enable();
stepper_e0.enable();
stepper_e1.enable();
stepper_y.rotate(720);
delay (1000);

/*
stepper_x.rotate(3601.5875);
delay(500);
stepper_x.rotate(-360
1.5875);

*/

/*

  • Moving motor one full revolution using the degree notation
    /
    /

    stepper_x.rotate(180);
    stepper_y.rotate(90);
    delay (250);
    stepper_x.rotate(-180);
    stepper_y.rotate(-90);
    delay (250);
    stepper_z.rotate(360);
    delay(1000);
    stepper_z.rotate(-360);
    stepper_e0.rotate(180);
    stepper_e1.rotate(180);
    */

/*

  • Moving motor to original position using steps
    */

//stepper.move(-MOTOR_STEPS*MICROSTEPS);

// pause and allow the motor to be moved by hand
stepper_x.disable();
stepper_y.disable();
stepper_z.disable();
stepper_e0.disable();
stepper_e1.disable();

delay(500);
}

No tags == no code.

Do we have to guess how you wired the switches? A hand-drawn schematic is OK.