UART Interface, TMC2208 and Arduino Nano

Hi All,

I'm trying to run a NEMA17 stepper motor at a low constant speed and need maximum torque from the stepper engine. Currently, the stepper motor is running with the wanted rpm, however, it seems that the serial connection (UART) is not established since spreadCycle and the defined microstep are ignored.
The connections between the TMC2208 v3.0 and Arduino Nano are as follows (in respective order):

  • VI0 to 5V
  • GND to GND
  • OB2, OB1, OA1, OA2 to stepper motor
  • GND and VM to 20V external power supply
  • DIR to D5
  • STEP to D2
  • PDN/UART split into two where 1k resistor is added before TX and the other to RX
  • EN to GND

The jumper on the driver board is soldered to enable the UART communication (According to the datasheet of the driver board)

The code in Arduino IDE is as follows:

// Defining
#define StepPin     2
#define DirPin      5
#define SERIAL_PORT Serial

#define InvertDir   HIGH
#define Current     1200
#define MicroStep   16
#define R_Sense     0.11

// Including library
#include <TMC2208Stepper.h>                       // Include library
TMC2208Stepper driver = TMC2208Stepper(&Serial, R_Sense);  // Create driver and use

// Setup
void setup() {
  SERIAL_PORT.begin(9600);
  Serial.begin(9600);             // Init used serial port
  while(!Serial);                 // Wait for port to be ready

  // Prepare pins
  pinMode(DirPin, OUTPUT);
  pinMode(StepPin, OUTPUT);

  driver.pdn_disable(1);              // Use PDN/UART pin for communication
  driver.I_scale_analog(0);           // Adjust current from the registers
  driver.rms_current(Current);        // Set driver current 500mA
  driver.toff(0x2);                   // Enable driver
  driver.en_spreadCycle(1);
  driver.shaft(InvertDir);
  driver.microsteps(MicroStep);

  digitalWrite(DirPin, InvertDir);         // Invert direction
}

// Looping
void loop() {
  digitalWrite(StepPin, !digitalRead(StepPin)); // Step
  delay(4);
}

I strongly suspect that there is something in the code that I'm missing since I don't have great knowledge of Arduino coding.

I've looked everywhere on different forums, videos and library documentation, but it doesn't seem to work. Please, if you have any comments that might be helpful, I would appreciate it!

I'm not sure about why the spread cycle is not being enabled, but for the microsteps, I think you need to add this line

driver.mstep_reg_select(1)

0: Microstep resolution selected by pins MS1, MS2
1: Microstep resolution selected by MSTEP register

Thanks for your input!
However, it didn't change. It was like the serial connection was not established. The rotational direction was also ignored.
I did a lot of different stuff, mostly trial and error, and found a solution in the end. If I disconnect the RX connection, then it works completely fine. I have no idea why. But here is the code which is working for me:

// Defining
#define StepPin     2
#define RX_PIN      0
#define TX_PIN      1

#define Current     1200
#define MicroStep   0     // 0: Native 256 microstep setting.
                          // 1: 128 microsteps per full step.
                          // 2: 64 microsteps per full step.
                          // 3: 32 microsteps per full step.
                          // 4: 16 microsteps per full step.
                          // 5: 8 microsteps per full step.
                          // 6: 4 microsteps per full step.
                          // 7: 2 microsteps per full step.
                          // 8: Full step.

// Including library
#include <TMC2208Stepper.h>                                // Include library
TMC2208Stepper driver = TMC2208Stepper(RX_PIN, TX_PIN);    // Create driver and use

// Setup
void setup() {
  driver.beginSerial(115200);    
  driver.push();

  // Prepare pins
  pinMode(StepPin, OUTPUT);

  driver.pdn_disable(1);              // Use PDN/UART pin for communication
  driver.I_scale_analog(0);           // Adjust current from the registers
  driver.rms_current(Current);        // Set driver current 
  driver.toff(5);                     // Enable driver
  driver.shaft(1);
  driver.en_spreadCycle(0);           // 1: spreadCycle
                                      // 0: stealthChop
  driver.pwm_autoscale(1);            // 1: if stealthChop is chosen. Otherwise 0
  driver.mstep_reg_select(1);
  driver.mres(MicroStep);
}

// Looping
void loop() {
  digitalWrite(StepPin, !digitalRead(StepPin));  // Step
  delayMicroseconds(100);
}

One possibility is that you got the dual wire Y connection wrong, or somehow, depending on the different input impedances, the Tx signal goes preferentially into the Arduino Rx and not the 2208 one wire uart.

I'll definitely look into that, thanks!
However, is it a problem running with the RX disconnected? As described, it is only running a single stepper motor at a constant speed

is it a problem running with the RX disconnected?

If you are not receiving information from the 2208 (like stall guard readings) there's no issue.

For simple stepper operation, running with the current set by the pot, microsteps set by the pins, and stepper control by the Arduino, there may not be an advantage for the uart connection.

Is there there a reason to be using more than 1/16 microsteps? It's not clear to me what advanced functions you are using which are available from the uart and not in default step/dir mode?

I understand your question.
The setup is used to drive a drum in a coffee roasting setup I've built. The plan is that the maximum capacity is a batch of 500g beans. For this, I need high torque from the stepper motor. In the code provided, I've not toggled in the setting such as spreadCycle or microsteps, which I think is contributing to the torque? In short, I wanted to be able to alternate these settings, since it might the necessary to rotate the drum with 500g beans. However, I'm still in the building phase of the coffee roaster
I hope this make sense

In my understanding of TMC2208 v3.0 manual, you have to either use "STEP/DIR" or "UART", both simultaneously is not valid.

Link to the manual:

Please don't tell us you are using the stepper motor as one of the end bearings for the drum! You already know how many rpm is needed by the drum, so use a belt and pulley system to reduce the motor speed and increase the torque on the drum.

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