How to use TMC2208 Stepper Motor Driver with Arduino

Published  July 17, 2024   0
TMC2208 Stepper Motor Driver

Today, we are going to explore the TMC2208, a popular driver module used for controlling 2-phase bipolar stepper motors. Known for its high efficiency and quiet operation, the TMC2208 is designed by Trinamic, a German company that specializes in motion control products. This driver module is widely used in various applications, thanks to its ability to deliver smooth and silent performance. A close alternative for the TMC2208 is the A4800 Stepper driver and we have already discussed how to use A4988 Stepper driver with Arduino, you can also check that our if you are interested. Also here at circuit digest we have also built more such Arduino projects and tutorials  all which is free to learn so do check them out if you wish to read more. 

Now lets get back to our TMC2208 stepper driver module understand its basics and learn how to use it with an Arduino UNO board. 

 

FTMC2208 Stepper Driver Module

TMC2208 Module

Here, let's look at some of the important features of the TMC2208 stepper motor driver module.

Silent Operation

One of the standout features of the TMC2208 is its ability to operate almost silently. This is achieved through Trinamic’s StealthChop2, a no-noise, high-precision chopper algorithm for inaudible motion and inaudible standstill of the motor.

Smooth Running

The TMC2208 has a micro step interpolator that provides up to 256 micro steps, allowing for very fine control over motor movements. This results in smoother motion and higher precision in positioning.

Simple Connectivity

The TMC2208 is designed for easy integration with existing systems. It supports a standard step/dir interface and can be configured through UART for advanced features and fine-tuning.

Current Control

With the TMC2208, you can easily adjust the motor current through an onboard potentiometer or UART communication. This allows for optimal performance and efficiency by minimizing heat generation and power consumption.

Automatic Standstill Power Down

This sensor less load detection feature allows the TMC2208 to detect motor stalls and provide feedback without the need for additional sensors. It enhances reliability and protects the motor from drawing excessive current.

Safeguards and Safety

TRINAMIC motor drivers offer safeguards to detect and protect against shorted outputs, output open circuit, overtemperature, and undervoltage conditions. These features enhance safety and ensure recovery from equipment malfunctions.

TMC2208 Pinout

Being a beginner, the 16 pins of this module might look complex, but believe me, it's simple to understand and use. Below, you can see the pinout marking of the TMC2208 stepper driver module using the actual driver image. At this time, I would like to mention that the module we are using in this tutorial is the TMC2208 V2.0, so kindly refer to it appropriately.

TMC2208 Stepper Driver Module Pinout

Next, let's see the detailed description of the pinouts of the TMC2208 module. Below, you can see a table describing the pins in short.

Pin No Pin Name Type Description
1 EN Digital Input Driver Enable Pin
2 MS1 Digital Input (pd) Microstep resolution configuration Pins
3 MS2 Digital Input (pd) Microstep resolution configuration Pins
4 NC - No Connections
5 PDN Digital Input & Output Pin responsible for automatic power down when kept low. Can also be used for UART communication.
6 CLK Digital Input Clock Input for connecting external clock if needed.
7 STEP Digital Input Step Input
8 DIR Digital Input (pd) Direction Input, Active Low
9 GND Power Ground Connection pin
10 VIO Power 3.3v to 5v IO Supply Coltage for all digital pins
11 M2A Analog Output Motor coil A Output 2
12 M1A Analog Output Motor coil A Output 1
13 M1B Analog Output Motor coil B Output 1
14 M2B Analog Output Motor coil B Output 2
15 GND Power Ground Connection pin
16 VM Power Motor supply voltage Pin
  (pd) - Active Pull-Down    

So, here are the detailed descriptions of the pinouts:

EN: This is the power enable pin for the motor power supply. Keeping it HIGH turns off the motor, and keeping it LOW turns on the motor.

MS1 & MS2: These are digital input pins used to configure the microstep resolution. Below, you can see a table that defines the respective micro step resolution for the provided input pattern.

MS1 MS2 Micro step Resolution
LOW LOW 1/8
LOW HIGH 1/2
HIGH LOW 1/4
HIGH HIGH 1/16

NC: This means no connection pin, so don't care about it.

PDN: This pin is a bit confusing as it can act as both input and output. If this pin is kept low, automatic standstill current reduction happens to reduce power wastage and the chance of overheating. Alternatively, this pin can be directly utilized as a UART input and output pin, which is an optional feature. Remember that in this module, this pin is connected to a jumper. If you need to use it, you must connect the jumper first; otherwise, the pin is internally configured as PullDown.

CLK: This is a clock input pin. If this pin is pulled LOW, the internal clock is utilized. Otherwise, you can provide an external clock signal. This is recommended for advanced use cases. For example, using a lower clock pulse like 4MHz can reduce power consumption and electromagnetic emissions, but it may sacrifice some performance accordingly.

STEP: This pin is used to control a step of the stepper motor. Each rising edge can rotate the shaft by one step.

DIR: This pin is used to control the direction of the motor. It determines whether the motor rotates clockwise or counterclockwise. Factors like motor wiring affect the actual direction. To simplify, keeping it LOW rotates the motor in one direction, while keeping it HIGH rotates it in the opposite direction.

M2A, M1A, M1B, M2B: These pins are where the motor gets connected. Finding the right wire configuration is straightforward. To simplify, you can use a continuity meter to identify the end terminals of each coil. These two individual coils are known as Coil A and Coil B. Connect the Coil A terminals to M1A and M2A, and the Coil B terminals to M1B and M2B respectively. That's it.

VIO, VM, GND: These are the power inputs for the driver module. Typically, every ground terminal is common. VIO powers the driver input and output, and VM powers the motor alone. VIO operates at around 3 to 5.5 volts, while VM should match the voltage requirements of the motor itself.

I hope you understand the pinouts and their descriptions of the TMC2208 driver module. Next, let's learn more about this hardware.

TMC2208 Schematic

To know more about the hardware, let's take a look at its schematic. Below is the actual module, the TMC2208 V2.0 stepper motor driver, used to provide an outline of the components onboard.

TMC2208 Parts Marking

Next, you can see the schematic of the module that we reverse-engineered. This helps people who are interested in integrating the TMC2208 IC directly into their project. It's also helpful for electronics enthusiasts to understand more about the internals of the module and how it works.

TMC2208 Schematic

Things I like to mention about this schematic:

  • The TMC2208 V2.0 module closely follows the application schematic found in the official datasheet.
  • Most of the required pins are directly connected to the header pins of the module, except for PDN and CLK. These two are electrically isolated using a jumper resistor. You can locate the jumper resistor in the parts marking image above. To bypass the jumper, simply solder the two pads provided there, ensuring no other components are disturbed.
  • There are three test pins available for advanced use cases.
  • Every ground is connected here to maintain a common ground.
  • A 110 milli ohm sense resistor is used to allow for the maximum current provided by the module. According to the datasheet, 110 milli ohms is suitable for motors rated up to 1.5A current.

Moreover, the other aspects of the schematics are self-explanatory. So, we have completed the overall hardware explanation and next, we will be interfacing this sensor with Arduino.

Components Required for Interfacing the TMC2208 Driver Module with Arduino

Hardware:

  1. Arduino UNO x 1
  2. NEMA17 Stepper Motor x 1
  3. TMC2208 Stepper Driver Module x 1
  4. BreadBoard x 1
  5. Jumper Wires Required Quantity

Software:

  1. Arduino IDE

Circuit Diagram for Interfacing the TMC2208 Driver Module with Arduino

To make it simple to get started, I won't cover the complex application and working of the TMC2208. Below, you can see a simple circuit diagram of interfacing the TMC2208 stepper driver module with the Arduino UNO. If you are completely new to stepper motors please check out our article to on how stepper motor works?, to understand the basics. 

Circuit Diagram for TMC2208 Interfacing with Arduino UNO

We are using a 5V power supply for both the digital I/Os and the motor, sourced from the Arduino UNO board. This is suitable for our demonstration project, but normally, we would use a separate power supply. To control the TMC2208, we'll use three digital pins on the Arduino (8, 9, and 10), which correspond to the EN, STEP, and DIR pins on the TMC2208. Any digital output pins can be used for this purpose. We're not using UART communication to keep things simple.

Motor Wiring Reference for TMC2208 Module

Next, we'll connect the motor to the driver. The motor has four wires, which are the ends of two separate coils. You can find the right coil wires by checking the continuity. Connect coil A wires to M1A and M2A, and coil B wires to M1B and M2B. It's straightforward, and you don't need to worry about the polarity of the coils—it will just change the direction of the motor without causing any issues. Refer to the diagram above for detailed connection instructions.

Assembled Hardware Image of TMC2208 Interfacing with Arduino Uno

Above, you can see the assembled image of the hardware. As mentioned, I am just using the Arduino 5V power rail to power up everything.

Next, let's move to the coding part of controlling the stepper motor.

Code for Interfacing the TMC2208 Module with Arduino UNO

As we are not using UART to control the motor, the code will look simpler. Here, we are going to perform functions like rotating the motor at a fixed speed and alternating the motor's rotation direction. So, let's get into the code.

Initially, you can see the Pin Definitions. As discussed, I am using pins 8, 9, and 10 of the Arduino UNO which connect to EN, STEP, and DIR of the TMC2208.

// Pin Definitions
#define EN_PIN 8    // LOW: Driver enabled, HIGH: Driver disabled
#define STEP_PIN 9  // Step on the rising edge
#define DIR_PIN 10  // Set stepping direction

Next, there are two variables declared. ‘noOfSteps’ controls the number of steps needed to be moved, and ‘microSecondsDelay’ sets the delay between each step-in microsecond.

int noOfSteps = 250;           // Number of steps to move in each direction
int microSecondsDelay = 1000;  // Delay in microseconds between each step

In the void setup() function, pins 8, 9, and 10 are set as OUTPUT. Initially, the Direction pin (DIR_PIN) is set LOW to establish the starting direction. The Enable pin (EN_PIN) is also set LOW, which activates the driver and powers the motor. Keeping EN_PIN HIGH would deactivate the motor, regardless of the driver's state. This setup ensures that the motor is enabled and ready to operate when the program starts.

void setup() {
  // Configure pin modes
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);

  // Initialize pin states
  digitalWrite(DIR_PIN, LOW);  // Set initial direction
  digitalWrite(EN_PIN, LOW);   // Enable the driver
}

In the `void loop()` function, there are two identical `for` loops that control a stepper motor. Each loop toggles the direction of the motor by changing the state of the `DIR_PIN`. The motor alternates between moving forward and backward, determined by whether `DIR_PIN` is set to low or high. 

void loop() {
  // Move the motor in one direction
  digitalWrite(DIR_PIN, LOW);  // Set direction to LOW
  for (int i = 0; i < noOfSteps * 2; i++) {
    digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));  // Toggle the step pin
    delayMicroseconds(microSecondsDelay);            // Wait for the specified delay
  }

  // Move the motor in the opposite direction
  digitalWrite(DIR_PIN, HIGH);  // Set direction to HIGH
  for (int i = 0; i < noOfSteps * 2; i++) {
    digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));  // Toggle the step pin
    delayMicroseconds(microSecondsDelay);            // Wait for the specified delay
  }
}

During each loop iteration, the motor takes a specified number of steps (`noOfSteps * 2`) and pauses briefly between steps (`delayMicroseconds(microSecondsDelay)`) to regulate its speed. This process repeats continuously, demonstrating basic motor control using digital signals and delays.

The motor moves one step per transition of the `STEP_PIN` from low to high, which is crucial for its rotation. Changing the direction is straightforward: keeping `DIR_PIN` low increments steps, while setting it high decrements steps. This setup illustrates fundamental motor driving principles using straightforward digital control techniques.

You can find the link to the complete code at the end of this article. Next, let's look at the working demonstration of the TMC2208.

Working Demonstration of TMC2208 Module Interfacing with Arduino UNO

After uploading the code to the Arduino Uno and making all the necessary connections, you can see the motor sweep. We already know there are three factors that affect motor rotation: MicroStep Resolution, Timing between each step, and Direction configuration. You can modify these factors to explore and learn more about controlling the servo using the TMC2208 module.

Above, you can see a GIF video demonstrating the project with the current configuration I used during the circuit connection and coding.

Frequently Asked Questions

TMC2208 Vs TMC2209

Actually, the TMC2209 is a newer model compared to the TMC2208 and comes packed with many additional features. Let's compare the two by looking at the table below.

Feature TMC2208 TMC2209
Step/Dir Interface Yes Yes
UART Interface Yes Yes
MicroPlyer Interpolation (Smooth running) Yes Yes
Microstep Resolution 256 256
StallGuard (Sensorless load and stall detection) No Yes
CoolStep (Current Control for energy saving) No Yes
StealthChop (Silent motor operation) Yes Yes
Drain Source Resistance - Low State 280mΩ 170mΩ
Drain Source Resistance - High State 290mΩ 170mΩ
Maximum Current 2A peak 2.8A peak
Voltage Range 4.75V - 36V 4.75V - 29V

The TMC2209 offers enhanced features like lower driver resistance, StallGuard, and CoolStep, making it more advanced and versatile compared to the TMC2208.

TMC2208 v3.0 Module

The module we used in this article is the TMC2208 v2.0. However, there is a newer module called the BIGTREETECH TMC2208-V3.0 Stepper Motor Driver. This v3.0 module is made by BIGTREETECH, a popular company known for manufacturing 3D printers.

Features of TMC2208 V3.0

Versatility in Thermals: The TMC2208 V3.0 module is designed with improved thermal management.
Component Layout: Most components are hidden below the PCB, except for the potentiometer used for tmc2208 current setting.
Documentation: BIGTREETECH provides comprehensive documentation for this module, making it easier to use and integrate.

Conclusion

If you can afford it, the TMC2208 V3.0 is a better choice due to its enhanced features and better design for thermal management. However, if budget is a concern, the TMC2208 v2.0 is also a good option and performs well.

Additional Motor Drivers and Project Ideas

Motor Drivers

  1. Stepper Motor Control with A4988 Stepper Motor Driver and Arduino UNO
  2. Control a NEMA 17 Stepper Motor with Arduino and DRV8825

Project Ideas

If you are looking for some project ideas related to stepper motors, below are some useful links:

  1. Automatic Bottle Filling System using Arduino
  2. DIY Motorized Camera Slider using Arduino and Stepper Motors for Video Shooting
  3. Arduino-based Roller Blinds to Automate and Control your Window Curtains with Google Assistant

These resources and project ideas can help you explore various applications of stepper motors and expand your knowledge and skills in working with them.

 

 

Code

// Pin Definitions
#define EN_PIN 8    // LOW: Driver enabled, HIGH: Driver disabled
#define STEP_PIN 9  // Step on the rising edge
#define DIR_PIN 10  // Set stepping direction

 

int noOfSteps = 250;           // Number of steps to move in each direction
int microSecondsDelay = 1000;  // Delay in microseconds between each step

 

void setup() {
  // Configure pin modes
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);

  // Initialize pin states
  digitalWrite(DIR_PIN, LOW);  // Set initial direction
  digitalWrite(EN_PIN, LOW);   // Enable the driver
}

 

void loop() {
  // Move the motor in one direction
  digitalWrite(DIR_PIN, LOW);  // Set direction to LOW
  for (int i = 0; i < noOfSteps * 2; i++) {
    digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));  // Toggle the step pin
    delayMicroseconds(microSecondsDelay);            // Wait for the specified delay
  }

  // Move the motor in the opposite direction
  digitalWrite(DIR_PIN, HIGH);  // Set direction to HIGH
  for (int i = 0; i < noOfSteps * 2; i++) {
    digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));  // Toggle the step pin
    delayMicroseconds(microSecondsDelay);            // Wait for the specified delay
  }
}

Have any question realated to this Article?

Ask Our Community Members