Arduino stepper motor control with CNC shield and DRV8825

Im using this example to run a setup seen on:

How do i rewrite the code to continuously move in one direction and adjust speed?

#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)n
int stps=6400;// 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(100);

  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(100);

}

It would probably be easier to start with a completely new program because all those delay() and delayMicroseconds() will prevent the program from being responsive.

Have a look at the second program in this Simple Stepper Code. You could add code to it to adjust the value of millisBetweenSteps - perhaps with a potentiometer.

...R
Stepper Motor Basics

Hi flavoni,

programming is something very different from asking for
"what's the cheatcode for game XY to reach final level?

Where somebody can post the cheat-code in one line

you type the code into your PC in and are done.

Programming is completely different.
Programming needs to understand how the code works.

This demo-code is pretty small. If you still have difficulties to understand it
I recommend this introductional tutorial

Arduino Programming Course

It is easy to understand and a good mixture between writing about important concepts
and get you going.

When you learned to ride a bike. Did you start in a halfpipe trying do do backloop-jumps?
Surely not. It's the same thing with learning programming. Though it is not as dangerous as having a crash in a half-pipe.

You will moving up the learning-curve much faster if you take 3 or 4 hours time to work through this introductional tutorial.

The minimum what you have to do that I will answer is:
Asking a concrete question related to your code. This question can be very very very simple it just has to be concrete and a relation to the code posted above.

best regards Stefan

My intentions are to get one project going for an installation, not getting through the arduino basics 101.

Appreciate your metaphores nevertheless...

This is the part that moves the stepper one step in the direction specified by its Direction pin. It sends a pulse to the Step pin of the stepper driver. Put this in loop() and the stepper will spin.

    digitalWrite(stepPin, HIGH);
    delayMicroseconds(delayTime);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(delayTime);

To have more than one stepper move at the same time, add two digitalWrite() lines for each additional stepper.