TMC26XMotorTester.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. TMC26XMotorTest.ino - - TMC26X Stepper library Example for Wiring/Arduino
  3. Copyright (c) 2011, Interactive Matter, Marcus Nowotny
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #include <SPI.h>
  21. #include <TMC26XStepper.h>
  22. //you may adapt this to your shield or breakout board connection
  23. #define CS_PIN 2
  24. #define DIR_PIN 6
  25. #define STEP_PIN 7
  26. #define ENABLE_PIN 8 //if it is not connected it won't be a problem
  27. #define TIMER_CLOCK_FREQ 2000000.0 //2MHz for /8 prescale from 16MHz
  28. #define INITIAL_CURRENT 500 //in mA
  29. #define MAX_SPEED 1000
  30. //we have a stepper motor with 200 steps per rotation, CS pin 2, dir pin 3, step pin 4 and a current of 300mA
  31. TMC26XStepper tmc26XStepper = TMC26XStepper(200,CS_PIN,DIR_PIN,STEP_PIN,INITIAL_CURRENT);
  32. char running;
  33. void setup() {
  34. //configure the enable pin
  35. pinMode(ENABLE_PIN, OUTPUT);
  36. digitalWrite(ENABLE_PIN,HIGH);
  37. startSerial();
  38. startMotor();
  39. //set this according to you stepper
  40. Serial.println(F("started"));
  41. }
  42. void loop() {
  43. loopSerial();
  44. runMotor();
  45. }