Hello Community,
I am building up a module comparable to a H-Bot, but rather simple. There is just one stepper motor running for the x-Axis and another for y.
This is how I want to just let the belt drive drive around a sensor stopping every few centimeters to let the sensor measure at each point.
I have already put together a sketch that works:
#define EN 8
//Direction pin
#define X_DIR 5
#define Y_DIR 6//Step pin
#define X_STP 2
#define Y_STP 3#define MOTOR_X_ENABLE_PIN 8
#define MOTOR_X_STEP_PIN 2
#define MOTOR_X_DIR_PIN 5#define MOTOR_Y_ENABLE_PIN 8
#define MOTOR_Y_STEP_PIN 3
#define MOTOR_Y_DIR_PIN 6#define endstop_x1 9
#define endstop_y1 10//DRV8825
int delayTime=300; //Delay between each pause (uS)
int stps=6400;// Steps to movevoid step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup(){
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);
}
void loop(){
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
delay(1000);
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
delay(1000);
step(false, X_DIR, X_STP, stps); //X, Clockwise
delay(1000);
}
The only problem now is that I want to integrate 4 Endstoppers to the CNC Shield. The next step would be now to instead of following a certain route, the sensor should follow the x-axis in one direction until a end stop is reached. Then it should move one step on the y-axis and start on the x-axis again in the other direction until it reaches an endstop again.
In the code I just want to have it like this:
step(true, X_DIR, X_STP, stps); //X, Counterclockwise
if Endstop is hitted
step (false, Y-DIR, Y_STP, stps)
step false, X_DIR, X_STP, stps)
I have looked up a couple of possibilities, but I couldnt find any apropriate solution to include the Endstops into the Arduino sketch so far. Can you assist me somehow? I imagined it to be not that hard, but if anyone has some experiences with endstops it might be solved rather quickly. Thanks in advance!