AccelStepper - motor disabled with negative speed

Hi everyone,

Sorry to add another post about AccelStepper, but with some searching I haven't found a duplicate of my question.

In a nutshell, I've got two steppers running properly forwards, but whenever I set a negative speed the motors don't move and appear disabled ( I can easily twist them back and forth with my hand).

Here's the code I'm using:

#include <AccelStepper.h>

int screwSpeed = 1000;
int enPin = 21;

AccelStepper screw1 (1, 38, 39); // Stepper1
AccelStepper screw2 (1, 40, 41);   // (Type:driver, STEP, DIR) - Stepper

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  screw1.setMaxSpeed(2000);
  screw2.setMaxSpeed(2000);
  screw1.setSpeed(screwSpeed);
  screw2.setSpeed(screwSpeed);
  pinMode(enPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(enPin,LOW);
  screw1.runSpeed();
  screw2.runSpeed();
}

when screwSpeed is set to any positive number, the motors turn as I would expect. When it's set to any negative number, no motion. if I serial print the current position or speed of the motor, the arduino thinks that it's moving (the position steadily decreases, the speed reports as negative)

for the hardware, I'm using an Arduino mega and driving the motors with TMC2208s in individual development boards

I suspect this is a hardware issue but I haven't turned up a solution after triple-checking my wiring, so I'd appreciate any tips.

I tried your code on my Uno with CNC shield and A4988 drivers and it works fine. Motors go clockwise with positive values of setSpeed() and counterclockwise with negative values.

Post a schematic and some photos.

Can you probe the dir pin on the driver or connect an LED to monitor the state of the dir pin? Does it change state with the sign of setSpeed value?

Here's a diagram and a few photos of my setup:


The DIR pin does change values: 5V with a positive speed and 0V with a negative speed. I tried switching some of the motor coil wires but no joy.

Could this be something to do with the TMC2208? I understood that they could be used as a plug-and-play replacement of an A4988, but perhaps that's not the case?

What confuses me is the particular method of failure: in other forum posts the motor jitters or continues spinning forwards when a negative speed is given, but in my case it just goes dead as if the power was unplugged, then happily back to life with a positive speed.

Are you observing the state of the dir pins, with a meter or logic analyzer, at the driver?

Are you observing the state of the dir pins, with a meter or logic analyzer, at the driver?

Yes, I'm using my multimeter to probe the DIR and GND directly on the driver chip. It's 5V when the motor is turning forwards, and 0V when the motor is dead (but should be turning backwards)

Time to dig into the driver data sheet. I am not at all familiar with those drivers. Is it like the TMC2209 in that it has a serial port that can be used to set options on the driver?

I think so (is that the same as UART?), although to be honest the TMC2208 documentation goes quickly over my head.

Yes, UART (Universal Asynchronous Receiver Transmitter) is the same as a serial port.

Do you have an A4988 or DRV8825 to put in the place of the TMC2208 just to test?

Do you have an A4988 or DRV8825 to put in the place of the TMC2208 just to test?

Yes, I swapped in some old A4988s and the motors run forwards and backwards, albeit too loudly and weakly for my project. So, either I have some damaged TMC2208s or they aren't as plug-and-play as I thought.

This video may be of interest.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.