Hi, everyone.
So, I'm working on a project using an Arduino Mega 2560 Rev3 attached to a RAMPS 1.4 Board. It's not for a RepRap 3D printer, but for something completely unrelated. The Arduino has 4 motors and 20x4 LCD screen attached to it. Two are Stepper Motors, and the other Two are Screw Linear Motors.
I created a program to test the motors, but when I run it, only one of the motors (a NEMA 17 Stepper Motor -known as SM 2) actually turns. The code isn't complex at all, but it still isn't working. I know the other 3 motors are actually working, because when I run the actual open source program to test it, they run for a little bit. But because of a problem - perhaps the same reason my test code isn't working - after running for a little, they fail to execute the other 95% of the program. The LCD Screen works 100% fine.
Can anyone help me out? Please let me know if there's any information you need. I've attempted to format my Motor Test Code below, as well as attached the code for the Motor Test and the open source program as well.
original_AMT_code.ino (35.1 KB)
motors_test.ino (3.2 KB)
[table][tr][td][size=14pt][sub]Code:[/sub][/size][hr][/td][/tr][tr][td][size=9pt][tt]#include <AccelStepper.h>
#include <LiquidCrystal.h>
//======= LCD ========================================================
#define LCD_SPEAKER 37
#define LCD_RS 16
#define LCD_Enable 17
#define LCD_D4 23
#define LCD_D5 25
#define LCD_D6 27
#define LCD_D7 29
LiquidCrystal lcd(LCD_RS, LCD_Enable, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
//======= ROTARY======================================================
#define ROTARY_EN1 31
#define ROTARY_EN2 33
#define ROTARY_BUTTON 35
Rotary rotary = Rotary(ROTARY_EN1, ROTARY_EN2);
//======= ENDSTOPS ===================================================
#define END_STOP_1 3
#define END_STOP_2 2
#define END_STOP_3 14
#define END_STOP_4 15
//======= STEPPERS ===================================================
#define USEDRIVER 1
//---- Stepper Motor 1 (RAMPS X)-------------------------------------
#define SM_1_STEP_PIN 54
#define SM_1_DIR_PIN 55
#define SM_1_ENABLE_PIN 38
AccelStepper SM_1 = AccelStepper(USEDRIVER, SM_1_STEP_PIN, SM_1_DIR_PIN);
//---- Stepper Motor 2 (RAMPS Y)-------------------------------------
#define SM_2_STEP_PIN 60
#define SM_2_DIR_PIN 61
#define SM_2_ENABLE_PIN 56
AccelStepper SM_2 = AccelStepper(USEDRIVER, SM_2_STEP_PIN, SM_2_DIR_PIN);
//---- Stepper Motor 3 (RAMPS E0)-------------------------------------
#define SM_3_STEP_PIN 26
#define SM_3_DIR_PIN 28
#define SM_3_ENABLE_PIN 24
AccelStepper SM_3 = AccelStepper(USEDRIVER, SM_3_STEP_PIN, SM_3_DIR_PIN);
//---- Stepper Motor 4 (RAMPS E1)-------------------------------------
#define SM_4_STEP_PIN 36
#define SM_4_DIR_PIN 34
#define SM_4_ENABLE_PIN 30
AccelStepper SM_4 = AccelStepper(USEDRIVER, SM_4_STEP_PIN, SM_4_DIR_PIN);
void initStepper(void *s, int ENABLE_PIN)
{ AccelStepper *stepper = (AccelStepper *)s;
stepper->setMaxSpeed(200 * 16 * 15000); //Faster than original speed
stepper->setAccelerationcolor=#000000[/color];
stepper->setMinPulseWidthcolor=#000000[/color];
stepper->setEnablePincolor=#000000[/color];
stepper->setPinsInverted(false, false, true); //invert logic of enable pin
stepper->enableOutputscolor=#000000[/color];
stepper->stopcolor=#000000[/color];
}
void setTwisterStepper(void *s, float maxspeed, float acccel)
{ AccelStepper *stepper = (AccelStepper *)s;
stepper->setMaxSpeedcolor=#000000[/color];
stepper->setAccelerationcolor=#000000[/color];
}
void setupcolor=#000000[/color] {
//Sets the maximum speed in steps per second:
SM_1.setMaxSpeed(1000 * 16 * 2);
SM_2.setMaxSpeed(1000 * 16 * 2);
SM_3.setMaxSpeed(1000 * 16 * 2);
SM_4.setMaxSpeed(1000 * 16 * 2);
SM_1.setEnablePincolor=#000000[/color];
SM_3.setEnablePincolor=#000000[/color];
SM_4.setEnablePincolor=#000000[/color];
SM_1.enableOutputscolor=#000000[/color];
SM_3.enableOutputscolor=#000000[/color];
SM_4.enableOutputscolor=#000000[/color];
SM_1.stopcolor=#000000[/color];
SM_3.stopcolor=#000000[/color];
SM_4.stopcolor=#000000[/color];
lcd.print("Is this working?");
}
void loopcolor=#000000[/color] {
// put your main code here, to run repeatedly:
//Sets the speed in steps per second:
SM_1.setSpeedcolor=#000000[/color];
SM_2.setSpeedcolor=#000000[/color];
SM_3.setSpeedcolor=#000000[/color];
SM_4.setSpeedcolor=#000000[/color];
//Step the motor with a constant speed as set by set speed:
SM_1.runSpeedcolor=#000000[/color];
SM_2.runSpeedcolor=#000000[/color];
SM_3.setCurrentPositioncolor=#000000[/color];
SM_4.setCurrentPositioncolor=#000000[/color];
SM_3.moveTocolor=#000000[/color];
SM_4.moveTocolor=#000000[/color];
}[/tt][/size][/td][/tr][/table]