#include <SPI.h>
#include <TMC26XStepper.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
//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 Demo 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");
mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module
mp3_set_volume (30);
pinMode(3, INPUT);
}
void loop() {
if (digitalRead(3) == 1)
{
tmc26XStepper.SPI_setSpeed(250); //Set 120 RPM per minute
tmc26XStepper.SPI_step(-1000); //Set the running steps to 200 steps
tmc26XStepper.spi_start() ; //Motor starting
delay(100);
mp3_play (1); //play mp3
delay (5000);
tmc26XStepper.SPI_setSpeed(250); //Set 120 RPM per minute
tmc26XStepper.SPI_step(1000); //
tmc26XStepper.spi_start() ;
delay(100);
}
}