Hello Dr. Flo,
Thank you for your prompt response. I have replaced the Y-axis stepper drivers with DM542 drivers, and now all the motors are functioning correctly. For your reference, I am sharing the updated code.
Could you please guide me on how to modify the OTTO G-code and advise on what should be included in the Python code so I can proceed further? I also added a capacitor to reduce noise in my system ,I would also shorten their legs and I successfully synchronized the Y1 and Y2 motors. You were right—I made a mistake in the code by separating the Enable pins instead of the Direction pins, which likely caused the noise and mismatches.
#include <AccelStepper.h>
// Define stepper pins for Z-axis
#define Z_EN_PIN 27
#define Z_STEP_PIN 25
#define Z_DIR_PIN 26
// Define stepper pins for X-axis
#define X_EN_PIN 3
#define X_STEP_PIN 4
#define X_DIR_PIN 5
// Define stepper pins for Y-axis
#define Y_EN_PIN 35
#define Y_STEP_PIN 37
#define Y_DIR_PIN_Y1 36 // Direction for Y1
#define Y_DIR_PIN_Y2 34 // Direction for Y2 (different direction pin for Y2)
// Define stepper pins for P-axis
#define P_EN_PIN 8
#define P_STEP_PIN 9
#define P_DIR_PIN 10
// Configure the stepper for Z, X, Y1, Y2, and P
AccelStepper stepperZ(AccelStepper::DRIVER, Z_STEP_PIN, Z_DIR_PIN);
AccelStepper stepperX(AccelStepper::DRIVER, X_STEP_PIN, X_DIR_PIN);
AccelStepper stepperY1(AccelStepper::DRIVER, Y_STEP_PIN, Y_DIR_PIN_Y1);
AccelStepper stepperY2(AccelStepper::DRIVER, Y_STEP_PIN, Y_DIR_PIN_Y2);
AccelStepper stepperP(AccelStepper::DRIVER, P_STEP_PIN, P_DIR_PIN);
void setup() {
Serial.begin(9600);
// Enable pins (optional)
pinMode(Z_EN_PIN, OUTPUT);
digitalWrite(Z_EN_PIN, LOW); // Enable Z driver
pinMode(X_EN_PIN, OUTPUT);
digitalWrite(X_EN_PIN, LOW); // Enable X driver
pinMode(Y_EN_PIN, OUTPUT);
digitalWrite(Y_EN_PIN, LOW); // Enable Y1 and Y2 drivers
pinMode(P_EN_PIN, OUTPUT);
digitalWrite(P_EN_PIN, LOW); // Enable P driver
// Set up motor parameters
stepperZ.setMaxSpeed(12000); // Set max speed for Z
stepperZ.setAcceleration(5000); // Set acceleration for Z
stepperX.setMaxSpeed(12000); // Set max speed for X
stepperX.setAcceleration(4000); // Set acceleration for X
stepperY1.setMaxSpeed(12000); // Set max speed for Y1
stepperY1.setAcceleration(4000); // Set acceleration for Y1
stepperY2.setMaxSpeed(12000); // Set max speed for Y2
stepperY2.setAcceleration(4000); // Set acceleration for Y2
stepperP.setMaxSpeed(12000); // Set max speed for P
stepperP.setAcceleration(4000); // Set acceleration for P
Serial.println("Setup complete");
}
void loop() {
// Move Z-axis forward
Serial.println(“Moving Z-axis forward 1 full rotation”);
stepperZ.moveTo(3200);
while (stepperZ.distanceToGo() != 0) {
stepperZ.run();
}
delay(500);
// Move X-axis forward
Serial.println("Moving X-axis forward 1 full rotation");
stepperX.moveTo(3200);
while (stepperX.distanceToGo() != 0) {
stepperX.run();
}
delay(500);
// Move both Y1 and Y2 motors synchronously but in opposite directions
Serial.println("Moving Y1 and Y2 forward (counter directions)");
stepperY1.moveTo(3200); // Move forward 1 full rotation
stepperY2.moveTo(-3200); // Move backward 1 full rotation (opposite direction)
while (stepperY1.distanceToGo() != 0 || stepperY2.distanceToGo() != 0) {
stepperY1.run();
stepperY2.run();
}
delay(500);
// Move P-axis forward
Serial.println("Moving P-axis forward 1 full rotation");
stepperP.moveTo(3200);
while (stepperP.distanceToGo() != 0) {
stepperP.run();
}
delay(500);
// Reverse Z-axis
Serial.println("Reversing Z-axis");
stepperZ.moveTo(0);
while (stepperZ.distanceToGo() != 0) {
stepperZ.run();
}
delay(500);
// Reverse X-axis
Serial.println("Reversing X-axis");
stepperX.moveTo(0);
while (stepperX.distanceToGo() != 0) {
stepperX.run();
}
delay(500);
// Reverse both Y1 and Y2 motors
Serial.println("Reversing Y1 and Y2 (counter directions)");
stepperY1.moveTo(0); // Return to start position
stepperY2.moveTo(0); // Return to start position (opposite direction)
while (stepperY1.distanceToGo() != 0 || stepperY2.distanceToGo() != 0) {
stepperY1.run();
stepperY2.run();
}
delay(500);
// Reverse P-axis
Serial.println("Reversing P-axis");
stepperP.moveTo(0);
while (stepperP.distanceToGo() != 0) {
stepperP.run();
}
delay(500);
}
I have attached the limit switch and optocoupler connection details for your review ( I connected all the ground to power supply ground )