AccelStepper: motor sometimes spin in the wrong direction

Hello,

I am using the accelstepper/multistepper class to control two stepper motor (here I am showing only one). I have a problem with this library, or better with the motor. I am using a 12V 28BYJ-48 modified to work as bipolar motor with the driver A4988 and an arduino nano.

When the motor have to do long movements it works perfectly (very smooth, almost no vibration), please see the code and the video: https://streamable.com/a7n3c

#include <Arduino.h>
#include <AccelStepper.h>
#include <MultiStepper.h>

MultiStepper steppers;
AccelStepper head_stepper(AccelStepper::DRIVER, 2, 3);

void setup()
{
    head_stepper.setMaxSpeed(500);
    steppers.addStepper(head_stepper);
    long long_max[] = {2147483647, 2147483647};
    steppers.moveTo(long_max);
}

void loop()
{
    steppers.run();
}

But when it comes to small movement it cames the pain: https://streamable.com/tehzy
As you can see sometimes it goes in the correct direction, but other times it
spins in the wrong one! How is this possible? What can I do?

#include <Arduino.h>
#include <AccelStepper.h>
#include <MultiStepper.h>

MultiStepper steppers;
AccelStepper head_stepper(AccelStepper::DRIVER, 2, 3);

void setup()
{
    head_stepper.setMaxSpeed(500);
    steppers.addStepper(head_stepper);
}

unsigned int counter = 1;
void loop()
{
    long little_movement[] = {30 * counter, 30 * counter};
    steppers.moveTo(little_movement);
    steppers.run();
    if (head_stepper.distanceToGo() == 0)
    {
        delay(500);
        counter++;
    }
}

Any idea?

I suspect your modifications to the motor are suspect, or you've wired it wrongly.

solved reducing the acceleration

#include <MultiStepper.h>

MultiStepper steppers;
AccelStepper head_stepper(AccelStepper::DRIVER, D2, D1);

void setup()
{
  Serial.begin(9600);
  float speeds[] = {500};
  float acc[] = {100};
  steppers.addStepper(head_stepper);
  steppers.setAcceleration(acc);
  steppers.setMaxSpeed(speeds);
}

long counter = 1;
void loop()
{
  steppers.run();
  if (steppers.distanceToGo() == 0)
  {
    long little_movement[] = {10};
    Serial.println(counter);
    steppers.move(little_movement);
    delay(500);
    counter++;
  }
}

Whoops, sorry I should have noticed that, setup() should always contain a call to setAcceleration() and a call to setMaxSpeed(). I thought the examples all did this?