Ramps 1.4 and NEMA17 Stepper Motors stuttering

Hello. I plan on using a Ramps 1.4 board with an Arduino Mega to control 4 stepper motors for my own project. I currently have the resources to wire 2 stepper motors to the Ramps board.

I am coding this project using the AccelStepper library. I created a modified version of the “Bounce.pde” file from the AccelStepper library. Here is the code

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

#define E1_STEP_PIN         36
#define E1_DIR_PIN          34
#define E1_ENABLE0_PIN       30

#define Z_STEP_PIN         46
#define Z_DIR_PIN          48
#define Z_ENABLE_PIN       62

AccelStepper z(AccelStepper::FULL2WIRE, Z_STEP_PIN, Z_DIR_PIN);
AccelStepper e0(AccelStepper::FULL2WIRE, E0_STEP_PIN, E0_DIR_PIN);
AccelStepper e1(AccelStepper::FULL2WIRE, E1_STEP_PIN, E1_DIR_PIN);

void setup() {
   Serial.begin(115200);
  pinMode(Z_ENABLE_PIN    , OUTPUT);
  pinMode(E1_ENABLE0_PIN    , OUTPUT);
  digitalWrite(Z_ENABLE_PIN    , LOW);
  digitalWrite(E1_ENABLE0_PIN    , LOW);
  
  e1.setMaxSpeed(1500);
  e1.setAcceleration(1500);
  e1.moveTo(800);
  z.setMaxSpeed(1500);
  z.setAcceleration(1500);
  z.moveTo(800);
}

void loop() {
  if (e1.distanceToGo() == 0) {
      e1.moveTo(0);
  }
  if (z.distanceToGo() == 0) {
      z.moveTo(0);
  }
  e1.run();
  z.run();
}

I have no idea how to get what the pin numbers for each motor are so I took them from code I found online and it works. I’m also unsure of how the AccelStepper constructor works for 4 pin motors because only the first two (step and direction) are defined in the documentation. This is why I enable the pins manually. This seems to work fine. I’m not sure if there is a better way to do this.

The 2 problems I have is the motors stutter when I run this code and I cannot figure out how many steps is one revolution. The stuttering seems to mess up the accuracy of the motors. They do not start and end at the same point and the stuttering makes movement unfeasible in my project. The stepper motor says that it is 1.8 degrees per step (200/rev) but I cannot get a full revolution with 800 steps. The only attachment to the board is the A4988 driver.

I am using a 12V 8A power source, A4988 drivers, and plan on using x2 NEMA 17, x1 NEMA 11, and x1 NEMA 8 stepper motor.

Video of bounce program with 7100 steps stuttering: https://youtu.be/xRVe_2dLKCQ
Video of bounce program with 800 steps: https://youtu.be/8vDgW9D3Ezo

Attached: Picture of setup

Please post links to the datasheets for your stepper motors. The NEMA numbers just define the size of the front face.

Have you correctly set the current limit for the stepper drivers? See this link. And the Pololu A4988 web page has instructions.

If you want several stepper motors to start and finish at the exact same time but move different numbers of steps then the AccelStepper library is not designed for that. You can use the MultiStepper library but it does not do acceleration.

If you need coordinated movement and acceleration you will need to write your own code and its not that difficult.

...R Stepper Motor Basics Simple Stepper Code Simple acceleration code.

vietxduy: Hello. I plan on using a Ramps 1.4 board with an Arduino Mega to control 4 stepper motors for my own project. I currently have the resources to wire 2 stepper motors to the Ramps board.

I am coding this project using the AccelStepper library. I created a modified version of the "Bounce.pde" file from the AccelStepper library. Here is the code

You need to use AccelStepper::DRIVER not AccelStepper::FULL2WIRE with step/direction drivers.

@Robin2 I have not set the current limit for the drivers. I will need to do that. I'll also look into the multistepper library.

Here are the spec sheets for the 3 motors NEMA17: https://images-na.ssl-images-amazon.com/images/I/81RsrEX4IAL.pdf NEMA11: https://images-na.ssl-images-amazon.com/images/I/81LzW9OkeKL.pdf NEMA8: https://images-na.ssl-images-amazon.com/images/I/81AyVzz6HSL.pdf

Edit: The a4988 drivers I am using are .2 Ohm so to calibrate I'm using Vref = Imax x 8 x .200(resistance x .7 (full step)

@MarkT Thank you I will make them DRIVER instead of FULL2WIRE

The Nema 17 motor requires 2 amps and that will overload an A4988 driver, and probably a DRV8825 also.

The A4988 should not really be asked to provide more than 1.7 amps. You could do some tests to see if your stepper motor performs adequately with that current setting.

If you need the full 2 amps I suspect you will need a separate stepper driver that won't fit the CNC Shield - though you should be able to connect it to the shield with wires. My suggestion would be to get a driver than can supply 50% to 100% more than the motor requires.

...R

The motors are still stuttering with the max Vref set so I guess it'd be easiest to buy a 1 amp NEMA17 motor so that no design changes will have to be made. Is this going to work?

You first need to identify the torque and speed needed from the stepper motor. There is no point buying a 1 amp motor if it cannot do the job. The torque of a stepper motor falls off as speed increases. The better motor manufacturers publish graphs showing how the torque varies with speed.

If you choose a high-impedance motor that requires less current then it won’t run as fast for a given supply voltage compared to a low-impedance high current motor that produces the same torque.

Before you do anything else get the two low-current motors working properly with the large motor disconnected.

…R

PS … Be VERY CAREFUL never to disconnect the wires between the motor and the stepper driver while the driver is powered up. The driver will be instantly destroyed.

I have the required torque (20Ncm with a safety factor of 2) and the speed needed from the stepper motor (480 rpm for 8 revolutions). I found a motor that will meet these requirements, but the only specs are pretty barebones. Would this work at that speed based on what you know about stepper motors?

Link for the new NEMA17 motor https://www.amazon.com/gp/product/B00W98OYE4/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

I'll work on getting the two other motors working. Thank you for the help.

vietxduy:
The motors are still stuttering with the max Vref set so I guess it’d be easiest to buy a 1 amp NEMA17 motor so that no design changes will have to be made. Is this going to work?

The good thing about steppers with proper drivers is you don’t have to get a driver “bigger” than the motor. If you set the current limit on the driver to 1A then it will only give 1A and cannot be damaged by a bigger motor.

The other good thing is the steppers are all equally efficient. So a 1A motor running at 1A will have about the same power output (torque) as a 2A motor running at 1A. The 2A motor is just bigger and heavier. Obviously it is better to get the right motor but if you can’t wait for the right one to be shipped to you, the wrong motor is not terribly wrong.

[I’m speaking about motors in the same class. A pancake stepper or a unipolar stepper are going to give different torque results for the same power input.]

Use this speed calculator to work out speed and torque from limited datasheet info: Stepper Motor Maximum Speed and Power Calculator

MorganS: So a 1A motor running at 1A will have about the same power output (torque) as a 2A motor running at 1A

That can't be true if the 1 amp motor has more coil windings.

...R