How to drive a stepper motor with your Arduino Mega using a TMC5130-EVAL

Only a few wires including an SPI port are required to control TMC5130-EVAL with your Arduino. Here are the few steps required to get started.

Preparation

If your Arduino  is a 5V type you have to resolder one resistor on the TMC5130-EVAL from position R3 to R8. This sets the logic level of the TMC5130 to +5V. While by default the resistor is soldered to the “right-hand” position, you have to move it to the “left-hand” position for 5V operation.

Extract from TMC5130-EVAL schematic
Illustration 1 – Extract from TMC5130-EVAL schematic

 

tmc5130-eval-logic-level-resistor
Illustration 2 – Position of the logic level resistor on the TMC5130-EVAL board

Wiring

The wiring is very simple. You will need 8 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 TMC5130-EVAL (As seen on illustration 4). As a reference you can use the TMC5130-Eval_v15_01_Schematic.pdf. Here you’ll find the signals that are on each pin. The configuration is documented in the comment section of the Arduino code.

Pinheader of TMC5130-EVAL
Illustration 3 – Pinheader of TMC5130-EVAL

 

Illustration 4 – TMC5130 wired up with Arduino Mega 2560

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 TMC5130

This example uses an external CLK provided by the Arduino’s pin 11.

You can use the internal CLK of the TMC5130 by tying the CLK16 signal to GND.

Arduino Code

The Arduino Code below does not need any additional libraries. The SPI library comes with the Arduino IDE. The program initializes the TMC5130 and executes a simple move to position cycle. It will rotate a 200 full step motor 10 revolutions to the one and 10 revolutions to the other direction depending on the wiring of the stepper motor. Please use either the TMC5130 datasheet or the TMCL IDE as a reference for the different registers.

Download

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

Related Pages

34 Comments

  • Lars Jaskulski Reply

    The next guide will explain howto use your Raspberry Pi 2 or 3 to communicate with the TMC5130-EVAL and turn the motor with a certain speed in velocity mode by the end of this week.

  • Convertini Reply

    Hi,
    if I attempt to compile this code I get this error message.
    Arduino: 1.8.2 (Windows 8.1), Board: “Arduino Due (Programming Port)”

    C:\Users\iRES-PC\Downloads\TMC5130-EVAL\TMC5130-EVAL.ino: In function ‘void setup()’:

    TMC5130-EVAL:34: error: ‘TCCR1A’ was not declared in this scope

    TCCR1A = bit (COM1A0); //toggle OC1A on Compare Match

    ^

    In file included from C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:44:0,

    from sketch\TMC5130-EVAL.ino.cpp:1:

    TMC5130-EVAL:34: error: ‘COM1A0’ was not declared in this scope

    TCCR1A = bit (COM1A0); //toggle OC1A on Compare Match

    ^

    C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro ‘bit’

    #define bit(b) (1UL << (b))

    ^

    TMC5130-EVAL:35: error: 'TCCR1B' was not declared in this scope

    TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

    ^

    In file included from C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/Arduino.h:44:0,

    from sketch\TMC5130-EVAL.ino.cpp:1:

    TMC5130-EVAL:35: error: 'WGM12' was not declared in this scope

    TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

    ^

    C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro 'bit'

    #define bit(b) (1UL << (b))

    ^

    TMC5130-EVAL:35: error: 'CS10' was not declared in this scope

    TCCR1B = bit (WGM12) | bit (CS10); //CTC, no prescaling

    ^

    C:\Users\iRES-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\cores\arduino/wiring_constants.h:93:25: note: in definition of macro 'bit'

    #define bit(b) (1UL < Preferences.

    • Lars Jaskulski Reply

      Hi Convertini,

      I just double checked with a fresh installation of Arduino IDE V1.8.3 and it compiles fine (with selected Arduino Uno Platform).
      From the error message I can see you try it with an Arduino Due which is an ARM platform. The code is based on the AVR. There might be some changes needed in the code.

      Did you try with a Arduino Leonardo or Mega?

      Best regards,
      Lars

  • j Reply

    Hey,

    Thanks for the Blog post.
    Worked fine with the Arduino Nano.

    Do you know where i find other commands, to change the motor behavior?

    Best regard

    j

  • qorckdtjs001 Reply

    HI j,
    I used this script to operate TMC5130-EVAL. actually i got the perfect result. Thanks

    but just before motor operation. i listen to high note noise from the motor.

    Is it happening to me alone?

    my motor is 1.2A , 24V and 17NEMA Stepper MOTOR

    • Lars Jaskulski Reply

      Hi,

      Great that the example worked for you. Have you tried stealthChop already? You can do so by changing the following code lines (line 46, 52 and 53).

      On line 46 please change the register value to 0x00000004. Comment line 52 and uncomment line 53.


      sendData(0x80,0x00000004); //GCONF

      //sendData(0xF0,0x00000000); // PWMCONF
      sendData(0xF0,0x000401C8); //PWM_CONF: AUTO=1, 2/1024 Fclk, Switch amp limit=200, grad=1

      This will enable the super silent stealthChop mode. Let me know if that worked for you and what you think.

      Best regards,
      Lars

      • qorckdtjs001 Reply

        Oh, Thanks for your rep

        but i had already used that. anyway i will try again.

        and I want to know Silent MODE in the TMC2100 and TMC5130

        both differance? TMC2100 have very silent operation but TMC5130 is not

        plz tell me about that

        Best regards,
        Qor

        • Lars Jaskulski Reply

          Hi Qor,

          To activate stealthChop with the TMC5130 the initial code in this post needs to be adapted a bit described in my previous answer. This will give you the same perfomance you experienced with the TMC2100.

          The perfomance with the TMC2100 and the TMC5130 is the same. With the TMC5130 you have some more flexibility to tune stealthChop due the fact you have registers with the SPI interface.

          Best regards,
          Lars

          • qorckdtjs001

            Hi Lars,

            i give up to operate Stealth mode TMC5130 by SPI .

            So i going to use Step/Dir mode. In TMC5130 datesheet , for the Step/Dir mode. SP_MODE pin tied LOW

            but my TMC5130_EVAL have not that external pin. how to use Step/dir mode

            plz help me about that

            Best regards,
            Qor

          • Lars Jaskulski

            Hi Qor,

            I really want you to use stealthChop with SPI as well. What can I do to help you? What issues do you have? Using stealthChop with SPI is possible. It might be that you need to reduce the velocity. To do so please change the register value for VMAX to a lower value.

            If you like to use STEP/DIR there is a solder jumper located close to the TMC5130. Please download the layout data: https://www.trinamic.com/fileadmin/assets/Products/Eval_Drawings/TMC5130-Eval_v15_LayoutData.zip
            and open the TMC5130-Eval_v15_12_FullViewTop.pdf. You need to solder the R_SD solder jumper.

            Best regards,
            Lars

  • FW Reply

    Hey Lars,

    great tutorial, it really helped me out a lot. As it happens, I’m currently working on a very similar project. I plan to power a motor with the TMC2660-EVAL board controlled by an Arduino. I wanted to drive the TMC2660 board via the step/direction interface, but this doesn’t seem to work.
    My backup plan now is to apply your SPI solution to my problem. I got one question though – Is it possible to use the register library for TMC5130 (TMC5130_registers.h)? Or is there a library for TMC2660?

    I would really appreciate your help on this topic.

    Kind regards,
    Finn

    • Lars Jaskulski Reply

      Hi Finn,

      Thanks for the positive feedback. The wiring will be very close to the TMC5130 wiring described in this post. Anyhow there might be some transfer work involved.

      For the TMC2660 we have our TTAP (Trinamic Technology Access Package) available to download here: https://www.trinamic.com/support/software/access-package/

      It is an API and covers most of our chips. You’ll find the TMC2660 in the folder \TMC-EvalSystem\boards\TMC2660_eval.c

      This might help to get things started. The registers are build up differently and the datagram is only 20 bits. With the TMC5130 it is 40 bits.

      Please let me know if you need further assistance.

      Best regards,
      Lars

      • FW Reply

        Hey Lars,

        thanks for the quick replay and pointing out the TTAP. I wasn’t really aware of that.

        Gonna work on that for now and see where I end up.

        Kind regards
        Finn

      • FW Reply

        Hey Lars,

        me again… I’m still struggling with my TMC2660. I’m fairly certain I got it hooked up correctly, but I’m very unsettled how to configure the timer. I transferred some Basic Setup HEX-Codes from the TMC2660 documentation, but the board still seems dead. Also, it’s irritating to me that the return from SPI.transfer is 0xFF or 255 in decimal.

        If you happen to have spare time for this, I would much appreciate it, if you could have a quick look at my code (please keep in mind, I’m no expert):
        https://github.com/FinnWCode/TMC2660

        Kind Regards
        Finn

        PS: I got the jumpers on the board set to INT_S and INT_D., but EXT_S and EXT_D doesn’t change anything besides that I get 0 instead of 255 as return from transfer.

        PPS: My power supply delivers solid 24 V, the arduino obviously 5V.

        • FW Reply

          Me again…

          Is it possible, that I have to resolder R7 to position R8 in order to set the logic level to 5V?

          • Lars Jaskulski

            Hi Finn,

            When R7 is assembled the V_IO get the supply from the 3V3 LDO. When disassembling R7 and assemble R8 +5V from the USB rail will be used.

            You might need to check the SPI function of Arduino. I am not sure if you can send 5 bytes as you have it in your github example code. Probably the TMC5130 example might help to do the SPI communication.

            I like to build up a TMC2660-EVAL setup to try it myself. I need some spare time and get back to you.

            Best regards,
            Lars

          • Lars Jaskulski

            Hi Finn,
            Did you have success in the mean time? What I recognized is that the delay in your step generation seems to be fairly high. Might be the reason you do not experience any motor movement with a micro step resolution of 256. Looking forward to your reply.
            Best regards,
            Lars

  • FW Reply

    Hey Lars,

    thank you very much for your help.
    You are correct: The SPI.function can indeed only send one byte at a time. I got that fixed in the code linked in my github above.
    After correcting the delays in the step generation and adjusting the motor current, everything is up and running.
    Only concern I have at the moment is a very high pitched noise when the motor is powered on. But I am positive to fix that via the various settings the TMC2660 offers.

    Thanks again and kind regards
    Finn

    • Lars Jaskulski Reply

      Hi Finn,

      Great!

      In regard of the high pitch noise: Please try to modify TOFF in the CHOPCONF register. TOFF = 1 is something you could try first. It might make sense to reduce TOFF to 1 when in standstill and get back to the default value before a movement starts. With TOFF = 0 you completely deactivate the driver stage. If you do not need any holding torque at this position this might be an option as well.

      Since this is off topic I will contact you directly so we can work on your application.

      Best regards,
      Lars

  • Chase Conrad Reply

    Hello,
    I’m thinking about using a TMC5041 because I need to control two motors. Can this code be modified to work with a TMC5041, and how would I move two motors simultaneously? Any help is greatly appreciated.
    Thanks!
    Chase

    • Lars Jaskulski Reply

      Hi Chase,

      Please check out the blog post from Mario: http://blog.trinamic.com/2017/08/02/how-to-drive-a-stepper-motor-via-uart-with-your-arduino-mega-using-a-tmc5072-eval/

      This is based on the TMC5072 dual axis driver band should be a very good starting point. The blog post from Mario usees the single wire UART interface, anyhow the structure of the program might help.

      The SPI communication with The TMC5130 and the TMC5041 is 40 bit so the SPI communication stays the same. The only thing to adapt is the register addressess when using this code example.

      To move motors simultaneously you would simple write the same values in the registers of each axis, for example the target position.

      Let me know if you have furrther questions.

      Best regards,
      Lars

  • Yakov Reply

    Hi,
    if i want to write my own program with arduino and TMC5130 – where can i found a software manual? , or some more guidance and explanation of the syntax and addresses and the data that i need to send from arduino to the driver.
    TX

  • Peter Reply

    Hi Lars I have spend now few week on Internet searching for solution of my problem without success my problem is I em currently upgrading my CNC so i bought some TMC262-BOB60.
    My problem is i want to run it only in step/ dir mode i have been trying write program for arduino nano to send driver configuration to run no success.
    all what i need is set driver to step/dir mode , step size , current limits , stall guard.
    Best regards
    Peter.

  • Chuck Reply

    Hello,

    We have been trying your TMC5130-EVAL-KIT and like the smooth operations and programming features using the Arduino. Can your TMCM-3212 three axis controller be run by an Arduino also? We have XYZ (three axis) projects we would like to adapt for the Arduino if this is possible. We also have a six axis requirement run from an Arduino, perhaps using two 3212’s?

    Thank you for your assistance.
    Chuck

    • Lars Jaskulski Reply

      Hello Chuck,

      The TMCM-3212 can in general be controlled by an Arduino as well. For this case you would use the TMCM-3212-TMCL version and the RS-485 interface. A connection thru USB might work as well. Furthermore you would send TMCL commands that are described in the TMCM-3212 Firmware manual which you can download here: https://www.trinamic.com/products/modules/details/tmcm-3212/#downloads-3

      Let me know if that is what you are looking for or if you have additional question.

      Best regards,
      Lars

  • Chuck Reply

    Hello Lars,

    I just received from Digi-Key the TMCM-3212-TMCL board with the wire loom TMCM-G4-CABLE. I will be trying to use it for repetitive 3 axis motors production with an Arduino. I will store the TMCL 3 motors commands inside the 3212 as a single 3212 function.

    My question is: How do I call this stored function from an Arduino to run the 3 motors?

    If this works with an Arduino, I will buy another 3212 to try for the 6 axis production machines.

    Thank you for your assistance!
    Chuck

  • Chuck Reply

    Hello,

    I have been using the TMCM-3212-TMCL for 3 motors and getting it to work well using Direct Mode binary commands from an Arduino through a MAX RS385 board. I am learning the very powerful Stand Alone use using the TMCL creator to create my program I download into the 3212. Then with just a single 9 byte serial command from the Arduino I can run stored multi-motor routines from the 3212. This is just what I was looking for.

    Is there anything similar for the TMC5130 single motor controller? I noticed there is no 5130 software plugin for the TMCL–IDE 3.0, is this due to no 5130 memory capabilities like the 3212?

    Also it seems the only real difference between the 3212 and the 6 axis TMCM-6212 board is the 6212 has less motor current capability per motor. Are there any other real differences than that?

    Thank you.

    Chuck

  • Tony Mackenzie Reply

    Hi,

    What modification to this code will be needed to get this to run with a TMC5160?

    Best regards,
    Tony

    • Lars Jaskulski Reply

      Hi Tony,
      This should be fairly easy to be done. Please compare the TMC5130 and TMC5160 datasheet. The SPI datagram is pretty much the same but the addresses differ. If you need further support please use our support system on the webpage http://trinamic.com. You find a blue button on the bottom right of each page. Please understand that the comment section is intended to be used for the respective article on this blog and that we can not support other products.
      Best regards,
      Lars

  • ANNA Reply

    Hello Lars
    Great Work ,I need your help to work with TMC5160- TA. I am working with a driver with LPC1313 as its controller. I like to use STEP/DIR mode.please pass me any information you have about it.

    • Lars Jaskulski Reply

      Hi Anna,
      Thank you! Please use the support system on our webpage to get support for the TMC5160. Please understand that the comment section is intended to be used for the corresponding blog entry.
      You find a blue button on the bottom right on every page of our main webpage: trinamic.com
      Best regards,
      Lars

Leave a Reply

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