Trinamic's TMC5160-Eval with an Aruidno Mega

Explore and tune StallGuard2 with the TMC5160-EVAL + Arduino Mega 2560 in step and direction mode

In this blog article we wire up a Arduino Mega2560 with a TMC5160-EVAL board to run in it STEP/DIR mode, use a timer to generate a fixed frequency for the STEP input. The diagnostic diag0 output pin of the TMC5160 will be used to indicate a defined load condition we want to react on. In this case we stop the motor respectively stop the step output of the Arduino.

Only ten wires are required to control the TMC5160-EVAL with your Arduino. Here are the steps to get started.


If your Arduino is a 5V type you have to desolder one resistor on the TMC5130-EVAL from position R211 and solder it to position R212. This sets the logic level of the TMC5130 to +5V as seen in the circuitry below.

Illustration 1 – TMC5160-EVAL – Voltage selection

While by default the resistor is soldered to the lower position, you have to move it to the upper position as shown in the red area below for 5V operation.

Illustration 2 – TMC5160-EVAL resistor selector for logic supply voltage


The wiring is very simple. You will need 10 jumper wires. To make the wiring more easy you can print out the TMC5130-EVAL_Pinning.pdf and cut out the template to mount it on the connector header of the TMC5160-EVAL (As seen on illustration 4). As a reference you can use the TMC5160-EVAL schematic. Here you’ll find the signals that are on each pin. The configuration is documented in the comment section of the Arduino code.

Illustration 3 – Pin header of TMC5160-EVAL

TMC5160 setup wiring with Arduino Mega
Illustration 4 – Arduino Mega 2560 wired up to TMC5160-EVAL for STEP/DIR mode

Cable colors of illustration 4
+5V –> red
GND –> blue
SDO –> yellow
SDI –> orange
SCK –> white
CSN –> grey
DRV_ENN –> black
CLK16 –> green

Using the internal CLK of the TMC5160

This example uses the internal CLK of the TMC5160. To use the internal CLK simply connect the CLK16 pin to GND.

Step pulse generation

To generate the step pulses a timer is used with a pre scaler of 1024. With a system CLK of the Arduino ATMEGA2560 of 16MHz that results in a 7.8125kHz frequency. As there is no ramping a jump start from velocity 0 to 7812.5 pps is done which should work with most motors. If not a acceleration ramp needs to be implemented.

The TMC5160 offers an internal Motion Controller that can be used as described with the TMC5130 blog post. As some people like to start with a step direction approach this blog post does cover this. Usually when people do try out the Motion Controller they will see the big benefits and make use of it. It does take off a lot of software work! The TMC5160 either starting in step direction and then explore the Motion Controller or directly evaluate the Motion Controller is a great procedure.

Arduino Code

The Arduino Code below does not need any additional libraries. The SPI library comes with the Arduino IDE. The program initializes the TMC5160. Please use either the TMC5160 datasheet or the TMCL IDE as a reference for the different registers.


The file includes the pinning template, the TMC5160-EVAL schematic and the Arduino project.

Related Pages