Aruino UNO, CNC Shield, A4988 Driver, stepeer, Without GRBL

Hello,
I come to you for help.
I’m doing a little program on an Arduino UNO to run a stepper motor, but it still does not work.
Hardware:

Arduino UNO
CNC Shield3
A4988
Stepper motor 1.8 deg / step (1.68A Rs = 0.1hom) ==> Vref = 0.94V
ATX PC power supply

For testing, I used GRBL, XYZ axes function very well, I want to do it, my own program and not used the GRBL.

thank you.
Sorry for my English

I do not know where I made an error.

My Code:

//STEP
#define X_STEP 2  // Uno Digital Pin 2==>X_STEP
//DIRECTION
#define X_DIR 5  // Uno Digital Pin 5==>X_DIRECTION
//Other
#define EN 8  // Uno Digital Pin 8==>Enabele

void step();

void setup() {
pinMode(X_DIR, OUTPUT); pinMode(X_STEP, OUTPUT);
pinMode (EN, OUTPUT); //
//digitalWrite (EN, LOW); //EN=0??
}

void loop() {
digitalWrite (EN, HIGH);//EN=1??
step (false, X_DIR, X_STEP, 200);
delay (2500);
step (true, X_DIR, X_STEP, 200);
}

void step(boolean dir, byte dirPin, byte stepPin, int N_steps){
digitalWrite (dirPin, dir);
delay (50);
for (int i = 0; i<N_steps; i++)
{
digitalWrite (stepPin, HIGH);
delayMicroseconds (500);
digitalWrite (stepPin, LOW);
delayMicroseconds (500);
}
}

SmErT: but it still does not work.

That tells us nothing useful.

Have a look at this Simple Stepper Code - especially the second example.

...R Stepper Motor Basics

try this - here is connected only motor on axis Z. It is simple and working. You must add two buttons (i have it on pins 50 and 51)

#define EN 8
byte directionPin = 7;
byte stepPin = 4;
byte buttonCWpin = 50;
byte buttonCCWpin = 51;
boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 20; // milliseconds

void setup() { 
  pinMode(EN, OUTPUT);
  digitalWrite(EN, LOW);
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(buttonCWpin, INPUT_PULLUP);
  pinMode(buttonCCWpin, INPUT_PULLUP);
  
}

void loop() { 
 curMillis = millis();
 readButtons();
 actOnButtons();
}

void readButtons() {
 buttonCCWpressed = false;
 buttonCWpressed = false;

 if (digitalRead(buttonCWpin) == LOW) {
 buttonCWpressed = true;
 }
 if (digitalRead(buttonCCWpin) == LOW) {
 buttonCCWpressed = true;
 }
}

void actOnButtons() {
 if (buttonCWpressed == true) {
 digitalWrite(directionPin, LOW);
 singleStep();
 }
 if (buttonCCWpressed == true) {
 digitalWrite(directionPin, HIGH);
 singleStep();
 }
}

void singleStep() {
 if (curMillis - prevStepMillis >= millisBetweenSteps) {
 prevStepMillis += millisBetweenSteps;
 digitalWrite(stepPin, HIGH);
 digitalWrite(stepPin, LOW);
 }
}

SmErT:
Hello,
I come to you for help.
I’m doing a little program on an Arduino UNO to run a stepper motor, but it still does not work.
Hardware:

Arduino UNO

CNC Shield3
A4988
Stepper motor 1.8 deg / step (1.68A Rs = 0.1hom) ==> Vref = 0.94V
ATX PC power supply



For testing, I used GRBL, XYZ axes function very well, I want to do it, my own program and not used the GRBL.

thank you.
Sorry for my English

I do not know where I made an error.

You are expecting a physical object to accelerate instantly to a high speed - doesn’t happen.
Speed must be ramped up and down or your motor will simply skip steps. Suggest you start
by trying out the AccelStepper library.

Oh, and indent your code if you want anyone else to bother reading it…

Thenk's for your hele i see what you sent me.

Hi, Thank you all
its worck

Here is the code:

#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

AccelStepper motor_X(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN); 


void setup()
{
  motor_X.setEnablePin(MOTOR_X_ENABLE_PIN);
  motor_X.setPinsInverted(false, false, true);
  motor_X.setAcceleration(20);  
  motor_X.move(200);
  motor_X.setMaxSpeed(100);
  //motor_X.setSpeed(100);
  motor_X.enableOutputs();
}

void loop()
{
  motor_X.run();
}

Even with stepper.h it worked I forgot the Enable Pin 8