DIY DTG - Build your own Digital T-Shirt Printer

 
cesar_00
Contributor
Topic Author
Posts: 4
Joined: Thu Sep 15, 2016 2:39 pm

HELP: Height adjustment system with two steppers

Tue May 16, 2017 7:35 am

Hey Guys, I´ve been working in a lifting system to move the printer up and down with a joystick command, two stepper motors with t8 screws. I found an arduino code from brainybits website that can move one nema 17 stepper with a joystick using easydriver controller. 
My problem is that I need to modify this code to run  the 2 steppers at the same time. how can i modify this code to do the job?


Other questions are: can I use the same module joystick  in parallel to connect the two arduinos with the same code to move the steppers at the same time?
                                 or, can i use  the Arduino outputs  in parallel to command two easydrivers  or other controllers to run two steppers at the same time?
  
I would be nice to contribute with that, I will upload images and plans  as soon as i got some answers how to modify this.
Thanks in advance!


the code:


#define step_pin 9  // Pin 9 connected to Steps pin on EasyDriver
#define dir_pin 8   // Pin 8 connected to Direction pin
#define MS1 10       // Pin 10 connected to MS1 pin
#define MS2 11       // Pin 11 connected to MS2 pin
#define SLEEP 12     // Pin 12 connected to SLEEP pin

#define X_pin A0    // Pin A0 connected to joystick x axis
#define Joy_switch 4  // Pin 4 connected to joystick switch

#define Limit01 2  // Pin 2 connected to Limit switch out
#define Limit02 3  // Pin 3 connected to Limit switch out

int step_speed = 10;  // Speed of Stepper motor (higher = slower)

void setup() {
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(SLEEP, OUTPUT);
 
  pinMode(Limit01, INPUT);
  pinMode(Limit01, INPUT);
 
  pinMode(Joy_switch, INPUT_PULLUP);
 
  digitalWrite(SLEEP, HIGH);  // Wake up EasyDriver
  delay(5);  // Wait for EasyDriver wake up
 

/* Configure type of Steps on EasyDriver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/

  digitalWrite(MS1, LOW);      // Configures to Full Steps
  digitalWrite(MS2, LOW);    // Configures to Full Steps
}

void loop() {
 if (!digitalRead(Joy_switch)) {  //  If Joystick switch is clicked
   delay(500);  // delay for deboucing
   switch (step_speed) {  // check current value of step_speed and change it
     case 1:
       step_speed=10;  // slow speed
       break;
     case 3:
       step_speed=1;  // fast speed
       break;
     case 10:
       step_speed=3;  // medium speed
       break;
   }
 }    
   
 if (analogRead(X_pin) > 712) {  //  If joystick is moved Left
   if (!digitalRead(Limit01)) {}  // check if limit switch is activated
   
     else {  //  if limit switch is not activated, move motor clockwise
     
       digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
       digitalWrite(step_pin, HIGH);
       delay(step_speed);
       digitalWrite(step_pin, LOW);
       delay(step_speed);
   }      
 }
 
   if (analogRead(X_pin)
< 312) {  // If joystick is moved right
   
   if (!digitalRead(Limit02)) {}  // check if limit switch is activated
   
     else {  //  if limit switch is not activated, move motor counter clockwise
     
       digitalWrite(dir_pin, HIGH);  // (HIGH = [color=#005c5f]anti-clockwise
/ LOW = clockwise)
       digitalWrite(step_pin, HIGH);
       delay(step_speed);
       digitalWrite(step_pin, LOW);
       delay(step_speed);
   }      
 }
}
[/color]
You do not have the required permissions to view the files attached to this post.
Last edited by cesar_00 on Wed May 24, 2017 6:08 am, edited 1 time in total.
 
User avatar
Andy
Site Admin
Posts: 1433
Joined: Mon Jul 25, 2016 5:59 pm

Re: HELP: Heigh adjustment system with two steppers

Tue May 16, 2017 7:43 am

If you want them to both run exactly the same just run the motor step and direction wires to 2 different motor drivers.
 
cesar_00
Contributor
Topic Author
Posts: 4
Joined: Thu Sep 15, 2016 2:39 pm

Re: HELP: Heigh adjustment system with two steppers

Tue May 16, 2017 9:09 am

Thank you Andy!

Who is online

Users browsing this forum: No registered users and 1 guest