Advertisement
Guest User

Stepper motor test with Spark Core

a guest
Aug 24th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. #include "AccelStepperSpark/AccelStepperSpark.h"
  2.  
  3. // Define the steppers/drivers and the step/dir pins used
  4. AccelStepper stepperSmall(AccelStepper::DRIVER, D5, D4);
  5.  
  6. // Define Microstepping pins
  7. #define MODE0 D0
  8. #define MODE1 D1
  9. #define MODE2 D2
  10.  
  11. int pos = 1200;
  12.  
  13. void setup()
  14. {
  15.  
  16.   /*
  17.  
  18.   Micrstepping table for the DRV8825
  19.   ----------------------------------
  20.  
  21.   MODE0  MODE1   MODE2   MICROSTEP RESOLUTION
  22.   =====   =====   =====   ====================
  23.   Low    Low     Low     Full step
  24.   High   Low     Low     Half step
  25.   Low    High    Low     1/4 step
  26.   High   High    Low     1/8 step
  27.   Low    Low     High    1/16 step
  28.   High   Low     High    1/32 step
  29.   Low    High    High    1/32 step
  30.   High   High    High    1/32 step
  31.  
  32.   */
  33.  
  34.   pinMode(MODE0, OUTPUT);
  35.   pinMode(MODE1, OUTPUT);
  36.   pinMode(MODE2, OUTPUT);
  37.  
  38.   digitalWrite(MODE0, LOW);
  39.   digitalWrite(MODE1, LOW);
  40.   digitalWrite(MODE2, LOW);
  41.  
  42.   stepperSmall.setMaxSpeed(800.0);
  43.   stepperSmall.setAcceleration(200.0);
  44.   stepperSmall.setSpeed(400);
  45.  
  46. }
  47.  
  48. void loop()
  49. {
  50.   if (stepperSmall.distanceToGo() == 0)
  51.   {
  52.     delay(500);
  53.     pos = -pos;
  54.     stepperSmall.moveTo(pos);
  55.   }
  56.   stepperSmall.run();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement