Stepper Motor frequently stopping

So i am moving a stepper while logging data over serial! Every time I am logging Data the Stepper stops, because the logging needs a bit longer then the Stepdelay. Now the stepper makes a “clack” sound every 0.5 seconds. It doesnt really bother me, but i am concerned that it might damge the steppers.

Is this so?

No damage to stepper. But your program is doing it the wrong way.

Without seeing your program it is impossible to provide advice.

...R
Stepper Motor Basics
Simple Stepper Code

My programm is pretty long, but it basicly gives every 10 microseconds an Highpulse to the stepperdriver Step pin. But when I log data it takes longer than 10 microseconds so there is a "longer" stepp Interval, which stops the motor. I know I could drive the Stepper with Interupts, but I didnt found a good library and I didnt find a simple way to implement a "slelfmade" Interupt function.
If somebody knows a library for this purpose or a simple way I would be really thankfull!

Thank You!

If you don’t post your code, how can we improve it?

You could read up on timer interrupts in the datasheet for the Arduino chip (you didn’t say which one). Did you think to search for timer libraries?

Okay So here is the function in my code which moves the Motor:

float CalcLoadValue() {
  float lV = (loadCell.averageValue(1) - tareValue) / gainValue;
  if (InvertMeasurments) {
    lV = lV * -1;
  }
  return lV;
}

void Move(int distance) {  //This function moves the Maschine the given amount of mm
  digitalWrite(enablePin, LOW);
  if (distance < 0) {
    digitalWrite(directionPin, HIGH);
  } else {
    digitalWrite(directionPin, LOW);
  }
  long Steps = MoveStepsMM * abs(distance);

  long LastMillis = millis();

  for (long i = 0; i <= Steps; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(stepPin, LOW);
    if(millis()-LastMillis>=500){
      Serial.println(CalcLoadValue()){
        LastMillis=millis();
      }
    }
  }
  delay(100);
  digitalWrite(enablePin, HIGH);
}

I use an Arduino Micro with drv8825 Stepper and Nema17 motors

Got a syntax error here.

      Serial.println(CalcLoadValue()){

At what frequency are you intending to drive step pulses? What is the motor, driver and microstepping settings?

Are you allowing for accleration/deceleration?

Oh! I simplified the function because it was emeded in another bigger oney and made an mistake...

My microstepping settings is 1/16 and the step pulses are 10 microseconds...
I dont have acceleration in my code... what would be the advantage of it? (It isnt really a Problem if the Stepper misses a few Steps)

probierer:
Okay So here is the function in my code which moves the Motor:

Please help us to help you ... post a complete program.

It doesn't have to be the entire long program, a shortened version that illustrates the problem will be better.

...R

So here is an Example Code:

#include "hx711.h"

/////Library Config
Hx711 loadCell(A1, A2);

////// PIN definitions
int directionPin = 2;
int stepPin = 3;
int enablePin = 8;

////// Config
float gainValue = -875.7 * (1 - 0.001); //CALIBRATION FACTOR
float tareValue;
bool InvertMeasurments = true;
long MoveStepsMM = 39000;

void setup() {
  // Serial
  Serial.begin(9600);
  
  // Load Cell
  tareValue = loadCell.averageValue(32);

  // Stepper
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  digitalWrite(directionPin, LOW);
  digitalWrite(stepPin, LOW);
  digitalWrite(enablePin, HIGH);

  Move(20);
}

void loop(){};



float CalcLoadValue() {
  float lV = (loadCell.averageValue(1) - tareValue) / gainValue;
  if (InvertMeasurments) {
    lV = lV * -1;
  }
  return lV;
}

void Move(int distance) {  //This function moves the Maschine the given amount of mm
  digitalWrite(enablePin, LOW);
  if (distance < 0) {
    digitalWrite(directionPin, HIGH);
  } else {
    digitalWrite(directionPin, LOW);
  }
  long Steps = MoveStepsMM * abs(distance);

  long LastMillis = millis();

  for (long i = 0; i <= Steps; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(stepPin, LOW);
    if (millis() - LastMillis >= 500) {
      Serial.println(CalcLoadValue());
      LastMillis = millis();
    }
  }
  delay(100);
  digitalWrite(enablePin, HIGH);
}

Note: Increasing the Baudrate wont work because I am sending the data to an Ble Module which has a max baudrate of 9600

Your code seems to be a bit mixed up. For example, why are you calling CalcLoadValue() in a function called Move()?

If you separate things it is generally much easier to find a solution.

What is your desired interval between steps (in millisecs or microsecs) ?

How long does a single call to CalcLoadValue() take (in microsecs)?

…R

probierer:
Oh! I simplified the function because it was emeded in another bigger oney and made an mistake...

My microstepping settings is 1/16 and the step pulses are 10 microseconds...

I'll repeat my question: what frequency are you expecting to drive step pulses - do you understand "frequency"?

I dont have acceleration in my code... what would be the advantage of it? (It isnt really a Problem if the Stepper misses a few Steps)

It depends what step-rate you are trying to move the motor at, and what the motor is, but normally without acceleration a stepper will stall or misbehave.

As I said I am sending every 10microseconds 1 puls so the frequenzy would be 100Hz. I would like to keep this frequency! I dont think I need acceleration since everything works fine when using the Stepper wihout Serial.println....

What is your desired interval between steps (in millisecs or microsecs) ?

10 microseconds

How long does a single call to CalcLoadValue() take (in microsecs)?

Around 200 microseconds

Then you have arrived at an impasse. You cannot do 200µsecs of work in 10µsecs.

You might be able to set up a HardwareTimer to produce step pulses in the background at 10µsec intervals.

Or maybe you need two Arduinos.

...R

Okay thank you!
I dont think its worth the work, since it works fine and the motors dont get damaged!

Thanks Everyone!