TMC2209 stepper driver on an Arduino Uno
A NEMA 17 on a TMC2209 with STEP, DIR and EN on pins 2, 3 and 4: one turn each way at the default 1/8 step, 1600 pulses a turn. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 25 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $45. On Mokxi they're free.
What you'll learn
- Step and direction control of a stepper
- Microstepping and pulses per turn
- Active-low enable pins
- Separate logic and motor power
- Generating pulses with
delayMicroseconds
- Difficulty: Intermediate
- Time: About 25 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
A TMC2209 driver turns simple step and direction signals into motor coil currents. The Uno's pins 2, 3 and 4 go to STEP, DIR and EN. The driver's logic runs from the Uno's 5V, and the motor power comes from a separate 12 V supply.
Left alone, the TMC2209 is in 1/8 step, so a 200-step motor needs 1600 pulses per turn. EN is active low, so the sketch holds it LOW to enable the driver.
The loop does one turn forward, waits half a second, does one turn back, and waits again. Each turn is 1600 short pulses.
Parts list
4 parts, plus the jumper wires. They retail for about $45; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × TMC2209 stepper driver
- 1 × Stepper motor, NEMA 17
- 1 × Power, 12 V
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| TMC2209 stepper driver pin GND | Arduino Uno R3 pin GND |
| TMC2209 stepper driver pin EN | Arduino Uno R3 pin 4 |
| TMC2209 stepper driver pin DIR | Arduino Uno R3 pin 3 |
| TMC2209 stepper driver pin STEP | Arduino Uno R3 pin 2 |
| TMC2209 stepper driver pin VIO | Arduino Uno R3 pin 5V |
| TMC2209 stepper driver pin VM | 12 V |
| Stepper motor, NEMA 17 pin B2 | TMC2209 stepper driver pin M2B |
| Stepper motor, NEMA 17 pin B1 | TMC2209 stepper driver pin M2A |
| Stepper motor, NEMA 17 pin A1 | TMC2209 stepper driver pin M1A |
| Stepper motor, NEMA 17 pin A2 | TMC2209 stepper driver pin M1B |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A NEMA 17 on a TMC2209 SilentStepStick, from an Uno, with plain pulses.
//
// TMC2209 STEP -> pin 2 DIR -> pin 3 EN -> pin 4
// TMC2209 VIO -> 5V GND -> GND
// TMC2209 VM / GNDM -> 12 V, M1A M1B and M2A M2B -> the motor's two coils
//
// The TMC2209 takes STEP and DIR like an A4988, but there is no RST or SLP to
// link, and with MS1 and MS2 left alone it is in 1/8 step, not full step: a
// 200 step motor takes 1600 pulses a turn. EN is active low.
const int STEP_PIN = 2;
const int DIR_PIN = 3;
const int EN_PIN = 4;
const int PER_TURN = 200 * 8;
void turn(bool forward) {
digitalWrite(DIR_PIN, forward ? HIGH : LOW);
for (int i = 0; i < PER_TURN; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(620);
}
}
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
Serial.begin(9600);
Serial.println("Mokxi Uno: TMC2209 at 1/8 step, one turn each way");
}
void loop() {
turn(true);
Serial.println("one turn forward");
delay(500);
turn(false);
Serial.println("and back");
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
turn sketch.ino
It sets DIR_PIN HIGH for forward or LOW for backward. Then it sends PER_TURN pulses (200 x 8 = 1600). Each pulse is STEP high for 5 microseconds and low for 620, and each pulse moves the motor one microstep.
void turn(bool forward) {
digitalWrite(DIR_PIN, forward ? HIGH : LOW);
for (int i = 0; i < PER_TURN; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(620);
}
}setup sketch.ino
It makes the STEP, DIR and EN pins outputs and writes LOW to EN_PIN to enable the driver, since the enable is active low. Then it opens serial and prints a start message.
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
Serial.begin(9600);
Serial.println("Mokxi Uno: TMC2209 at 1/8 step, one turn each way");
}loop sketch.ino
It calls turn(true) for one turn forward, prints a message, and waits 500 ms. Then it calls turn(false) to turn back, prints "and back", and waits 500 ms. This repeats forever.
void loop() {
turn(true);
Serial.println("one turn forward");
delay(500);
turn(false);
Serial.println("and back");
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The motor does not move This project
Check VIO is on 5V and VM on 12 V, and the grounds are joined. Also check the EN pin is held LOW. - A turn is not one full turn This project
PER_TURNassumes 1/8 step. If you change the microstep setting, change that number to match. - The motor does not move or just buzzes. TMC2209 stepper driver
Power VM with 4.75 to 29 V and the logic VIO. Enable pulls low to turn on. Check the coil wires are two matched pairs, and connect the grounds. - The driver overheats or the motor is weak. TMC2209 stepper driver
Set the current limit with the reference voltage before running. Do not exceed the rating of the motor, and add a heat sink for sustained use. - The motor buzzes, shudders, or only vibrates instead of turning. Stepper motor
Coils are swapped. Find the two coil pairs by measuring resistance with a meter (a few ohms between wires of one coil). Connect each pair to one driver coil output, A to A and B to B. - The motor stalls or loses steps when you speed up. Stepper motor
A stepper cannot jump to a high speed. Start with slow step pulses and ramp up gradually. Check the driver current limit (Vref) and give the supply enough voltage, such as 12 V. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.