Hello forum
I am in the process of using an Arduino UNO + CNC Shield + 3 x A4988 drivers + 3 Stepper Motors. I have limit switches assigned to each of the axis as well.
Thanks to the guidance and tutorials in this forum, I've managed to program the movement of the motor routines.
What i currently need help with is how to connect buttons to the CNC shield.
Button 1:
On press i would like to pause the logic/interrupt the program. Pressing it again would resume the program
Button 2:
Pressing it would reverse the movement of the motors till the trigger the limit switch, after which they will stop. Sort of a go-to-home/reset button.
Have shared my wip code here.
To give you a background, i am new to arduino. Have taken this up to address a specific automation requirement in my factory which is to wind tape around a sheet of acrylic.
// simple stepper motor control
#define EN 8 // stepper motor enable
#define X_DIR 5 // x axis direction control
#define Y_DIR 6 // y axis direction control
#define Z_DIR 7 // z axis direction control
#define X_STP 2 // x axis step control
#define Y_STP 3 // y axis step control
#define Z_STP 4 // z axis step control
const int limitPin = 9;
long int stps=15;
int delayTime=15;
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(50);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(8);
digitalWrite(stepperPin, LOW);
delayMicroseconds(800);
}
}
void setup (){
// setup stepper motor I/O pin to output
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);
pinMode(limitPin, INPUT_PULLUP);
}
void loop (){
// 200 steps per turn
while( digitalRead(limitPin) == LOW)
step(false, X_DIR, X_STP, 180);
step(false, Y_DIR, Y_STP, 500);
step(false, Z_DIR, Z_STP, 200);
delay(1000);
step(false, X_DIR, X_STP, 1800);
step(false, Y_DIR, Y_STP, 500);
step(false, Z_DIR, Z_STP, 200);
delay(1000);
if( digitalRead(limitPin) == LOW)
step(true, X_DIR, X_STP, 1800);
step(true, Y_DIR, Y_STP, 200);
step(true, Z_DIR, Z_STP, 200);
delay(1000);
}
