[Step motor control]

Hello, I am using Arduino UNO to control a NEMA 23 Step motor. My driver is M542 from Leadshine Technology.

Both user's manual attached.

I'm using Bipolar serie conection on my step motor

I want a code to do one complete revolution and then stop

I have already tried some step motor libraries and didn't work fine, so now I'm trying to write my own code:

int pulPin = 8;
int dirPin = 9;
int enblPin = 13;

byte loops = 0;

void setup() {
  
  // Definir pinos como saída de dados (output)
  pinMode(pulPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enblPin, OUTPUT);

  // Definições iniciais
  digitalWrite(pulPin, LOW);
  digitalWrite(enblPin, LOW);

  // Definir direção  (LOW - Anti horário | HIGH - Horário)
  digitalWrite(dirPin, LOW);
 
  // Comuniação portal serial
  Serial.begin(9600);

  // Definição inicial 2
  digitalWrite(enblPin, HIGH);
  delay(100);
  digitalWrite(enblPin, LOW);

  while(loops < 256)
 {
  // Comando de pulsos
   
  digitalWrite(pulPin, HIGH);
  digitalWrite(pulPin, LOW);

  // Delay entre pulsos = frequência = Velocidade de giro do disco
  delay(1);

  loops ++;
}

}

void loop() { 


}

My problem is: I'm controling the number of pulses sent to motor through line:

while(loops < 256)
 {
  // Comando de pulsos
   
  digitalWrite(pulPin, HIGH);
  digitalWrite(pulPin, LOW);

  // Delay entre pulsos = frequência = Velocidade de giro do disco
  delay(1);

  loops ++;
}

But I can't find a especific number to put at "while(loops < _____ )

If I put 255, motor starts to spin and stops right after I started my code (It spins aproximately 1º).

If I put 256, motor starts to spin and doesn't stop anymore.

Can anyone help me? I'm a beginner at Arduino.

arquivo_46.pdf (523 KB)

M542d.pdf (218 KB)

These links may help

Stepper Motor Basics
Simple Stepper Code

...R