Hi @shigs555 ,
if you read your sketch carefully you will find this:
{while(digitalRead(buttonPin) ==LOW)
myStepper.step(motDir * 1);
delayMicroseconds(dt);
I think that the curly bracket is at the wrong place here. It should be on the right hand side:
while(digitalRead(buttonPin) ==LOW){
myStepper.step(motDir * 1);
delayMicroseconds(dt);
Otherwise only the line " myStepper.step(motDir * 1);" would be inside the while loop().
Feel free to check out this sketch:
/*
Forum: https://forum.arduino.cc/t/stepper-motor-cancellation/1213693
Wokwi: https://wokwi.com/projects/387464144368906241
*/
#include <Stepper.h>
int stepsPerRevolution = 2048;
int motSpeed = 50;
int dt = 500;
const byte button1Pin = 6;
const byte button2Pin = 7;
int motDir = 1;
bool motRun = false;
Stepper myStepper(stepsPerRevolution, 2, 4, 3, 5);
void setup()
{
Serial.begin(9600);
myStepper.setSpeed(motSpeed);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
}
void loop()
{
bool button1State = digitalRead(button1Pin);
motRun = (button1State == LOW);
while (motRun){
bool button2State = digitalRead(button2Pin);
myStepper.step(motDir * 1);
delayMicroseconds(dt);
motRun = (button2State == HIGH);
}
}
which you can test on Wokwi: https://wokwi.com/projects/387464144368906241
Explanation:
void loop()
{
// Read the status of button1 in loop()
bool button1State = digitalRead(button1Pin);
// if the button is pressed set motRun to true, else to false
motRun = (button1State == LOW);
// While motRun is true do what's in the while-loop()
while (motRun){
// Read the state of button2
bool button2State = digitalRead(button2Pin);
// Control the stepper
myStepper.step(motDir * 1);
// Wait for dt micro seconds
delayMicroseconds(dt);
// If button2 is pressed (LOW) set motRun to false else to true
// So if button2 is pressed leave the while loop() which stops the stepper
// as it is no longer stimulated by myStepper.step()
motRun = (button2State == HIGH);
}
}
This can be seen as a "minimum state machine" depending on the boolean motRun ...
The nice thing is that due to the use of two buttons and the immediate change into the other state where the specific button is no longer evaluated there is no need to debounce the buttons.
As this is a special case I recommend to have a look at debouncing buttons, e.g. here https://www.circuitbasics.com/how-to-use-switch-debouncing-on-the-arduino/
Otherwise sooner or later it will create trouble 
Good luck!