-1

Problem Description:

I'm controlling two NEMA 17 stepper motors with A4988 drivers and an Arduino Uno. I'm experiencing a peculiar issue where one motor runs perfectly smooth during code upload but becomes erratic afterward, while the second motor works correctly in both scenarios.

The Specific Problem:

During upload: Both motors run smoothly

After upload:

Motor #1: Jerky, inconsistent movement, sometimes stalling or missing steps

Motor #2: Continues to work perfectly The same code produces different behaviors between the two motors

Hardware Setup:

  • Arduino Uno
  • Two A4988 drivers (one for each motor)
  • Two NEMA 17 stepper motors (identical models)
  • Power Supply: 19V, 3.42A (both motors connected in parallel)
  • USB power from computer during programming

Circuit Configuration:

  • 19V, 3.42A Power Supply
  • A4988 #1 ── NEMA 17 #1 (problematic)
  • A4988 #2 ── NEMA 17 #2 (working correctly)

What I've Tried:

  • Verified power supply - 19V, 3.42A should be sufficient for both motors

  • Added decoupling capacitors (470µF) near each A4988

  • Verified all connections - No loose wires or poor connections

  • Added proper initialization in setup()

Current Code:

#include <Arduino.h>
#include <AccelStepper.h>
const int STEPA = 3;
const int DIRA = 4;
const int ENA = 2;
const int STEPB = 13;
const int DIRB = 8;
const int ENB = 12;
// const int EM = 8;
#define motorInterfaceType 1

AccelStepper StepperA(motorInterfaceType, STEPA, DIRA);
AccelStepper StepperB(motorInterfaceType, STEPB, DIRB);

void setup() {
  Serial.begin(115200);
  //pinMode(EM, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  StepperA.setMaxSpeed(2500);
  StepperA.setAcceleration(100);
  StepperA.setSpeed(2000);

  StepperB.setMaxSpeed(2000);
  StepperB.setAcceleration(100);
  StepperB.setSpeed(2500);
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);
}


int prev_place[] = {0, 0};
bool running = true;
void loop() {
  // ALWAYS RUN THE MOTORS
  StepperA.run();
  StepperB.run();

  // Only read commands when motors are idle
  if (StepperA.distanceToGo() == 0 && StepperB.distanceToGo() == 0) {
    digitalWrite(ENA, HIGH);
    digitalWrite(ENB, HIGH);

    if (Serial.available() > 0) {

      String cmd = Serial.readStringUntil('\n');
      cmd.trim();

      int dx = 0;
      int dy = 0;

      if (cmd == "F")      { dx = 0;  dy = 200; }
      else if (cmd == "B") { dx = 0;  dy = -200; }
      else if (cmd == "R") { dx = 200; dy = 0; }
      else if (cmd == "L") { dx = -200;dy = 0; }
      else if (cmd == "D1") { dx = -100;dy = 100; }
      else if (cmd == "D2") { dx = 1000;dy = 1000; }
      else if (cmd == "Q") { StepperA.stop(); StepperB.stop();}

      int da = dx + dy;
      int db = dx - dy;
      // Serial.write);
      if(da>0 || da<0){
        digitalWrite(ENA, LOW);
      }
      if(db>0 || db<0){
        digitalWrite(ENB, LOW);
      }
      int dadeg = (36 * da) / (10 * PI);
      int dbdeg = (36 * db) / (10 * PI);
      Serial.print(dadeg*10000);
      StepperA.move(dadeg / 1.8);
      StepperB.move(dbdeg / 1.8);
    }
  }
}

Key Observations: Power: 19V should be within A4988 specs (8-35V), 3.42A should be enough for two motors

During upload: Both motors work perfectly (as a matter of fact, i don't why they move while code is being uploaded)

After upload: Only one motor becomes problematic

The problematic motor/driver combination is consistent (problem follows the specific A4988)

Current sharing: Both VREF pots set to same voltage

Heating: Neither A4988 gets excessively hot

What is the issue and how to solve?

I am new to this forum and any advice would be appreciated!

BONUS CLUE: If I hold the reset button on the Arduino, for as long as I hold it, it keeps rotating the motors perfectly, when i leave it they stop. Also, they were working perfectly 3 days ago. We just plugged them in today and this problem occured.

New contributor
Sanchit Batra is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
6
  • are you saying that the motors move smoothly when the Arduino is turned off? Commented 2 days ago
  • Actually no, because the motors run when the code is being uploaded as in the Arduino is connected to my laptop and I have clicked the upload button. WHILE it is uploading the motors automatically move smoothly. Commented 2 days ago
  • sounds like something is miswired Commented 2 days ago
  • app.cirkitdesigner.com/project/…. Commented 2 days ago
  • 2
    please do not write information in comments ... edit the question instead ... add a picture of the circuit directly into the question Commented 2 days ago

1 Answer 1

-1

This to just inform to anyone in the future who faces a similar problem. I solved the motors problem by simply shifting all of the pins that were from 10-13 to before that. Apparently these pins have something low-level technical going on which interferes with the working.

New contributor
Sanchit Batra is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 2
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented yesterday
  • 2
    that does not answer the question you asked ... what is the issue? Commented yesterday
  • 1
    Hi Sanchit, it would really help others if you did two things. 1) Post your diagram in the question itself. 2) Explain your answer with more details Commented 21 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.