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

46 Comments

  • Lars Jaskulski

    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

    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

    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

    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

    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

    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

    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

    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

  • FW

    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

    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

    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

    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.

  • 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

  • FW

    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 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

  • 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

    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

    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

    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

    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

    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

    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.

  • Lars Jaskulski

    Hi Yakov,
    The datasheet of the TMC5130 has all the information that you need to know what to send to what address. Please check:
    https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5130_datasheet.pdf

    On page 29 the documentation of the registers start.

    Additionally you can check the TMC5130-EVAL manual:
    https://www.trinamic.com/fileadmin/assets/Products/Eval_Documents/TMC5130_Eval_manual.pdf

    The basic SPI communication described above is the start to write and read the registers and the rest is your software work 😉

    You can check our API as well (scroll to the bottom of the page):
    https://www.trinamic.com/support/software/access-package/

    Hope that helps,
    Best regards,
    Lars

  • Chuck

    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

    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

    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

    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

    Hi,

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

    Best regards,
    Tony

  • ANNA

    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

    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

  • Lars Jaskulski

    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

  • Alex M

    Hello,

    It seems I found bug/mistake in the TMC5130 datasheet. Have a look at the page 103 (23 DC Motor or Solenoid)

    There is:
    1) “Bits 8..0 control motor A and Bits 24..16 control motor B PWM”
    2) “Setting the corresponding PWM bits between -255 and +255 (signed, two’s complement numbers) will vary motor voltage from -100% to 100%.”

    If I understood it correctly only 8 bits used to regulate power from -100% to 100%. In that case it should be values -128 to +127 accordingly.
    Please correct me if I am wrong.

  • Daniel Frenkel

    Is there any reason or advantage to use the internal clock (CLK16) rather than the external clock provided by the SPI master?

  • BAEK

    Hello Lars
    im using TMC5130 for my project. its a great!
    and i need your help to work with tmc5130-TA..
    in the introduce TMC5130 on youtube, there is a Button of actual position clear. right?
    I wanna working TMC5130 to reset Actual position
    Actually I am using the power shorting method. but it
    s not smart
    so i wanna code about reset actual position or other thing

    Best regards,

  • Lars Jaskulski

    Hello,
    You can simply write 0 to the actual position register.
    Best regards,
    Lars

  • BAEK

    Hello Lars,
    Thank you for your reply.
    But the problem was not solved.
    Your method is to turn the motor back to its initial position.

    I want to know how to set the current position of the motor the initial value.

    Currently I am using the power off method to set initial value. Is there another way?

    Best regards,

  • Lars Jaskulski

    Hello,
    If you want to reset the position you need to do the following:
    1) Set VMAX = 0 (If you don’t the motor will turn to the new target position if in position mode)
    2) Set the actual position to 0
    3) Set the target position to 0

    Hopefully that should give your intended results. If not let us know.

    Best regards,
    Lars

  • Lars Jaskulski

    Hi Alex,
    Thanks for the hint. We check your finding and correct it if needed and provide a new documentation with the next release of the datasheet.
    Much appreciated!
    Best regards,
    Lars

  • Christian

    Hallo Lars,
    this is a wonderful work and a nice blog. I’m trying this with the TMC2130-EVAL, isn’t the code quite similar ? I was not sucessful with the EVAL-Kit, i.e. using the Landungsbrücke. The motor is blocking easily at high velocities (more than 200) or with microstepping (only up to halfstep 🙁 ), but this may be an issue of the motor. I want to setup StallGuard, which needs higher velocities, if I understood this right. My intention in using the arduino is that I’m driving a similar motor with the SilentStepStick 2130, which runs quite smoothly but so far without StallGuard.

  • Emil

    Hi Lars,

    Thanks for the example, it helped me getting started with TMC5130. However, I am having trouble enabling the dcStep feature of the controller. I am pretty sure I have set everything correctly, however, the motor misses steps and doesn’t slow down when I apply a load. Do you have any examples of how to configure the dcStep?

    Thanks!

  • Lars Jaskulski

    Hi Emil,
    To make an example with dcStep is a good idea. Right now we can offer the application note AN003_-_dcStep_Basics_and_Wizard.pdf
    Please check if that helps you. If you have further questions or need additional support please do not hesitate to use our support system. You’ll find a blue button on every page of our main webpage: http://www.trinamic.com
    Best regards,
    Lars

Leave a Reply

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