-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathTMC2130_AccelStepper.ino
47 lines (40 loc) · 1.54 KB
/
TMC2130_AccelStepper.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Author Teemu Mäntykallio
* Initializes the library and turns the motor in alternating directions.
*/
#define EN_PIN 38 // Nano v3: 16 Mega: 38 //enable (CFG6)
#define DIR_PIN 55 // 19 55 //direction
#define STEP_PIN 54 // 18 54 //step
#define CS_PIN 40 // 17 40 //chip select
constexpr uint32_t steps_per_mm = 80;
#include <TMC2130Stepper.h>
TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);
#include <AccelStepper.h>
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);
void setup() {
SPI.begin();
Serial.begin(9600);
while(!Serial);
Serial.println("Start...");
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
driver.begin(); // Initiate pins and registeries
driver.rms_current(600); // Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
driver.stealthChop(1); // Enable extremely quiet stepping
driver.stealth_autoscale(1);
driver.microsteps(16);
stepper.setMaxSpeed(50*steps_per_mm); // 100mm/s @ 80 steps/mm
stepper.setAcceleration(1000*steps_per_mm); // 2000mm/s^2
stepper.setEnablePin(EN_PIN);
stepper.setPinsInverted(false, false, true);
stepper.enableOutputs();
}
void loop() {
if (stepper.distanceToGo() == 0) {
stepper.disableOutputs();
delay(100);
stepper.move(100*steps_per_mm); // Move 100mm
stepper.enableOutputs();
}
stepper.run();
}