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