Help Needed - Controlling 3 stepper motors through a Gecko G540

Hi All

I am starting to loop a little bit in my first attempt at setting up an old CNC mill that I want to control off of 2 joysticks. I am trying to get the X, Y & Z on the joysticks and the centre press on both joysticks to toggle through 3 speeds for the steppers.

Attached is what I have come up with for wiring but the code side of things I am struggling to find exactly what I need.

So I have 2 questions -

1 - does this wiring diagram look correct for what I am trying to do?
2 - would there be anyone able to assist in helping me write the code?

Hopefully I have made some sense and not confused everyone!

Thanks
Dwayne

here

in your circuit, there should be a common ground between driver and arduino

hi KASSIMSAMJI , ive had a look at that one didnt seem to cover what i was looking for… but could be just me… lol i dont know what im doing…

ive found a code that ive hacked at… but 100% got no idea… this look ok?

also changed the wireing lay out added limit switches in attachment…

#define step_pin 2  // Pin 2 connected to X Steps pin 2 on g540
#define dir_pin 3   // Pin 3 connected to X Direction pin 3 on g540
#define step_pin 4  // Pin 4 connected to Y Steps pin 4 on g540
#define dir_pin 5   // Pin 5 connected to Y Direction pin 5 on g540
#define step_pin 6  // Pin 6 connected to Z Steps pin 6 on g540
#define dir_pin 7   // Pin 7 connected to Z Direction pin 7 on g540



#define X_pin A0    // Pin A0 connected to joystick VRx axis
#define Y_pin A1    // Pin A1 connected to joystick VRy axis
#define X_pin A2    // Pin A2 connected to joystick VRz axis
#define Joy_switch 8  // Pin 8 connected to joystick switch

#define Limit + 10  // Pin 10 connected to Limit switch +
#define Limit - 9   // Pin 9  connected to Limit switch -

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

void setup() {

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
  pinMode(SLEEP, OUTPUT);
  
  pinMode(Limit+, INPUT);
  pinMode(Limit-, INPUT);
  
  pinMode(Joy_switch, INPUT_PULLUP);
  
  digitalWrite(SLEEP, HIGH);  // Wake up g540
  delay(5);  // Wait for g540 wake up
  

/* Configure type of Steps on g540
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/

 
}

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(Limit+)) {}  // 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(Limit-)) {}  // check if limit switch is activated
   
     else {  //  if limit switch is not activated, move motor counter clockwise
     
       digitalWrite(dir_pin, HIGH);  // (HIGH = anti-clockwise / LOW = clockwise)
       digitalWrite(step_pin, HIGH);
       delay(step_speed);
       digitalWrite(step_pin, LOW);
       delay(step_speed);
   }

see sticky post above and learn how to use code tags please

so did you test that code? if yes ,what worked and what didn't?

KASSIMSAMJI:
see sticky post above and learn how to use code tags please

so did you test that code? if yes ,what worked and what didn’t?

hi, got the code tags sorted…

and no, i did more research on the code and it was for use with a “Easy Driver board” so i don’t think it will work with the g540 so back to square one

It would help if you write what you expect to happen, what components you have (are these 2 gray things joysticks or what?), do the components work as intended, ....