Controlling tmc 2209 with an Arduino Uno via UART

Hi,

I'm trying to control my tmc 2209 via UART with an Arduino Uno. I found this forum post and followed it as good as I could.

Here is my wiring:

And here is my code:

#include <TMCStepper.h>

#define STEP_PIN         3 
#define SERIAL_PORT Serial 
#define R_SENSE 0.11f 
#define DRIVER_ADDRESS 0b00 
#define MICROSTEPS 16

TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);

void setup() {
  SERIAL_PORT.begin(115200);      // INITIALIZE UART TMC2209
  Serial.begin(115200);
  delay(500);
  Serial.println(F("Serial Initialized"));

  driver.begin();                // Initialize driver
  driver.toff(5);                 // Enables driver in software

  driver.rms_current(600);       // Set motor RMS current
  driver.microsteps(MICROSTEPS); 

  driver.pwm_autoscale(true);    // Needed for stealthChop
  driver.en_spreadCycle(false);   // false = StealthChop / true = SpreadCycle
  driver.shaft(false); 

  Serial.print(F("microsteps: "));   Serial.println(driver.microsteps());
  Serial.print(F("current: "));   Serial.println(driver.rms_current()); 
}

void loop() {
  digitalWrite(STEP_PIN, HIGH);
  delay(3.6);
  digitalWrite(STEP_PIN, LOW);
  delay(3.6);
}

It also kinda works. The motor turns with the expected microstepping and the serial print also returns the correct values for microstepping and the current.
The Problem is that the step stick uses the current value set by the screw and not the value set by UART.

I don't know why but no matter what current value I set via UART the motor always uses 200ma even if the serial Print reports that the value was set to 600ma. And if I now start to turn the screw the current changes.
I thought the value set by the screw is overwritten if UART is configured?

Any ideas?

Read:

" On some Arduino boards (e.g. Uno, Nano, Mini , and Mega) pins 0 and 1 are used for communication with the computer on the serial port named "Serial". Pins 0 and 1 cannot be used on these boards to communicate with the TMC2209.
Connecting anything to these pins can interfere with that communication, including causing failed uploads to the board.

Arduino boards with additional hardware serial ports, such as "Serial1" and "Serial2", can use those ports to communicate with the TMC2209."

Ref: " GitHub - janelia-arduino/TMC2209: The TMC2209 is an ultra-silent motor driver IC for two phase stepper motors with both UART serial and step and direction interfaces.

Thank you so much, this was the problem.
I simply switched to software serial (as used in the TMCStepper example) and now it works just fine.

1 Like

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