jawzzz:
I'm trying to control a 24 volt Nema 23 stepper motor with an Arduino Nano and a stepper driver. Here are links for the motor and driver.
No such thing as a 24V stepper - its a 2.8A stepper. Current driven motors only have a current rating.
Currently I'm using a 12 volt 3 A DC power supply for the motor. I understand the motor is 24 volts, but I've read 12 volts will be ok as long as the motor can get enough current. The motor's coils are rated at 2.8 A so I believe 3 A from the power supply should be enough. Is this my first mistake?
Yes, but not the way you think. The driver will output more current to the motor winding than it
takes from the supply. Its a power converter, not a linear regulator. That supply will handle several
such motors (at low speed) in fact.
My issue is, the motor does not turn smoothly. I'm trying to have it turn 180 degrees in either direction based on an input. Below is my code. I do not think the code is the issue since I can get this to work fine with a Nema 17.
The wiring is very simple.
For the motor driver:
ENA- ==> Not used
ENA+ ==> Not used
DIR- ==> Pin 5
DIR+ ==> 5 volts
PUL- ==> Pin 6
PUL+ ==> 5 voltsFor the stepper:
Yellow ==> A+
Green ==> A-
Red ==> B+
Blue ==> B-#include <AccelStepper.h>
AccelStepper stepper(1, 6, 5);
int stepVal;
void setup() {
Serial.begin(9600);
stepper.setMaxSpeed(150);
stepper.setAcceleration(100);
stepper.setCurrentPosition(0);
}
void loop() {
if (Serial.available() > 0) {
char input = Serial.read();
if (input == '0') {
stepVal = 1;
} else if (input == '1') {
stepVal = 2;
} else if (input == '2') {
stepVal = 3;
}
}
switch (stepVal) {
case 1:
stepper.runToNewPosition(0);
stepper.run();
break;
case 2:
stepper.runToNewPosition(-200);
stepper.run();
break;
case 3:
stepper.runToNewPosition(0);
stepper.run();
delay(200);
stepper.runToNewPosition(-200);
stepper.run();
delay(200);
break;
}
}
Why aren't you calling runToNewPosition upon reading the command byte from serial? You just
need run() in the rest of the loop, that's all.
Anyway your problem is that you are not using move() or moveTo() calls, which implement
acceleration. You need acceleration for smooth and consistent operation. Strip out that runToPosition
stuff, its not how to do things.