Nema 17 suddenly losing torque/freaking out?

I'm using a Nema 17 stepper motor with a A4988 driver board, to turns a card carousel for a sort of split-flap display.
It'll be working fine for a bit and then suddenly act like it's lost torque, or something.

The wiring is pretty much this, with the only difference being that the 5v power is now connected to the 5v pin, not VIN, on the Arduino:

This in the code i'm currently trying it with:

#include <Arduino.h>
#include "A4988.h"

int Step = 3;   //GPIO3 in Arduino UNO --- Step of stepper motor driver
int Dire = 2;   //GPIO2 in Arduino UNO --- Direction of stepper motor driver
int Sleep = 4;  //GPIO4 in Arduino UNO --- Control Sleep Mode on A4988
int MS1 = 7;    //GPIO7 in Arduino UNO --- MS1 for A4988
int MS2 = 6;    //GPIO6 in Arduino UNO --- MS2 for A4988
int MS3 = 5;    //GPIO5 in Arduino UNO --- MS3 for A4988

//Motor Specs
const int spr = 200;  //Steps per revolution
int RPM = 6;
int Microsteps = 4;  
int stepSize = 5;

int hallSensorPin = 8;
int hallSensor;

int homed = 0;

//Providing parameters for motor control
A4988 stepper(spr, Dire, Step, MS1, MS2, MS3);

void setup() {
  Serial.begin(9600);
  pinMode(Step, OUTPUT);    //Step pin as output
  pinMode(Dire, OUTPUT);    //Direcction pin as output
  pinMode(Sleep, OUTPUT);   //Set Sleep OUTPUT Control button as output
  digitalWrite(Step, LOW);  // Currently no stepper motor movement
  digitalWrite(Dire, LOW);

  pinMode(hallSensorPin, INPUT);

  randomSeed(analogRead(0));

  // Set target motor RPM to and microstepping setting
  stepper.begin(RPM, Microsteps);
  digitalWrite(Sleep, HIGH);  //A logic high allows normal operation of the A4988 by removing from sleep
}


void findHome(int SensorPin) {
  if (homed == 0) {
    while (digitalRead(SensorPin) == HIGH) {
      stepper.move(10);
    }
    // Cycle to start possition.
    stepper.move(stepSize * 13);
    homed = 1;
  }
}

void showCard(int cardNum) {
  if (homed == 1) {
    homed = 0;
    stepper.move(stepSize * cardNum);
  }
}

int drawCard() {
  int result;

  result = random(79);

  return result;
}


void loop() {
  // findHome(hallSensorPin);
  // delay(1000);
  // showCard(drawCard());

  stepper.move(stepSize * drawCard());
  
  delay(1000);
}

Sometimes nudging the cards helps kick it off again, sometimes it doesn't. I'm not sure if it's struggling with a lack of torque or if there's something up with the signals to/from the driver board.
Any help would be appreciated!

Did you adjust the current limit on the A4988 to that required by the driver?
Can your power supply provide the required current?

In case you use a driver enable (sleep?) pin - don't use it! The motor looses torque as soon as the driver is disabled.

Some drivers have a break/powersave pin that reduces the current while the motor shall stand still - at reduced current and torque.

yep! The driver has a sleep pin, but the only time it's in use is to make sure it's set to not being asleep. I've not been able to find any other power saving features, and it's working as expected some/most of the time.

yep, the current limit is set on the driver, as pre-specs, and the powersupply should be enough (12v-2amps). The problem is kinda intermittent, which seems strange.

Is everything soldered together or are you using a solderless breadboard?

Check its state (voltage) when the motor loses torque.

just using a solderless board for now.

That can be quite problematic, especially for the high current connections.

Also, your code moves the motor a random number of steps. It is possible that the random numbers turn out to be a long sequence of small steps, so may look like a torque problem. For debugging just move the motor a constant number of steps and see what happens.

FYI: Don't connect/disconnect anything when power is applied, you could damage the driver board.
Full step mode will provide the most torque.

the number steps isn't fully random. it'll never be less than 5 steps. The code picks a number wteen 0 and 79 (the number of cards on the carousel) and then multiplies that by 5 (the number of steps needed to progress one card), and then moves that number of steps.

I've tried just having it advance at a steady rate, but it has the same issue; it works fine for a minute or two and then seem to struggle.

Here's a video showing what's happening (it's running the pick a random card, code):
https://youtube.com/shorts/1h5uA_E2ENo?feature=share

Then it's a hardware issue. Bad connections or you have the current set to low or your power supply doesn't provide enough current.

If it was a power issue i'd expect it to struggle all time, wouldn't it?

On further testing, its looking less like a torque problem and more like it stops moving 5 steps at a time, and only moves 1 step. It seems to happen when it gets to a specific point in the rotation, and then it's fine again once it moves 80 or 90 degrees further around. The weight distribution of the carousel doesn't really change, Sooooo, maybe the motor is damaged?

Missing steps is usually caused by not having the current set correctly or your stepper just does not have enough torque or because you are using a solderless breadboard.
The symptoms may not show up immediately
As I said full step mode provides the most torque, microstepping is less torque.

I've tried setting it back to full step, and it acts the same in the same part of the rotation.

The current seems to be set correctly (according ot the datasheet, and some others who helped me out with that).
Would that only cause the issue in a single quater of the rotation?

Then despite what you think you must have some kind of binding/friction problem at that point.

Would that only cause the issue in a single quater of the rotation?

No.

What are you motor specifications and what current do you have the driver set to?

YES! I did some more checking, and took a deburring tool to some parts and and hit it all with some lube from my 3D printer and that seems to have got it! :smiley:
This mechanical stuff is still fairly new to me, so I guess i'm missing some basics XD
Thank you!!

Great. Look like a fun device!

Where did you get your library?
Is the forward force of the falling cards making the motor send reverse power, causing problems with the next forward step?
What happens if you remove the square top? friction solved.

Have a nice day!