Stepper motor skipping steps using accelstepper

I am running a nema 23 motor through a DM556 stepper driver using an esp32. The pulse input is conncted to pin 4 and the direction input is connected to pin 5.
I am able to get the stepper motor running using a simple while loop but without acceleration it bounces all over the place.

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 4, 5);

void setup() {
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop() {
  // If at the end of travel go to the other end
  if (stepper.distanceToGo() == 0)
    stepper.moveTo(-stepper.currentPosition());

  stepper.run();
}

I upload the following code which is an example that comes with the library where the only thing I change is AccelStepper stepper; to AccelStepper stepper(1, 4, 5);
It turns the motor irradically and makes horrible chattering noises while running but does go back and forth. I marked a line on the top of the gear and it never returns to the same position it starts. I have tried running it at different speeds and accelerations and there doesnt seem to be much difference.

Any help is much appreciated,

Thank you

It's impossible to pinpoint the reason from what You tell.
Schematics, please, and links to the datasheets of the stepper and the driver.

1 Like

How does distanceToGo() get a measurement to compare to zero, and what keeps this loop from running at clock speed?

distanceToGo returns the steps between actual position and target position. If its zero, the target position has been reached.

Nothing - but why should one?

How did you configure your driver? And what are the electrical specs of your stepper?

I assume sending a motor to positions faster than the motor can physically arrive would result in the observed appearance of random positions, rather than waiting for feedback on the arrival of the motor at the position.

The motor can be found here https://www.makerstore.com.au/product/elec-nema23-8-ht/
Thats the driverdm556-digital-stepping-driver-manual-v1.0.pdf (1.0 MB)
My settings are currently 3.2A full wave at 400 steps/sec but I have tried different setting and it seemed to make it slightly better but not by much.

1 Like

The step speed Accelstepper creates does not depend on how fast run() ist called. As long as it is called faster than needed.

1 Like

I have now tried using a dedicated power supply instead of powering it over the usb and it did nothing. I have you used a dedicated level shifter from 3.3v to 5v logic and again no change. I have tested each configuration with the while loop just to ensure that the ciruit is correct and each time it worked but when ever i upload using accelStepper it fails.

Was USB to "dedicated power supply"? How are you powering all the things? Schematic? What voltage and amps of power supply are being fed into the driver?

Is the motor loaded or unloaded?

Sorry I should of said that the usb was originally just plugged into the computer.

This is the power supply I am using and everything is running off 5v

You cannot power a DM556 with a 5V supply for the stepper. It needs much more voltage. Try with at least 20V.

Agreed, This is the power supply I use for a similar set up.

A little bit oversized for the equipment used here - but of course will do.

Maybe but I experienced similar issues as the OP and this is what solved it and for $12 at that time well worth it.

I said that it works without accel so I assumed you meant low voltage.
https://www.makerstore.com.au/product/elec-lrs-350-48/ this is the psu for the motor if your that interested

Has anyone been able to use accelstepper with an esp32? Maybe the library doesnt work with the esp32 chipset

The pulse/dir pins of the driver expect a TTL signal.
Low <0.5volt, High >4volt.

The ESP32 is a 3.3volt logic processor.
How did you solve the 3.3volt to TTL translation.
Leo..

I orginally used a level shifter and then accidentally plugged it in without and it still works. If you look at the schematic its just driving an optocoupler which can trigger at 3.3v

"it still works" is hobby-grade engineering.
Only 5volt VCC on the optos(+), and a driver that can pull the opto(-) with ~15mA to ground ensures reliable operation. An I2C level shifter (if you have used that) is not able to do that, nor is an ESP pin.
Leo..

Just for anyone in the future who is trying to get Accelstepper working with an esp32 all I had to do was change the driver settings when creating the motor Object.

So instead of

AccelStepper stepper(1, 4, 5);

Use
AccelStepper stepper(2, 4, 5);