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

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

20 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

Leave a Reply

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