Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. /**
  2. * Author Teemu Mäntykallio
  3. * Initializes the library and turns the motor in alternating directions.
  4. */
  5.  
  6. #define EN_PIN 44 // Nano v3: 16 Mega: 38 //enable (CFG6)
  7. #define DIR_PIN 38 // 19 55 //direction
  8. #define STEP_PIN 40 // 18 54 //step
  9. #define CS_PIN 42 // 17 64 //chip select
  10. #define MOSI_PIN 51
  11. #define MISO_PIN 50
  12. #define SCK_PIN 52
  13.  
  14. bool dir = true;
  15.  
  16. #include <TMC2130Stepper.h>
  17. TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN, MOSI_PIN, MISO_PIN, SCK_PIN);
  18.  
  19. void setup() {
  20. Serial.begin(115200);
  21. while(!Serial);
  22. Serial.println("Start...");
  23. driver.begin(); // Initiate pins and registeries
  24. driver.rms_current(50); // Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
  25. driver.stealthChop(1); // Enable extremely quiet stepping
  26.  
  27. digitalWrite(EN_PIN, LOW);
  28.  
  29. Serial.print("DRV_STATUS=0b");
  30. Serial.println(driver.DRV_STATUS(), BIN);
  31. }
  32.  
  33. void loop() {
  34. digitalWrite(STEP_PIN, HIGH);
  35. delayMicroseconds(1);
  36. digitalWrite(STEP_PIN, LOW);
  37. delayMicroseconds(1);
  38. uint32_t ms = millis();
  39. static uint32_t last_time = 0;
  40. if ((ms - last_time) > 2000) {
  41. if (dir) {
  42. Serial.println("Dir -> 0");
  43. driver.shaft_dir(0);
  44. } else {
  45. Serial.println("Dir -> 1");
  46. driver.shaft_dir(1);
  47. }
  48. dir = !dir;
  49. last_time = ms;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement