I'm using a repurposed MKS Gen L V1.0 board (arduino MEGA + RAMPS, basically) to control a pair of IR sensors and a NEMA 23 stepper with TB6600 driver.

The application is simple: raise and lower the end of a roller. Wait for a signal from the sensors, wait for a time to see if the issue fixes itself and if it doesn't, turn 300 revolutions CW to raise, CCW to lower; wait; if we still have an issue, turn 150; issue fixed, return to zero.

It all works the way I want it to, except for the speed and direction of the stepper. NOTE: this is with the motor not attached to anything. NO LOAD.

To test, I've loaded a very simple script:

// speed tests
for (int a = 650; a <= 1200; a += 50) {
    // do the thing a few times (for this test, once)
    for (int y = 0; y <= 1; y++) {
        // turn one revolution
        for (int x = 0; x <= 200; x++) {
            digitalWrite(stepPin, HIGH);
            digitalWrite(stepPin, LOW);


Any delayMicroseconds value below 650 or above 1200, the motor jitters or vibrates but doesn't turn. When it does spin, the motor changes direction between spins, and as we get near the top of bottom of the range, it'll even change direction mid-spin.

The driver is set to 200p/rev and 1.5a. (I played with microstepping and higher amperage, but it didn't make an appreciable difference.)

Before you enthusiastically recommend a library, I've worked with both AccelStepper and Stepper (the default Arduino library?), and neither were as reliable or predictable as the code above.

I would like to be able to use AccelStepper, but the ac/de-celeration ramps have the same symptoms as my simpler code: between 650 and 1150μs, everything's fine, anywhere outside that range is not.

What don't I know? What am I missing to be able to turn slower and/or faster than that narrow range? Why does it change direction mid-spin or between spins?

enter image description here

New contributor
Bill in Kansas City is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Is the motor axle attached to something mechanically? If yes, have you tried it with no load attached to the motor?
    – chrisl
    2 days ago
  • This is without load. Once it is loaded, it'll be turning a screw, so very little load on it. 2 days ago
  • Please provide an image of how you wired everything up. Sudden direction change might indicate a floating dir pin
    – chrisl
    2 days ago
  • Done: image as requested. yesterday
  • Did you connect ground of the RAMPS to the negative terminals of the TB6600?
    – chrisl
    19 hours ago


Your Answer

Bill in Kansas City is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.