Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: effita on Jun 30, 2020, 12:34 am

Title: Can't switch direction in TMC2209 standalone
Post by: effita on Jun 30, 2020, 12:34 am
hello
I'm using Arduino and TMC2209 to control stepper motor.
Using the stand-alone interface (direction and step pins only) I can't switch the rotating direction.

  digitalWrite(DIR_PIN,HIGH);

      for (int i=0; i<1000; i++){
        digitalWrite(STP,HIGH);
        delayMicroseconds(100);
        digitalWrite(STP,LOW);
        delayMicroseconds(100);
     }

This is the super simple code I'm using. when I change the DIR_PIN to LOW (or HIGH), the rotating direction is always the same, what am I doing wrong?
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Paul_KD7HB on Jun 30, 2020, 04:54 am
What happens when you make the delays long enough for the motor to actually move in the other direction?

Paul
Title: Re: Can't switch direction in TMC2209 standalone
Post by: effita on Jun 30, 2020, 09:51 am
What happens when you make the delays long enough for the motor to actually move in the other direction?

Paul
What do you mean?
Those delays long enough for the motor to rotate...
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Robin2 on Jun 30, 2020, 10:25 am
Have a look at this Simple Stepper Code (http://forum.arduino.cc/index.php?topic=277692.0)

If that does not help them please post a photo of a drawing showing how you have everything connected AND a link to the datasheet for the stepper driver.

...R
Stepper Motor Basics (http://forum.arduino.cc/index.php?topic=284828.0)
Title: Re: Can't switch direction in TMC2209 standalone
Post by: effita on Jun 30, 2020, 02:28 pm
Have a look at this Simple Stepper Code (http://forum.arduino.cc/index.php?topic=277692.0)

If that does not help them please post a photo of a drawing showing how you have everything connected AND a link to the datasheet for the stepper driver.

...R
Stepper Motor Basics (http://forum.arduino.cc/index.php?topic=284828.0)

ok, thanks for the reply
so I use the second code on your link.
the stepper motor rotates the same direction (very slow) regardless of the button been pushed.


Code: [Select]


// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW

byte directionPin = 9;
byte stepPin = 8;

byte buttonCWpin = 10;
byte buttonCCWpin = 11;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;

byte ledPin = 13;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 25; // milliseconds

void setup() {

     Serial.begin(9600);
     Serial.println("Starting Stepper Demo with millis()");

     pinMode(directionPin, OUTPUT);
     pinMode(stepPin, OUTPUT);
     pinMode(ledPin, OUTPUT);
     
     pinMode(buttonCWpin, INPUT_PULLUP);
     pinMode(buttonCCWpin, INPUT_PULLUP);
     
}

void loop() {
   
    curMillis = millis();
    readButtons();
    actOnButtons();
   
}

void readButtons() {
   
    buttonCCWpressed = false;
    buttonCWpressed = false;
   
    if (digitalRead(buttonCWpin) == LOW) {
        buttonCWpressed = true;
    }
    if (digitalRead(buttonCCWpin) == LOW) {
        buttonCCWpressed = true;
    }
}

void actOnButtons() {
    if (buttonCWpressed == true) {
        digitalWrite(directionPin, LOW);
        singleStep();
    }
    if (buttonCCWpressed == true) {
        digitalWrite(directionPin, HIGH);
        singleStep();
    }
}

void singleStep() {
    if (curMillis - prevStepMillis >= millisBetweenSteps) {
            // next 2 lines changed 28 Nov 2018
        //prevStepMillis += millisBetweenSteps;
        prevStepMillis = curMillis;
        digitalWrite(stepPin, HIGH);
        digitalWrite(stepPin, LOW);
    }
}




this is the datasheet (https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC2209_Datasheet_V103.pdf), also I attached drawing of how everything connected.
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Robin2 on Jun 30, 2020, 02:59 pm
Image from Reply #4 so we don't have to download it. See this  Simple Image Posting Guide (http://forum.arduino.cc/index.php?topic=519037)

(https://forum.arduino.cc/index.php?action=dlattach;topic=693093.0;attach=371012)

...R
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Robin2 on Jun 30, 2020, 03:09 pm
What happens if you try the first (simpler) program in my link?

What happens if you connect the DIR pin either to GND or VIO?

If you have correctly connected to the step, direction and GND pins I'm afraid I can't think of anything to suggest. I am not familiar with that stepper driver.

Your diagram shows an ESP32 but your Original Post said you are using an Arduino. Which is it? (Not sure if it matters).

...R
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Paul_KD7HB on Jun 30, 2020, 03:53 pm
What do you mean?
Those delays long enough for the motor to rotate...
How much time do you think is necessary for a motor to stop, reverse direction and move again? 100 ms is way to short. Try 1000ms.

Paul
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Robin2 on Jun 30, 2020, 05:26 pm
How much time do you think is necessary for a motor to stop, reverse direction and move again? 100 ms is way to short. Try 1000ms.
The code in the Original Post has the direction fixed. The 100ms is the timing for the steps.

...R
Title: Re: Can't switch direction in TMC2209 standalone
Post by: effita on Jun 30, 2020, 05:30 pm
How much time do you think is necessary for a motor to stop, reverse direction and move again? 100 ms is way to short. Try 1000ms.

Paul
You are wrong.
It works even with 2 milliseconds and less. It depends which driver you use and the microstepping configuration
Title: Re: Can't switch direction in TMC2209 standalone
Post by: Paul_KD7HB on Jun 30, 2020, 06:08 pm
The code in the Original Post has the direction fixed. The 100ms is the timing for the steps.

...R
Oh, I was seeing he was changing the direction every 100ms.

Paul