I normally don't do things this way but unfortunately I'm under the gun. I have a project that requires using the NEMA 17 stepper motors to turn an undetermined number of times, pause, then reverse to return to the home position. I would also like to be able to use either a momentary on switch to activate.
I don't need to use GRBL. I just need to do this "simple" movement sequence.
I am totally new to Arduino and on a very steep learning curve. I'm not a very good coder or programmer but trying to pick it up as quickly as possible. Thank you in advance for your help and for your patience.
I think the issue is that the sequence is not correct to drive the stepper motor, but I don't know where to address it in the code.
I'm using and UNO with CNC Shield mounted on top with A4988 stepper motor drivers. Here is the link to the kit from Amazon https://www.amazon.com/gp/product/B06XHKSVTG/ref=ppx_yo_dt_b_detailpage_o03_s01?ie=UTF8&psc=1
I have also read the pots may need to be adjusted to produce the correct current but havent found code to produce a constant or know what legs to place probes from multimeter on.
Here is the sample code I'm using to try to just get the motors turning.
#define EN 8
//Direction pin
#define X_DIR 5
#define Y_DIR 6
#define Z_DIR 7
//Step pin
#define X_STP 2
#define Y_STP 3
#define Z_STP 4
//DRV8825
int delayTime=30; //Delay between each pause (uS)
int stps=200;// Steps to move
void 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(Z_DIR,OUTPUT); pinMode(Z_STP,OUTPUT);
pinMode(EN,OUTPUT);
digitalWrite(EN,LOW);
}
void loop(){
step(false,X_DIR, X_STP, stps); //X, Clockwise
step(false,Y_DIR, Y_STP, stps); //Y, Clockwise
step(false,Z_DIR, Z_STP, stps); //Z, Clockwise
delay(2000);
step(true,X_DIR, X_STP, stps); //X, Counterclockwise
step(true,Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true,Z_DIR, Z_STP, stps); //X, Counterclockwise
delay(2000);
}