SHARE
TWEET

Untitled

a guest Sep 19th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <TMCStepper.h>
  2.  
  3. #define MAX_SPEED        20 // In timer value
  4. #define MIN_SPEED       300
  5.  
  6. #define STALL_VALUE     100 // [0..255]
  7.  
  8. #define EN_PIN          PC1  // Enable
  9. #define DIR_PIN         PC4  // Direction
  10. #define STEP_PIN       PE12  // Step
  11. #define SERIAL_RX        -1  // TMC2208/TMC2224 SoftwareSerial receive pin
  12. #define SERIAL_TX       PD8  // TMC2208/TMC2224 SoftwareSerial transmit pin
  13.  
  14. #define R_SENSE 0.091f// Match to your driver
  15.  
  16. // Select your stepper driver type
  17. //TMC2209Stepper driver(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS);
  18.  
  19. HardwareSerial Serial_xyz(-1, PD8);
  20. TMC2209Stepper driverx(&Serial_xyz, R_SENSE, 0);
  21. TMC2209Stepper drivery(&Serial_xyz, R_SENSE, 1);
  22. TMC2209Stepper driverz(&Serial_xyz, R_SENSE, 2);
  23.  
  24. HardwareSerial Serial_e(-1, PC6);
  25. TMC2209Stepper drivere0(&Serial_e, R_SENSE, 0);
  26. TMC2209Stepper drivere1(&Serial_e, R_SENSE, 1);
  27.  
  28. void setup() {
  29.   Serial.begin(115200);         // Init serial port and set baudrate
  30.   while (!Serial);              // Wait for serial port to connect
  31.   Serial.println("\nStart...");
  32.  
  33.   Serial_xyz.begin(115200);
  34.   Serial_e.begin(115200);
  35.  
  36.   pinMode(EN_PIN, OUTPUT);
  37.   pinMode(STEP_PIN, OUTPUT);
  38.   pinMode(DIR_PIN, OUTPUT);
  39.   // disable steppers
  40.   digitalWrite(EN_PIN, LOW);
  41.   delay(500);
  42.   driverx.senddelay(14);
  43.   delay(10);
  44.   drivery.senddelay(14);
  45.   delay(10);
  46.   driverz.senddelay(14);
  47.   delay(10);
  48.   drivere0.senddelay(14);
  49.   delay(10);
  50.   drivere1.senddelay(14);
  51.   delay(10);
  52.   drvSetupX();
  53. }
  54.  
  55. void drvSetupX() {
  56.   driverx.begin();                 //  SPI: Init CS pins and possible SW SPI pins
  57.                                    // UART: Init SW UART (if selected) with default 115200 baudrate
  58.   driverx.toff(5);                 // Enables driver in software
  59.   driverx.rms_current(600);        // Set motor RMS current
  60.   driverx.microsteps(16);          // Set microsteps to 1/16th
  61.  
  62. //driverx.en_pwm_mode(true);       // Toggle stealthChop on TMC2130/2160/5130/5160
  63. //driverx.en_spreadCycle(false);   // Toggle spreadCycle on TMC2208/2209/2224
  64.   driverx.pwm_autoscale(true);     // Needed for stealthChop
  65. }
  66.  
  67. void loop1() {
  68.   Serial.print("Driver X version ");
  69.   Serial.println(driverx.version());
  70.   Serial.print("Driver X status 0x");
  71.   Serial.println(driverx.DRV_STATUS(), HEX);
  72.  
  73.   Serial.print("Driver Y version ");
  74.   Serial.println(drivery.version());
  75.   Serial.print("Driver Y status 0x");
  76.   Serial.println(drivery.DRV_STATUS(), HEX);
  77.  
  78.   Serial.print("Driver Z version ");
  79.   Serial.println(driverz.version());
  80.   Serial.print("Driver Z status 0x");
  81.   Serial.println(driverz.DRV_STATUS(), HEX);
  82.  
  83.   Serial.print("Driver E0 version ");
  84.   Serial.println(drivere0.version());
  85.   Serial.print("Driver E0 status 0x");
  86.   Serial.println(drivere0.DRV_STATUS(), HEX);
  87.  
  88.   Serial.print("Driver E1 version ");
  89.   Serial.println(drivere1.version());
  90.   Serial.print("Driver E1 status 0x");
  91.   Serial.println(drivere1.DRV_STATUS(), HEX);
  92.  
  93.   delay(1000);
  94. }
  95.  
  96. void loop() {
  97.   digitalWrite(STEP_PIN, 0);
  98.   delayMicroseconds(160);
  99.   digitalWrite(STEP_PIN, 1);
  100.   delayMicroseconds(140);
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top