How to drive a stepper motor with your Raspberry Pi 3/2 using a TMC5130-EVAL

In this start up guide you get explained how to connect your Raspberry Pi 3 or 2 for the basic operation of the TMC5130-EVAL board. It will use the internal Motion Controller and +3V3 logic supply for the TMC5130. The wiring will be limited to the basic functionallity to communicate via SPI. The internal CLK for the TMC5130 will be used respective the CLK16 pin (Shown on figure 1) has to be tied to GND. The SPI CLK frequency of the Raspberry Pi will be set up to be 1MHz.


With a fresh installation of Raspbian (In this tutorial Raspbian Jessy Lite – Version March 2017 – Release date 2017-03-02) first update the libraries:

This may take a while since it will upgrade all packages that are installed to the newest version if available. Furthermore it will upgrade dependencies or remove them if they have been replaced with other dependencies.

Download and install the bcm2835 library. Note XXX is a place holder for the latest version. For this guide version “1.52” was used. In this case XXX is replaced by “1.52”. You can check the latest version by scrolling to the bottom of the following page:

Afterwards restart your PI by typing.



The wiring is very simple. You will need 8 jumper wires. As a reference you can use the TMC5130-Eval_v15_01_Schematic.pdf. You will find the signals that are on each pin.

Signal Raspberry Pi 2 TMC5130-EVAL
+5V +5V (2) +5V (5)
GND GND (39) GND (2)
TMC5130 enable GND (9) DIO_0 (8)
TMC5130 CLK GND (6) CLK16 (23)
Chip select (CS) SPI0 CS0 (24) SPI1_CSN (30)


Pinheader of TMC5130-EVAL


Raspberry Pi 3 GPIO Header
Raspberry Pi 3 GPIO Header – Source:

Raspberry 3 wired up with TMC5130-EVAL
Raspberry 3 wired up with TMC5130-EVAL


Please note that the TMC5130-EVAL has to be powered with the supply voltage e.g. 24V. To avoid damage only disconnect or connect a motor without supply voltage.

Raspberry Pi Code

An example code to initialize the TMC5130 is shown below. It will clear the reset flag in the GCONF register, sets example chopper configurations and sets the run and hold current for the motor. Furthermore it will set the ramping mode to velocity mode, an acceleration and a velocity. Be aware that the motor runs as soon as you execute the script.
You can download the code directly with your pi by typing:

Compiling and running the code

Please use the following command to compile the code.

This compiles the file spi-5130.c

Now you are able to execute the example.

Related Pages


  • parovelb Reply

    Good reference. And how to connect a RPi2/3 to a TMCM 6110 RS485 with a db9 connector?

    • Lars Jaskulski Reply

      Hello, thanks for your feedback! Connecting a Raspberry Pi with a TMCM-6110 sounds interesting. We do not have an example ready but it sounds like a great idea. Are you currently working on that?

      • parovelb Reply

        Yes, I am working on that. I have trouble finding the complete pinout diagram for the rs485 connector of the module. In the hardware manual only the DATA+ (pin 7), DATA- (pin 2) and POWER(GND) (pin 3) are mentioned.

        • Lars Jaskulski Reply

          Hi, that is correct. The TMCM-6110 comes with a 2-wire RS-485 interface (Half-Duplex).
          Furthermore it seems that you will need additional RS-485 transceiver Hardware for the Pi. You’ll find ready to use modules / addons but could develop your own electronic as well.
          I could think of using a USB to RS-485 converter connected to the Raspberry Pi as well. Sureley depends on the compatibility of the drivers but might be worth a try.

  • A Hacking Reply

    I have a few questions:

    Any example code for Python?

    As I understand the 5130 chip enables real time control of the stepper motor which is a huge benefit when working with a system like the RPi.

    How would you implement the end-stop detection in python via the stepper motor?



    • Lars Jaskulski Reply

      Hi Adam,

      Currently we do not have code examples available for python but this is a good idea for a future blog post.
      The end-stop detection is mainly dependent on the stallGuard2 feature. First a SPI communication to the chip is necessary. After that you can configure the responsible registers fitting for your needs.

      Below a screen capture on youtube that shows the necessary steps when using our GUI – TMCL IDE and the TMC5130-EVAL-KIT.

      You’ll find additional information on stallGuard2 in the TMC5130 datasheet and in an application note.

      I hope that helps and feel free to share your results with the RPi using python + stallGuard2.

      Best regards,

Leave a Reply

Your email address will not be published. Required fields are marked *