Another Stepper Motor Issue : Dir pin does nothing

I'm using an Arduin UNO Wifi connected to a TMC2209 Motor Controller board with that connected to a TwoTrees Stepper Motor model 17HS4401S.

I've gotten it to make the Stepper Motor run, but it always runs in the same direction. It doesn't matter if I

digitalWrite(PinDirection, HIGH);

or

digitalWrite(PinDirection, LOW);

it always goes in the same direction.

The motor also gets quite HOT.

What might I be doing wrong?

Here's the Arduino code I'm using:

const pin_size_t PinStep = 12;
const pin_size_t PinDirection = 7;
const pin_size_t PinEnable = 13;
void setup() 
{
  pinMode(PinStep, OUTPUT);
  pinMode(PinDirection, OUTPUT);
  pinMode(PinEnable, OUTPUT);

  digitalWrite(PinEnable,LOW);  
  digitalWrite(PinStep, LOW);
}

void StepperForward()
{
  digitalWrite(PinDirection, HIGH);
}

void StepperReverse()
{
  digitalWrite(PinDirection, LOW);
}

void StepTheMotor()
{
  digitalWrite(PinStep, HIGH);
  delay(1); // One millisecond
  digitalWrite(PinStep, LOW);
}

void loop() 
{
  StepperForward();
  for (int i = 0 ; i < 100; ++i)
  {
    StepTheMotor();
    delay(1); // millisecond
  }
  delay(1000);

  StepperReverse();
  for (int i = 0 ; i < 100; ++i)
  {
    StepTheMotor();
    delay(1); // millisecond
  }
 delay(1000);
}

How is it wired up?

Stepper motors do get (very) hot in use, that's probably not a problem here.

Test using 100 ms stedelay.

Thank you for the suggestion.

I've been using some sample code I came across and it specified delay(1), which is 1 millisecond. That does the expected number of steps (I think, at least it moves some rotation) but always goes in the same direction.

I tried your suggestion of delay(100) and that does make it go in the desired location (per setting the DIR pin LOW or HIGH), but it only goes about one step. In fact, anything other than the delay(1), as specified in the sample code I'm using, results in the rotation reversing as selected, but only moves about one step, when in fact I'm trying to make it do 100 steps.

Is it possible I should be using delayMicroseconds() to give finer control?

Sorry. 100 was a mistakr. Test a delay of 10 ms.
I've benn running plenty of steppers that needed like 10 ms delay between the steps.
Using a library haaving a eleration is needed for high speed.
What documentation specifies 1 ms?

I think I found the problem, and it's not the delay value. A delay of 1ms appears to be just fine. The problem was in connecting the two "coils" from the motor to the pins on the motor driver.

Every document I've come across has indicated like this:

Red -> 1A
Blue -> 1B

Green -> 2A
Black -> 2B.

Where Red/Blue is one coil, Green/Black is the other coil.
And basically saying that the pins labeled '1'f or one coil, labeled '2' for the other coil.

And that's how I wired it and got the weird results.

I just tried a different wiring, namely:

Red -> 1A
Blue -> 2A

Green -> 1B
Black -> 2B.

In other words one coil goes to the A pins, the other coil goes to the B pins.

And now it's working just fine, reversing direction as desired and controlled via the DIR pin.

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