Open xAdhamx opened 7 months ago
You are trying to move motors using a Ramps 1.4 board and a (your) Arduino program. Steppers work on a Ramps board but I have never tested a servo.
First I would try the grbl-l-mega firmware to be sure all is connected OK and your ramps shield, drivers, steppers, etc are OK. You need to use the RAMPS branch.
Even if the grbl-l-mega firmware is working, it is still possible that the arduino AccelStepper library is not working with the pins you selected. So the next step would be to try the AccelStepper library using one of the AccelStepper examples and AccelStepper pin configuration. If that is working, change the pin configuration to the pin selected on the ramps board (do not use the ramps shield) and see if things are working. Last would be to try the ramps shield.
Grbl-L-Mega is modified for a lathe. It could be that the modifications broke the servo code. To test a servo, It is better to use the original grbl-mega version. To get the servo running, you could follow the same procedure.
Start by connecting just 1 stepper. If that is running, add the remaining steppers one by one.
Please let me know the results,
Best regards, Huub
I checked the file cpu_map.h for the ramps configuration and the pin mapping differs from yours
// Define step pulse output pins.
#define STEP_BIT_0 0 // X Step - Pin A0
#define STEP_BIT_1 6 // Y Step - Pin A6
#define STEP_BIT_2 3 // Z Step - Pin D46
#define STEP_PIN(i) _PIN(STEP_PORT_##i)
// Define step direction output pins.
#define DIRECTION_BIT_0 1 // X Dir - Pin A1
#define DIRECTION_BIT_1 7 // Y Dir - Pin A7
#define DIRECTION_BIT_2 1 // Z Dir - Pin D48
// Define stepper driver enable/disable output pin.
#define STEPPER_DISABLE_BIT_0 7 // X Enable - Pin D38
#define STEPPER_DISABLE_BIT_1 2 // Y Enable - Pin A2
#define STEPPER_DISABLE_BIT_2 0 // Z Enable - Pin A8
I checked my pin definition to the ramps schematic and these are OK. Here you find a complete instruction to setup ramps and connecting to bluetooth
I have ramps 1.4 with mega 2560 and i connect my steppers with A4988 Driver but its not working and my HC-06 not working too but my servo is working well here’s my code :
include
include
include
// Define the step and direction pins for each stepper motor // These numbers are constant in Ramps 1.4
define Stepper1_STEP_PIN 54
define Stepper1_DIR_PIN 55
//#define x_enable_pin 38
define Stepper2_STEP_PIN 60
define Stepper2_DIR_PIN 61
//#define y_enable_pin 56
define Stepper3_STEP_PIN 46
define Stepper3_DIR_PIN 48
//#define z_enable_pin 62
define Stepper4_STEP_PIN 26
define Stepper4_DIR_PIN 28
//#define Stepper5_STEP_PIN 36 //#define Stepper5_DIR_PIN 34
// Define Servo Motor
define SERVO_PIN_1 11 // These numbers are constant in Ramps 1.4
define SERVO_PIN_2 6 // These numbers are constant in Ramps 1.4
define SERVO_PIN_3 5 // These numbers are constant in Ramps 1.4
define SERVO_PIN_4 4 // These numbers are constant in Ramps 1.4
define RX_PIN 0
define TX_PIN 1
// we have multiple simultaneous steppers, all moving at different speeds and accelerations AccelStepper stepper1_Vertical_Right(AccelStepper::DRIVER, Stepper1_STEP_PIN, Stepper1_DIR_PIN); AccelStepper stepper2_Horizantal_Right(AccelStepper::DRIVER, Stepper2_STEP_PIN, Stepper2_DIR_PIN); AccelStepper stepper3_Vertical_Left(AccelStepper::DRIVER, Stepper3_STEP_PIN, Stepper3_STEP_PIN); AccelStepper stepper4_Horizantal_Left(AccelStepper::DRIVER, Stepper4_STEP_PIN, Stepper4_DIR_PIN); //AccelStepper stepper5(AccelStepper::DRIVER, Stepper5_STEP_PIN, Stepper5_DIR_PIN);
Servo servo1_Verical_Right; Servo servo2_Horizantal_Right; Servo servo3_Verical_Left; Servo servo4_Horizantal_Left;
SoftwareSerial bluetooth(TX_PIN, RX_PIN); // RX, TX pins
void setup() { Serial.begin(9600); bluetooth.begin(9600);
// Sets the maximum permitted speed. stepper1_Vertical_Right.setMaxSpeed(1000); // Sets the acceleration/deceleration rate. stepper1_Vertical_Right.setAcceleration(500);
stepper2_Horizantal_Right.setMaxSpeed(1000); stepper2_Horizantal_Right.setAcceleration(500);
stepper3_Vertical_Left.setMaxSpeed(1000); stepper3_Vertical_Left.setAcceleration(500);
stepper4_Horizantal_Left.setMaxSpeed(1000); stepper4_Horizantal_Left.setAcceleration(500);
servo1_Verical_Right.attach(SERVO_PIN_1); servo2_Horizantal_Right.attach(SERVO_PIN_2); servo3_Verical_Left.attach(SERVO_PIN_3); servo4_Horizantal_Left.attach(SERVO_PIN_4);
}
void loop() { if (bluetooth.available()) { char command = bluetooth.read(); Serial.print("Received command: "); Serial.println(command);
switch (command) { case 'U': MoveUp(); break; case 'L': MoveLeft(); break; case 'R': MoveRight(); break; case 'D': MoveDown(); } } MoveDown(); MoveRight(); }
void MoveDown() { // Move servo2 for 45 degrees and servo4 at the same time servo2_Horizantal_Right.write(45); servo4_Horizantal_Left.write(45);
// Delay for 2 second delay(2000);
// Move stepper1_Vertical_Right for 75 steps and stepper3_Vertical_Left at the same time stepper1_Vertical_Right.moveTo(75); stepper3_Vertical_Left.moveTo(75); while ( stepper1_Vertical_Right.currentPosition() && stepper3_Vertical_Left.currentPosition() != 75) { stepper1_Vertical_Right.run(); stepper3_Vertical_Left.run(); }
// Move servo2 and servo4 back to 0 degrees servo2_Horizantal_Right.write(0); servo4_Horizantal_Left.write(0);
// Move servo3 for 50 degrees servo3_Verical_Left.write(40);
// Move stepper3_Vertical_Left for 200 steps stepper3_Vertical_Left.moveTo(200); while (stepper3_Vertical_Left.currentPosition() != 200) { stepper3_Vertical_Left.run(); }
// Move servo3 for 35 degrees servo3_Verical_Left.write(0);
// Move servo1 for 90 degrees servo1_Verical_Right.write(90);
// Move stepper1_Vertical_Right for 100 steps stepper1_Vertical_Right.moveTo(100); while (stepper1_Vertical_Right.currentPosition() != 100) { stepper1_Vertical_Right.run(); }
// Move servo1 for 90 degrees again servo1_Verical_Right.write(0);