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.
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.
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?
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.