Hello, fresh newbie here with an issue that puzzles:
I'm using a Nema 17 motor set to 6400 microsteps, TB6600 stepper Driver, Elegoo Nano clone.
I want 5.4 revolutions of the motor after pushing a button, at 6400 microsteps, that's 34560 steps, and the motor runs continuously after I push the button. I kept reducing the number of steps and 32767 is the highest nember of steps it'll run and stop before the motor runs nonstop at 32768 and above. I switched to 3200 microsteps (17280 steps for 5.4 turns) and the motor stops as desired.
I think I'm fine at 3200, getting the desired number of turns, but am curious what the issue is when trying 6400 microsteps. Is it the Nano, the Driver? Anybody? I've got a lot to learn.
/* Attempt to run a stepper motor with TB6600 stepper motor driver
and Arduino without a library: push button, run x revolutions */
// Define stepper motor connections, button, and steps per revolution:
#define buttonPin 7
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 3200
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// run motor 5.4 revs:
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 5.4 revolutions:
for (int i=0; i < 17280; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(125);
digitalWrite(stepPin, LOW);
delayMicroseconds(125);
}
} else {
// turn motor off:
digitalWrite(stepPin, LOW);
digitalWrite(dirPin, LOW);
}
}
Common cathode wiring on the Stepper driver, 5V from Nano to one leg of the button, other leg to pin 7 on the Nano with a 10K pulldown resistor, 24V power supply on the motor, Nano running on power from USB. Everything sharing ground.
I think we were typing at the same time. I've written up the wiring which as I've said, works fine with the steps defined below the threshold.
It just seemed odd to me that any number below that threshold worked fine, but nothing above it, only changing the number of steps. The code I posted is the current iteration with steps per rev redefined as 3200 instead of 6400 and the number of steps to run, divided by two.
The code is a patchwork of different sketches found online, I'm sure it could be cleaner and more direct. I was just curious if there's something about extreme microstepping or "large" numbers that are causing the issue?
I tried the same numbers, 32767 / 32768 at the 3200 microstep setting, and the issue repeats. Runs and stops as designed at 32767, but runs without stopping at 32768.
Thank you Stefan, I THOUGHT it might be something like this, and a friend I spoke with also confirmed it, and offered a slight code change that worked. I will study the other respondents replies and keep learning.