# How to control motor driver?

**URL:** <https://forum.arduino.cc/t/how-to-control-motor-driver/1025240>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [August 24, 2022, 1:52pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240 "2022-08-24T13:52:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gugu51](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gugu51/32/1099080_2.png) [@gugu51](https://forum.arduino.cc/u/gugu51)\
**Post date:** [August 24, 2022, 1:52pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/1 "2022-08-24T13:52:00Z")

</div>

Hello!

i could need some insights on how to control my new stepper motor:  
i got the 17HS15-1504S-X1 and the tmc2208.  
Now i need the RPM of about 100.  
For now i did most like this: [Stepper Motor Driver TMC2208 - FabLab Kannai - Fab Academy 2022](https://fabacademy.org/2022/labs/kannai/Instruction/tips/stepper_TMC2208/)  
But wasnt able to use the tmc-lib since i dont understand the sample of the imported lib completly and was scared of doing something wrong ☹

Wiring like this

 ![grafik](https://europe1.discourse-cdn.com/arduino/original/4X/4/5/5/4554b175ea53cb9d4d5ccb20f7d4a7eb1d5f8333.png)

Right now im using this code for testing:

```cpp
/*
  SilentStepStick TMC2208/TMC2209 Example
  Rsense: 0.11 Ohm
  Other examples/libraries can be found here:
  https://github.com/teemuatlut/TMCStepper
  https://github.com/trinamic/TMC-API
  https://github.com/manoukianv/TMC2208Pilot
  Example source code free to use.
  Further information: https://learn.watterott.com/license/
*/

// Note: You also have to connect GND, 5V/VIO and VM.
// A connection diagram can be found in the schematics.
#define EN_PIN 7 //enable (CFG6)
#define STEP_PIN 8 //step
#define DIR_PIN 9 //direction

void setup()
{
  //set pin modes
  pinMode(EN_PIN, OUTPUT);
  digitalWrite(EN_PIN, HIGH); //deactivate driver (LOW active)
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(DIR_PIN, LOW); //LOW to CCW
  //digitalWrite(DIR_PIN, HIGH); //HIGH to CW
  pinMode(STEP_PIN, OUTPUT);
  digitalWrite(STEP_PIN, LOW);

  digitalWrite(EN_PIN, LOW); //activate driver
}

void loop()
{
  //make steps
  digitalWrite(STEP_PIN, HIGH);
  delay(2);
  digitalWrite(STEP_PIN, LOW);
  delay(2);
}

```

But even with delay(1) its to slow. I thought it would mean 2ms per step, with 200 steps=\> 400ms per full rotation. But it takes roughly 3seconds per full rotation. So this might be due to the step-length (e.g. full step, half, 1/4 ..).  
But where do i control this - since it doesnt seem to be controlled via software.

Also: for the small stepper motor of the arduno starter kit i used the stepper.h -lib. With that i could set the speed to e.g 300 or something like this. Is it possible to use this lib while using the tmc or is it like "one or the other"?  
Im sorry, its like there is SO MUCH knowledge online - but im confused by all the different aproaches, wiring, components..

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [August 24, 2022, 2:56pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/2 "2022-08-24T14:56:47Z")

</div>

What I see is your loop() code is telling the stepper to step many thousands of time per second. You need to compute the number of steps per second to give you the RPM you need. Then delay the number of milliseconds after each step to give the motor time to react to the step pulse. You do know the number of steps you motor need to make one revolution, don't you?

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [August 24, 2022, 3:49pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/3 "2022-08-24T15:49:28Z")

</div>

[Robin2's simple stepper program tutorial](https://forum.arduino.cc/t/simple-stepper-program/268292) may have information of interest.

To achieve higher speeds you will need to accelerate the motor. It cannot reach those speeds from a dead stop. Use the [AccelStepper](https://www.airspayce.com/mikem/arduino/AccelStepper/) or the [MobaTools stepper](https://github.com/MicroBahner/MobaTools) libraries. I think MobaTools easier to learn.

The Stepper library that comes with the Arduino IDE will not support step/dir type drivers like the TNC2208, TMC2209, A4988, DRV8825, ...

---

<div class="post-metadata">

**Author:** ![gugu51](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gugu51/32/1099080_2.png) [@gugu51](https://forum.arduino.cc/u/gugu51)\
**Post date:** [August 24, 2022, 4:14pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/4 "2022-08-24T16:14:32Z")

</div>

Thanks for your replys!

I want to have like 120 RPM.  
That's 2 full rotations per second. The stepper got 200 steps, so 400 steps per second. So 400 times per sec high and then low. With a delay of 1 ms it would be 500 steps per sec, which is way faster than its going.

I will definitely look into the mobatools, looks like a good start.

Like I said, I got the lib from TMC, I guess I should take a look into the documentation of that...

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [August 24, 2022, 4:40pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/5 "2022-08-24T16:40:03Z")

</div>

Remember that a stepper motor, by design must STOP between steps because that could be the last step needed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 20, 2023, 4:40pm UTC](https://forum.arduino.cc/t/how-to-control-motor-driver/1025240/6 "2023-02-20T16:40:27Z")

</div>

Closed on February 20, 2023, 4:40pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
