X27 with stepper library - strange behaviour

I have an X27 168 wired directly to the Arduino pins 8,9,10 and 11. I tried various sample programs on this site but was getting strange behavior, so I have cut the program down to try and understand the interaction between the stepper library and the X27.

This is my code:

#include <Stepper.h>

#define STEPS 315

Stepper myStepper(STEPS, 8, 9, 10, 11);

void setup() {
      Serial.begin(9600);
      delay(1000);
      Serial.write("Start\n");
      
      delay(1000);

      Serial.write("Set speed\n");
      delay(1000);
      myStepper.setSpeed(100);
    
      delay(1000);
      
      Serial.write("Step -600 first\n");
      delay(1000);
      myStepper.step(-600);
      
      delay(1000);
      
      Serial.write("Step -600 second\n");
      delay(1000);
      myStepper.step(-600);
}

void loop() {
      delay(1000);
      
      Serial.write("Step -600 loop\n");
      myStepper.step(-600);

}

As I understand it, to zero the motor, it should be instructed to step with a value greater than the number of available steps so that it will hit the stop. My first attempt at this told the motor to step -600 but had unpredictable results with a different movement each time I pressed reset or uploaded the program, so I added the second step(-600) and it still behaved erratically, so I added the step(-600) in the loop and this video shows the behavior.

I am trying to create a gauge that fits in a 50mm housing with the pivot near the top, so I cant have the needle swinging so far round

What is an "X27 168"?

Please post a link to its datasheet.

...R

It's a gauge motor:

I have an X27 168 wired directly to the Arduino pins 8,9,10 and 11.

Do you have inductive kick diodes to protect the Arduino?

If not, don't expect that setup to work more than a few minutes. Sensible people use a motor driver.

My original plan was to use an A4988 driver but I found various postings on the forums to say that the X27 could be driven directly from the Arduino pins and as space is tight, I switched to this option.

I haven't added diodes but will do, however it hasn't failed after a few minutes, I left it running all day yesterday to see if there were any heat issues.

mgb:
I haven't added diodes but will do, however it hasn't failed after a few minutes, I left it running all day yesterday to see if there were any heat issues.

You can live for thousands of days but you only die once. Fit the diodes now.

...R