How to make Stepper motor stop with TMC260 Stepper Motor Driver Shield
Hi All,
I'm currently trying to create a program that turns a motor one way and once sensor detect the object, begin going the other way. I'm using Arduino Uno R3 and TMC 260 Stepper Motor Driver Shield. I'm sure it might be simple, but I've been stuck on this for a while and really need some help now...
I'm currently trying to create a program that turns a motor one way and once sensor detect the object, begin going the other way. I'm using Arduino Uno R3 and TMC 260 Stepper Motor Driver Shield. I'm sure it might be simple, but I've been stuck on this for a while and really need some help now...
Code: Select all
Thanks for your help!#include <SPI.h>
#include <TMC26XStepper.h>
const byte sensor1 = 3;
const byte led = 13; //LED will be on pin 13
//we have a stepper motor with 200 steps per rotation,CS pin 6, dir pin 4, step pin 5 and a current of 300mA
TMC26XStepper tmc26XStepper = TMC26XStepper(200,6,4,5,800);
void setup() {
Serial.begin(9600);
Serial.println("==============================");
Serial.println("TMC26X Stepper Driver App");
Serial.println("==============================");
//set this according to you stepper
Serial.println("Configuring stepper driver");
//char constant_off_time, char blank_time, char hysteresis_start, char hysteresis_end, char hysteresis_decrement
tmc26XStepper.setSpreadCycleChopper(2, 24, 8, 6, 0);
tmc26XStepper.setRandomOffTime(0);
tmc26XStepper.SPI_setCoilCurrent(100);
tmc26XStepper.setMicrosteps(128);
tmc26XStepper.setStallGuardThreshold(4, 0);
Serial.println("config finished, starting");
Serial.println("started");
pinMode(sensor1, INPUT);
pinMode(led, OUTPUT);
Serial.println("setup() complete");
Serial.println(" ");
}
void loop() {
if (digitalRead(sensor1) == 0){ // 0 = On / NO(Normally Open)
Serial.println("1 Detected");
tmc26XStepper.SPI_setSpeed(300); // Set 120 RPM per minute
tmc26XStepper.SPI_step(-2000); // Set the running steps to -2000 steps
tmc26XStepper.spi_start() ;
}
delay (5000);
if (digitalRead(sensor1) == 1){ // 1 = Off / NO(Normally Open)
Serial.println("1 Still Not Detected");
tmc26XStepper.SPI_setSpeed(300); // Set 200 RPM per minute
tmc26XStepper.SPI_step(3000); // Set the running steps to 3000 steps
tmc26XStepper.spi_start();
delay (2000);
tmc26XStepper.SPI_setSpeed(300); // Set 200 RPM per minute
tmc26XStepper.SPI_step(-3000); // Set the running steps to 3000 steps
tmc26XStepper.spi_start();
delay (2000);
do{
if(digitalRead(sensor1) == 0){
Serial.println("1 Detected");
tmc26XStepper.SPI_setSpeed(3000); // Set 200 RPM per minute
tmc26XStepper.SPI_step(3000); // Set the running steps to 3000 steps
tmc26XStepper.spi_start();
}
}while(digitalRead(sensor1) == 1);
}
}
}