Hi all
Hardware
Arduino UNO
CNC Shield
2 X NEMA 17 Steppers
2 X drv8825 Stepper Drivers
4 X End Stops
4 X LDR
2 X Worm Gear Drives
The problem I am having is the Steppers pulse each time the code does a loop like the steppers are tuning on and off.
Code
#include <arduino.h>
#include "BasicStepperDriver.h"
// Motor steps per revolution. Most steppers are 200 steps or 1.8 deg_mrees/step
#define MOTOR_STEPS 200
#define RPM 100
// 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 32
//Set max rotation for angle and deg_mrees
//#define turn 360
#define ang_max 90
#define deg_max 180
#define ang_min 0
#define deg_min 0
// All the wires needed for full functionality
#define DIR_X 5
#define STEP_X 2
#define DIR_Y 6
#define STEP_Y 3
#define ENABLE 8
// LDR pin connections
// name = analogpin;
int ldrt = A3; //ldR top coolen Pin - Gray on Sencor
int ldrb = A0; //ldR Bottom Abort pin - Blue on Sencor
int ldrl = A1; //ldR left Hold pin - White on Sensor
int ldrr = A2; //ldR Right Resume pin - Broun on Sencor
int est = 9; // end stop top X+
int esb = 10; // end stop botom Y+
int esl = 11; // end stop left Z+
int esr = 12; // end stop right SpnEn
int ang;
int deg;
int incomingByte = 0; // for incoming serial data
int degr;
int ag;
BasicStepperDriver stepper_X(MOTOR_STEPS, DIR_X, STEP_X, ENABLE);
BasicStepperDriver stepper_Y(MOTOR_STEPS, DIR_Y, STEP_Y, ENABLE);
void setup() {
Serial.begin(115200);
stepper_X.begin(RPM, MICROSTEPS);
stepper_Y.begin(RPM, MICROSTEPS);
}
void loop() {
int tp = analogRead(ldrt); // Read top LDR
int btm = analogRead(ldrb); // Read Bottom LDR
int estp = digitalRead(est); // Read Top End Stop
int esbt = digitalRead(esb); // Read Bottom End Stop
int eslf = digitalRead(esl); // Read Left End Stop
int esrt = digitalRead(esr); // Read Right End Stop
int dtime = 50; // Delay
int avtb = (tp - btm) / 2; // average value top Bottom
if ((avtb >= 3) && (ang <= ang_max))
{
if (ang <= ang_max) ang = ang + 1;
if ((ang <= ang_max) && (ang >= ang_min))
{
stepper_X.enable();
stepper_X.rotate(32);
}
}
if ((avtb <= -3) && (ang >= ang_min))
{
if (ang >= ang_min) ang = ang - 1;
if ((ang >= ang_min) && (ang <= ang_max))
{
stepper_X.enable();
stepper_X.rotate(-32);
}
}
int lt = analogRead(ldrl); // Read left LDR
int rt = analogRead(ldrr); // Read Right LDR
int avlr = (lt - rt) / 2; // average value Left Right
if ((avlr > 3) && (deg <= deg_max))
{
if (deg <= deg_max) deg = deg + 1;
if ((deg <= deg_max) && (deg >= deg_min))
{
stepper_Y.enable();
stepper_Y.rotate(32);
stepper_Y.disable();
}
}
if ((avlr < -3) && (deg >= deg_min))
{
if (deg >= deg_min) deg = deg - 1;
if ((deg >= deg_min) && (deg <= deg_max))
{
stepper_Y.enable();
stepper_Y.rotate(-32);
stepper_Y.disable();
}
}
// Check End Stops
if (estp == 0)
{
stepper_X.enable();
stepper_X.rotate(32*6);
stepper_X.disable();
ang = 0;
}
if (esbt == 0)
{
stepper_X.enable();
stepper_X.rotate(-32*6);
stepper_X.disable();
ang = 90;
}
if (eslf == 0)
{
stepper_Y.enable();
stepper_Y.rotate(32*6);
stepper_Y.disable();
deg = 0;
}
if (esrt == 0)
{
stepper_Y.enable();
stepper_Y.rotate(-32*6);
stepper_Y.disable();
deg = 180;
}
Serial.print(ang);
Serial.print(" ");
Serial.print(estp);
Serial.print(" ");
Serial.print(esbt);
Serial.print(" ");
Serial.print(avtb);
Serial.println(" ");
if ((avtb < 3) && ( avtb > -3)) stepper_X.disable();
delay(dtime);
}
At this point I am only working with the X Stepper (ang).
When avtb is between -3 and 3 the stepper_X should be disabled but still pulses.
Any sugestions