Stepper motor - Arduino alternatives/accuracy improvement

The way the program is coded means that a timing problem would cause the pulse to be delayed, not skipped.

if (micros() >= next_Micros)

But the graph does suggest it is being skipped, as if the next tick time is reset without executing the code that does the pulse, and I can’t see how that could happen.

However the pattern is consistent with the logging device missing the step, rather than any problem with the code. This could be revealed by adjusting the pulse HIGH time to a much longer delay, such as half the total period (6310uS) to create a square wave rather than a pulse. In that case a problem with the logging would be revealed as a delay rather than a miss. (DRV8825 (and probably any other driver) is edge triggered)).

I have previously stated that the code does not have interrupts that could be causing a delay in the loop - this is not correct. You have started the serial interface even though isn’t used, and that will enable an interrupt that could possibly get triggered. Remove the Serial.begin() line and see if that makes a difference.

But it is probably worthwhile to create a new version of the code as James suggests. Another option is to use interuupts and the timer library.
Arduino Workshop - Chapter 5 - Interrupts - Video Tutorial Australia
You would do this without including any other part of your required functionality: purely to see what is needed to get a reliable, smooth movement.

2 Likes