Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. /* Arduino Multiple Stepper Control Using The Serial Monitor
  2.  
  3. Created by Yvan / https://Brainy-Bits.com
  4.  
  5. This code is in the public domain...
  6.  
  7. You can: copy it, use it, modify it, share it or just plain ignore it!
  8. Thx!
  9.  
  10. */
  11.  
  12. #include "AccelStepper.h"
  13. // Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
  14.  
  15. // AccelStepper Setup
  16.  
  17.  
  18. AccelStepper stepperX(1, 8, 9); // 1 = Easy Driver interface
  19. // UNO Pin 8 connected to STEP pin of Easy Driver
  20. // UNO Pin 9 connected to DIR pin of Easy Driver
  21.  
  22. // Stepper Travel Variables
  23. long TravelX; // Used to store the X value entered in the Serial Monitor
  24.  
  25. int move_finished=1; // Used to check if move is completed
  26.  
  27.  
  28. void setup() {
  29.  
  30. Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds
  31.  
  32. // Print out Instructions on the Serial Monitor at Start
  33. Serial.println("Enter Travel distance seperated by a comma: X,Z ");
  34. Serial.print("Enter Move Values Now: ");
  35.  
  36. // Set Max Speed and Acceleration of each Steppers
  37. stepperX.setMaxSpeed(500.0); // Set Max Speed of X axis
  38. stepperX.setAcceleration(500.0); // Acceleration of X axis
  39.  
  40. }
  41.  
  42.  
  43. void loop() {
  44.  
  45. while (Serial.available()>0) { // Check if values are available in the Serial Buffer
  46.  
  47. move_finished=0; // Set variable for checking move of the Steppers
  48.  
  49. TravelX= Serial.parseInt(); // Put First numeric value from buffer in TravelX variable
  50. Serial.print(TravelX);
  51. Serial.print(" X Travel , ");
  52.  
  53.  
  54. stepperX.moveTo(TravelX); // Set new move position for X Stepper
  55.  
  56. delay(1000); // Wait 1 seconds before moving the Steppers
  57. Serial.print("Moving Steppers into position...");
  58. }
  59.  
  60. // Check if the Steppers have reached desired position
  61. if ((stepperX.distanceToGo() != 0) || (stepperZ.distanceToGo() !=0)) {
  62.  
  63. stepperX.run(); // Move Stepper X into position
  64.  
  65. }
  66.  
  67. // If move is completed display message on Serial Monitor
  68. if ((move_finished == 0) && (stepperX.distanceToGo() == 0) && (stepperZ.distanceToGo() == 0)) {
  69. Serial.println("COMPLETED!");
  70. Serial.println("");
  71. Serial.println("Enter Next Move Values (0,0 for reset): "); // Get ready for new Serial monitor values
  72. move_finished=1; // Reset move variable
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement