Searching a proper Stepper Motor library for driver TMC2209 V1.3 which works with ESP Wroom32 E

What does "non working" mean? Does it not compile? Does the upload fail? Or does it not behave as expected.

You will have to provide details like code (and libraries used if any) and wiring diagram for anybody to be able to assist (I might not be the one that can assist)


I've moved your topic to a more suitable location on the forum.

1 Like

Isn't that the same as this topic:

Why opening a new one?

1 Like

Hi sterretjeThe the library examplesof library TMC2209 , also TMCStepper were compiling (only some of them) but that doesn't moves my motor.

I used library TMC2209 , also TMCStepper library examples. But one of them are able to move motor.

Motor is ok as i tried that with A4988 driver. Drivers also i bought new to get confirmation of defectiveness in driver board. Connections are properly done too according to me. Microcontroller is also file , as it driven motor with A4988.

What is possible reason..... Did any example of TMC2209 , also TMCStepper library worked for anyone....Can anyone tell me???

Hi MicroBahner

I was not intended to do that , but i was not getting enough responses there which can provide me solution. That's why i opened new.

Hi, @pssingh

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Lets start with how you have the 2209 connected to the ESP32.

Can you also post some images of your project?
So we can see your component layout.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi TomGeorgeJackson
I will start with Code --- Here it is not compiling , but in one of post in IDE forum, someone claimed it is working. I installed libraries FastAccelSteeper + TMCStepper . Still not able to compile

#include "FastAccelStepper.h"
#include <TMCStepper.h>

#define STEP_PIN 2
#define DIR_PIN 15

#define RXD2 16
#define TXD2 17

#define SHAFT true

#define SERIAL_PORT_2 Serial2  // TMC2208/TMC2224 HardwareSerial port - pins 16 & 17
#define DRIVER_ADDRESS_1 0b00    // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f          // E_SENSE for current calc, SilentStepStick series use 0.11

FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;

TMC2209Stepper driver(&SERIAL_PORT_2, R_SENSE, DRIVER_ADDRESS_1);  // Create TMC driver

int current = 1500;
int stall = 10;
int accel = 8000;
int max_speed = 19000;
int tcools = (3089838.00 * pow(float(max_speed), -1.00161534)) * 1.5;  //*64 after max speed

int motor_microsteps = 16;
int motor_steps_per_rev = 200;

void setup() {
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);

  // INTITIALIZE SERIAL0 ITERFACE
  Serial.begin(115200);
  delay(500);
  Serial.println(F("---------------------------------------------------"));
  Serial.println(F("UART0 serial output interface intitialized @ 115200"));

  // INITIALIZE SERIAL2 UART FOR TMC2209
  SERIAL_PORT_2.begin(115200);  // INITIALIZE UART TMC2209, SERIAL_8N1, 16, 17
  Serial.println(F("UART2 interface for TMC2209 intitialized   @ 115200"));
  Serial.println(F("---------------------------------------------------"));

  //TMCSTEPPER SETTINGS
  driver.begin();
  driver.pdn_disable(true);      // Use PDN/UART pin for communication
  driver.toff(5);                // [1..15] enable driver in software
  driver.blank_time(24);         // [16, 24, 36, 54]
  driver.I_scale_analog(false);  // Use internal voltage reference
  driver.rms_current(current);   // motor RMS current (mA) "rms_current will by default set ihold to 50% of irun but you can set your own ratio with additional second argument; rms_current(1000, 0.3)."

  driver.mstep_reg_select(true);
  read_ms();
  driver.microsteps(motor_microsteps);  //note that MicroPlyer will interpolate to 256
  read_ms();

  driver.TCOOLTHRS(tcools);
  driver.seimin(1);  // minimum current for smart current control 0: 1/2 of IRUN 1: 1/4 of IRUN
  driver.semin(0);
  driver.iholddelay(3);  // 0 - 15 smooth current drop
  driver.shaft(SHAFT);
  driver.intpol(true);  // interpolate to 256 microsteps
  driver.SGTHRS(stall);

  driver.pwm_autoscale(true);    // Needed for stealthChop
  driver.en_spreadCycle(false);  // false = StealthChop / true = SpreadCycle, Spreadcycle can have higher RPM but is louder
  driver.internal_Rsense(false);
  driver.TPWMTHRS(0);

  engine.init();
  stepper = engine.stepperConnectToPin(STEP_PIN);
  stepper->setDirectionPin(DIR_PIN);
  stepper->setAutoEnable(true);

  stepper->setSpeedInHz(max_speed);
  stepper->setAcceleration(accel);
}

//***********************************************************************
void read_ms() {
  uint16_t msread = driver.microsteps();
  Serial.print("Microsteps: ");
  Serial.println(msread);
}
//***********************************************************************

void loop() {

  driver.microsteps(16);
  read_ms();
  driver.VACTUAL(19000);  //SET SPEED OF MOTOR
  delay(3000);            // MOTOR MOVES 2 SEC THEN STOPS


  driver.VACTUAL(0);  //STOP MOTOR BY SETTING SPEED TO 0
  delay(1000);

  driver.microsteps(0);
  read_ms();
  driver.VACTUAL(-19000);  //SET SPEED OF MOTOR
  delay(3000);             // MOTOR MOVES 2 SEC THEN STOPS

  driver.VACTUAL(0);  //STOP MOTOR BY SETTING SPEED TO 0
  delay(1000);
}

This setup is picture attached below...

Connections are as follows.....

  • List item

Step pin -- gpio2
Dir pin -- gpio 15
Tx -- gpio 16
Rx --gpio 17
4 pins (1B, 2A, 2A, 2B) -- Directly connected from motor with4 pin connector
GND - GND of ESP
VDD - 5 V pin of ESP
EN - Not connected
NC - Not connected
MS2 - Not Connected
MS1 - Not Connected
GND -- GND (Externally )
Vmot -- 12V (Externally)

Thats it i have done

Never do that, it's cross posting and wastes peoples time. I've merged your two topics.

Understood. But i would be loosing more time if i argue .

Here i come for solutions and that is what matters for me which is still pending. Posts with Thousands of views are already there to drive TMC2209 with a motor, but no one has proper solution inside...
I would be be thankful for people who would help

Like I said I do not have time to play games. You have been asked many times for information which you have failed to supply. Without the needed information how can you expect an accurate and working answer. Good Luck!

Hi.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Have you got gnd of ESP32 connected to gnd of 2209?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I already provided driver/dev kit name, connections, setup image, even code, motor type,.

Can you tell what is missing there

I given power supply to driver TCM2209 from ESP32 5V,GND pins.

But for driving motor, I given Voltage and GND externally
12V, GND).

I used these connection.

Something wrong in codes I think. Since Connection are simple and properly done as shown in picture.
Please let me know if error in image!

Hi, @pssingh

Sorry but there are no pin labels on the MCU.

Please reverse engineer your project and DRAW YOUR schematic.

Thanks... Tom... :smiley: :+1: :coffee: :coffee: :coffee: :australia:

1 Like

The ESP is a 3.3V device. So Vio of TMC2209 must be 3.3V, not 5V. Standard schematics are useless. As @TomGeorge already pointed out, helpers need an exact schematic of your project to help.

I am backing out, the OP does not want to solve the problem. It would be relative simple to solve if we had the information asked for but the OP is an expert and is apparently testing us as th OP knows better what we need then we do.

I already attached it in thread previously. No Issues. A code i found which works for me
It rotates accelerates clockwise anticlockwise with good speed for 5 seconds when i ground GPIO21/22 , and deaccelerates to after that for 2 seconds. But i don't know how to use UART feature of TMZ2209 for current adjustment....?This is only help i need from anyone here...

My code is attached below..... Please ignore previous non working codes. I request to focus this one since i think i am near to solution...

#include <TMCStepper.h>

// Stepper driver pin definitions
#define PIN_STEP_ENABLE 14
#define PIN_STEP1_DIRECTION 13
#define PIN_STEP1_STEP 12
#define SERIAL_PORT Serial2  // TMC2209 uses a hardware serial port
#define DRIVER_ADDRESS 0b00  // TMC2209 Driver address

// Button pin definitions
#define PIN_BUTTON_1 21
#define PIN_BUTTON_2 22

#define R_SENSE 0.11f // Match to your driver's Rsense value
TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);

// Stepper driver variables
int targetSpeed = 0;
int currentSpeed = 0;
int stepIncrement = 50;
int maxSpeed = 8000;  // Adjust max speed if needed
int minSpeed = -8000;  // Adjust min speed if needed
int slowSpeed = 500;   // Slow speed for initial 3 seconds
int acceleration = 400;
int deceleration = 10; // Slower deceleration for smooth transition
int currentPosition = 0; // Declare currentPosition globally

void setup() {
    SERIAL_PORT.begin(115200);
    driver.begin();
    driver.toff(4);  // Enable driver
    driver.rms_current(300);  // Set driver current
    driver.microsteps(16);  // Enable microstepping
    driver.en_spreadCycle(false); // Enable StealthChop

    // Set both buttons as INPUT_PULLUP so we can detect when they are pressed
    pinMode(PIN_BUTTON_1, INPUT_PULLUP);
    pinMode(PIN_BUTTON_2, INPUT_PULLUP);

    // Configure stepper driver pins as OUTPUTs
    pinMode(PIN_STEP1_DIRECTION, OUTPUT);
    pinMode(PIN_STEP1_STEP, OUTPUT);
    pinMode(PIN_STEP_ENABLE, OUTPUT);

    // ENABLE pin has to be pulled LOW for TMC2209 used in this example to enable the driver
    digitalWrite(PIN_STEP_ENABLE, LOW);
}

void loop() {
    static bool slowStart = true;
    static unsigned long slowStartTime = 0;
    static bool transitioningToSlow = false;
    static bool slowingDown = false;

    if (digitalRead(PIN_BUTTON_1) == LOW || digitalRead(PIN_BUTTON_2) == LOW) {
        if (slowStart) {
            slowStartTime = millis();
            slowStart = false;
            transitioningToSlow = false;
            slowingDown = false;
        }

        if (millis() - slowStartTime < 5000) {
            // Run at normal speed for 5 seconds
            if (digitalRead(PIN_BUTTON_1) == LOW) {
                targetSpeed = maxSpeed;
            } else if (digitalRead(PIN_BUTTON_2) == LOW) {
                targetSpeed = minSpeed;
            }
        } else if (millis() - slowStartTime < 8000) {
            // Smooth transition to slow speed
            if (!transitioningToSlow) {
                transitioningToSlow = true;
                slowingDown = true;
            }
            if (slowingDown) {
                if (currentSpeed > slowSpeed || currentSpeed < -slowSpeed) {
                    targetSpeed = (currentSpeed > 0) ? currentSpeed - deceleration : currentSpeed + deceleration;
                } else {
                    targetSpeed = (targetSpeed > 0) ? slowSpeed : -slowSpeed;
                    slowingDown = false;
                }
            }
        } else {
            // Reset slow start mechanism after 8 seconds
            slowStart = true;
            transitioningToSlow = false;
            slowingDown = false;
        }
    } else {
        targetSpeed = 0;
        slowStart = true;
        transitioningToSlow = false;
        slowingDown = false;
    }

    // Smooth acceleration/deceleration
    if (currentSpeed < targetSpeed) {
        currentSpeed = min(currentSpeed + acceleration, targetSpeed);
    } else if (currentSpeed > targetSpeed) {
        currentSpeed = max(currentSpeed - acceleration, targetSpeed);
    }

    static unsigned long nextChange = 0;
    static uint8_t currentState = LOW;
    if (currentSpeed == 0) {
        currentState = LOW;
        digitalWrite(PIN_STEP1_STEP, LOW);
    } else {
        if (micros() > nextChange) {
            if (currentState == LOW) {
                currentState = HIGH;
                nextChange = micros() + 20;  // Short delay for high stepping rate

                if (currentSpeed > 0) {
                    currentPosition++;
                } else if (currentSpeed < 0) {
                    currentPosition--;
                }
            } else {
                currentState = LOW;
                nextChange = micros() + (1000000 / abs(currentSpeed)) - 20;
            }

            if (currentSpeed > 0) {
                digitalWrite(PIN_STEP1_DIRECTION, LOW);
            } else {
                digitalWrite(PIN_STEP1_DIRECTION, HIGH);
            }

            digitalWrite(PIN_STEP1_STEP, currentState);
        }
    }
}

Hi Tom , i used exact same circuit as i posted above. Right now my hardware works as motor moving with minimal noise. But in code, i need anyone help to resolve.....

#include <TMCStepper.h>

// Stepper driver pin definitions
#define PIN_STEP_ENABLE 14
#define PIN_STEP1_DIRECTION 13
#define PIN_STEP1_STEP 12
#define SERIAL_PORT Serial2  // TMC2209 uses a hardware serial port
#define DRIVER_ADDRESS 0b00  // TMC2209 Driver address

// Button pin definitions
#define PIN_BUTTON_1 21
#define PIN_BUTTON_2 22

#define R_SENSE 0.11f // Match to your driver's Rsense value
TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);

// Stepper driver variables
int targetSpeed = 0;
int currentSpeed = 0;
int stepIncrement = 50;
int maxSpeed = 8000;  // Adjust max speed if needed
int minSpeed = -8000;  // Adjust min speed if needed
int slowSpeed = 500;   // Slow speed for initial 3 seconds
int acceleration = 400;
int deceleration = 10; // Slower deceleration for smooth transition
int currentPosition = 0; // Declare currentPosition globally

void setup() {
    SERIAL_PORT.begin(115200);
    driver.begin();
    driver.toff(4);  // Enable driver
    driver.rms_current(300);  // Set driver current
    driver.microsteps(16);  // Enable microstepping
    driver.en_spreadCycle(false); // Enable StealthChop

    // Set both buttons as INPUT_PULLUP so we can detect when they are pressed
    pinMode(PIN_BUTTON_1, INPUT_PULLUP);
    pinMode(PIN_BUTTON_2, INPUT_PULLUP);

    // Configure stepper driver pins as OUTPUTs
    pinMode(PIN_STEP1_DIRECTION, OUTPUT);
    pinMode(PIN_STEP1_STEP, OUTPUT);
    pinMode(PIN_STEP_ENABLE, OUTPUT);

    // ENABLE pin has to be pulled LOW for TMC2209 used in this example to enable the driver
    digitalWrite(PIN_STEP_ENABLE, LOW);
}

void loop() {
    static bool slowStart = true;
    static unsigned long slowStartTime = 0;
    static bool transitioningToSlow = false;
    static bool slowingDown = false;

    if (digitalRead(PIN_BUTTON_1) == LOW || digitalRead(PIN_BUTTON_2) == LOW) {
        if (slowStart) {
            slowStartTime = millis();
            slowStart = false;
            transitioningToSlow = false;
            slowingDown = false;
        }

        if (millis() - slowStartTime < 5000) {
            // Run at normal speed for 5 seconds
            if (digitalRead(PIN_BUTTON_1) == LOW) {
                targetSpeed = maxSpeed;
            } else if (digitalRead(PIN_BUTTON_2) == LOW) {
                targetSpeed = minSpeed;
            }
        } else if (millis() - slowStartTime < 8000) {
            // Smooth transition to slow speed
            if (!transitioningToSlow) {
                transitioningToSlow = true;
                slowingDown = true;
            }
            if (slowingDown) {
                if (currentSpeed > slowSpeed || currentSpeed < -slowSpeed) {
                    targetSpeed = (currentSpeed > 0) ? currentSpeed - deceleration : currentSpeed + deceleration;
                } else {
                    targetSpeed = (targetSpeed > 0) ? slowSpeed : -slowSpeed;
                    slowingDown = false;
                }
            }
        } else {
            // Reset slow start mechanism after 8 seconds
            slowStart = true;
            transitioningToSlow = false;
            slowingDown = false;
        }
    } else {
        targetSpeed = 0;
        slowStart = true;
        transitioningToSlow = false;
        slowingDown = false;
    }

    // Smooth acceleration/deceleration
    if (currentSpeed < targetSpeed) {
        currentSpeed = min(currentSpeed + acceleration, targetSpeed);
    } else if (currentSpeed > targetSpeed) {
        currentSpeed = max(currentSpeed - acceleration, targetSpeed);
    }

    static unsigned long nextChange = 0;
    static uint8_t currentState = LOW;
    if (currentSpeed == 0) {
        currentState = LOW;
        digitalWrite(PIN_STEP1_STEP, LOW);
    } else {
        if (micros() > nextChange) {
            if (currentState == LOW) {
                currentState = HIGH;
                nextChange = micros() + 20;  // Short delay for high stepping rate

                if (currentSpeed > 0) {
                    currentPosition++;
                } else if (currentSpeed < 0) {
                    currentPosition--;
                }
            } else {
                currentState = LOW;
                nextChange = micros() + (1000000 / abs(currentSpeed)) - 20;
            }

            if (currentSpeed > 0) {
                digitalWrite(PIN_STEP1_DIRECTION, LOW);
            } else {
                digitalWrite(PIN_STEP1_DIRECTION, HIGH);
            }

            digitalWrite(PIN_STEP1_STEP, currentState);
        }
    }
}

On my code , i am struggling so much to achieve this logic. Can anyone help me for that, i tried so hard, but luck no luck worked, that would be my perfect solution if it works...
**Button 1 GPIO 21(PIN_BUTTON_1):

When grounded (LOW), the motor should move anticlockwise at a slow speed for the first 3 seconds.
After 3 seconds, the motor should continue moving anticlockwise at a faster speed for an 5 seconds.
Button 2 GPIO22(PIN_BUTTON_2):

When grounded (LOW), the motor should move clockwise at a fast speed for the first 5 seconds.
After 5 seconds, the motor should continue moving clockwise at a slow speed for an 3 seconds.** If i try changing something, things doesn't work as expected. Please help

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