Hello,
i search for your help with my little project.
I test many thinks but nothing help.
The process should be:
if buttonMat is pressed (low) the motor x move until buttonend is pressed (low) (buttonMat is still pressed)
after that motorx stop and motor y turn 360°. (cut material) after this the mat fall down and the buttonEnd is unpressed.
The process starts from beginn.
My problem is that motor x doesn't move continuously. Its stucks randomly.
I use an arduino uno and a cnc shield v3. Stepper 42mm Kuman Motor 17HD48002H-22B
Can you find the error?
#include <AccelStepper.h>
// for the Arduino Uno + CNC shield V3 + A4988 + FL42STH47-1684A
#define MOTOR_X_ENABLE_PIN 8
#define MOTOR_X_STEP_PIN 2
#define MOTOR_X_DIR_PIN 5
//
#define MOTOR_Y_ENABLE_PIN 9//9
#define MOTOR_Y_STEP_PIN 3//3
#define MOTOR_Y_DIR_PIN 6//6
AccelStepper motor_X(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN);
AccelStepper motor_Y(1, MOTOR_Y_STEP_PIN, MOTOR_Y_DIR_PIN);
//variable
int counter=0;
//def button
const int buttonMat = 12; //y-
const int buttonEnd = 11; //y+
void setup()
{
motor_X.setEnablePin(MOTOR_X_ENABLE_PIN);
motor_X.setPinsInverted(false, false, true);
motor_X.setAcceleration(10000);
motor_X.setSpeed(200);
motor_X.setMaxSpeed(300);
//motor_X.enableOutputs();
//motor_X.disableOutputs();
//
motor_Y.setEnablePin(MOTOR_Y_ENABLE_PIN);
motor_Y.setPinsInverted(false, false, true);
motor_Y.setAcceleration(10000);
motor_Y.setSpeed(500);
motor_Y.setMaxSpeed(500);
//motor_Y.enableOutputs();
//motor_Y.disableOutputs();
///Def Serial Output
Serial.begin(230400);
//Def Button
pinMode(buttonMat,INPUT_PULLUP);
pinMode(buttonEnd,INPUT_PULLUP);
}
void loop()
{
Serial.print("motor disable");
Serial.println();
delay(500);
motor_Y.disableOutputs();
motor_X.disableOutputs();
while (digitalRead(buttonMat)==LOW )
{
if(digitalRead(buttonEnd)==HIGH)
{
Serial.print("material insert and move forward");
Serial.println();
forward();
}
else
{
Serial.print("material reach endstop");
Serial.println();
Serial.print("Caution start cutting in 2.5s");
Serial.println();
delay(2500);
startCut();
counter++;
String strCounter = String(counter);
Serial.print(strCounter + " " + "Parts cutted");
Serial.println();
delay(2500);
}
}
}
void startCut()
{
Serial.print("Danger! Start CUT");
Serial.println();
motor_X.stop();
motor_Y.enableOutputs();
motor_Y.move(200);
motor_Y.runToPosition();
// motor_Y.stop();
}
void forward()
{
motor_X.enableOutputs();
motor_Y.disableOutputs();
motor_X.move(1);
motor_X.runToPosition();
}