Proper settings when driving stepper motor with TMC2209

The 17HS4401 motor and TMC2209(has heat sink) driver are running very hot(it's painful when you touch the motor). I have set the vref and measured it (1.79v)

So as i read 60(Celsius) is normal, maybe a bit above? Otherwise, the motor runs really quietly.

I am trying to make rail for precise macro photography on my own, but first i need to clear almost every unknown of how to set up the motor properly with the TMCStepper library and use of AccelStepper library, so i can move the motor a couple of micro meters at a time!

My questions are do i utilize properly software serial connection that configures the driver with via the TMCStepper library? I wired one digital pin on my arduino nano to the CLK pin of the driver to act as software TX and then bridged another digital port with 1K resistor to the same CLK pin. For directions i looked here Stepper_motor_developing_platform and janelia-arduino/TMC2209

Both of them show that method of communication with one wire, but i am a bit confused on where should i use it? USART or CLK? In one other example i saw that hey use software slave clock (SCK), should i use it here and with what pin? And what type - hardware or software serial on the nano?

To be clear the motor runs fine i just wonder if those driver configurations are doing anything or if i am doing something wrong!

EN - 12
MS1 - 11
MS2 - 10
PDN - GND
USART - not connected
CLK - 2
STEP - 9
DIR - 8


#include <TMCStepper.h> // Stepper motor driver library for TMCxxxx motors (TMC2209)
#include <AccelStepper.h> // Accelstepper library for driving by the STEP&DIR pins
#include <SoftwareSerial.h> // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
//#include <Streaming.h> 

#define EN_PIN           12 // Enable
#define DIR_PIN          8  // Direction
#define STEP_PIN         9  // Step
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2 (both zero (GND))
#define R_SENSE 0.11f       // Sense resistor "R110" - There are 2 of them because of the 2 stepper coils.
#define MS1 11              // MS1
#define MS2 10              // MS2 - Microstepping 8, 16, 32, 64. Alternatively, address pins if UART used

//#define SW_SCK           5      // Software Slave Clock (SCK)
#define SW_TX            2      // SoftwareSerial receive pin
#define SW_RX            3

SoftwareSerial SoftSerial(SW_RX, SW_TX);


TMC2209Stepper driver(&SoftSerial, R_SENSE, DRIVER_ADDRESS); // Creating an instance called "driver"
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);
void setup() {
  delay(3000);
  Serial.begin(115200);        // Initialize hardware serial port for both debugging and TMC2209 communication 
  SoftSerial.begin(11520);
  driver.beginSerial(11520);

  pinMode(EN_PIN, OUTPUT);   // Enable motor pin
  pinMode(STEP_PIN, OUTPUT); // Step pin
  pinMode(DIR_PIN, OUTPUT);  // Dir pin
  pinMode(MS1, OUTPUT);      // Microstepping config pin 1
  pinMode(MS2, OUTPUT);      // Microstepping config pin 1
  digitalWrite(MS1, LOW);    // MS1 = 0
  digitalWrite(MS2, LOW);    // MS2 = 0; Notice: When UART is used, these pins are used for assigning an address to the driver
  digitalWrite(EN_PIN, LOW); // Enable driver

  driver.begin();                 // Start the library
  driver.toff(5);                 // Enables driver in software - TOFF: slow decay time
  driver.rms_current(600);        // Set motor RMS current (RMS*sqrt(2) ~ max current consumption)
  driver.microsteps(8);           // Set microsteps to 1/8th
  driver.en_spreadCycle(false);   // Toggle spreadCycle on TMC2208/2209/2224
  driver.pwm_autoscale(true);     // Needed for stealthChop

  stepper.setMaxSpeed(2000);      // 100mm/s @ 80 steps/mm
  stepper.setSpeed(1000);          // 100mm/s @ 80 steps/mm
  stepper.setAcceleration(1000);  // 2000mm/s^2
  stepper.setEnablePin(EN_PIN);   // Pass the enable pin to the library
  stepper.setPinsInverted(false, false, true);
  stepper.enableOutputs();        // Enable motor current
}

void loop() {
 
   driver.microsteps(32);          // Change microstepping to 1/32
   stepper.moveTo(1000);           // Set up an absolute target for the stepper motor

  while (stepper.distanceToGo() != 0) { // While the target is not reached, run the motor
    stepper.run(); // Run the motor with acceleration/deceleration
  }
  
  delay(2000);                     // Wait for 2 seconds

  driver.microsteps(16);           // Change microstepping to 1/16
  stepper.moveTo(-1000);           // Set up another absolute target for the stepper motor

  while (stepper.distanceToGo() != 0) { // While the target is not reached, run the motor
    stepper.run(); // Run the motor with acceleration/deceleration
  }
  
  delay(2000);                

   
 

}

Software serial will not run anywhere close to the speed you are trying to use.

11520 is a strange baud rate:

...for:

https://docs.arduino.cc/learn/built-in-libraries/software-serial/

Maybe it isn't communicating anything at all. When you tell it go 1000 1/32 microsteps forward (56° ?) and 1000 1/16 microsteps backwards, (112°?) does it end up in the same place or move 56° (?) per cycle?

Try less current by using a smaller Vref ( 1.2V? 0.9V? whatever) and see if it moves well.

1 Like

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