For this week we worked as a group to design and operate a machine.
The electronics we used for our machine are:
// Define connections for Motors
#define stepA_stepPin 2
#define stepA_dirPin 3
#define stepA_enablePin 4
#define stepA_homeSwitchPin 13
#define stepB_stepPin 5
#define stepB_dirPin 6
#define stepB_enablePin 7
#define steps_per_arm 3250 //3250 for full arm len
#define steps_per_revolution 9600 //200 * 3 ratio * 16 microstepping = 360 deg
// Define motion speed and direction parameters
bool stepA_dir_out = true;
bool stepA_dir_in = false;
bool stepB_dir_left = true;
bool stepB_dir_right = false;
int step_delay = 500;
void setup() {
// Set up stepper motor pins as outputs
pinMode(stepA_dirPin, OUTPUT);
pinMode(stepA_stepPin, OUTPUT);
pinMode(stepA_enablePin, OUTPUT);
pinMode(stepB_dirPin, OUTPUT);
pinMode(stepB_stepPin, OUTPUT);
pinMode(stepB_enablePin, OUTPUT);
// Setup limit switch as input
pinMode(stepA_homeSwitchPin, INPUT_PULLUP);
// Enable both steppers
digitalWrite(stepA_enablePin, LOW);
digitalWrite(stepB_enablePin, LOW);
// Perform homing sequence for Stepper A
while (digitalRead(stepA_homeSwitchPin) == HIGH) {
stepA_run(1, stepA_dir_out);
}
// Go to table center
stepA_run(steps_per_arm, stepA_dir_in);
}
void stepA_run(int steps, bool dir) {
stepper_run(steps, dir, stepA_stepPin, stepA_dirPin);
}
void stepB_run(int steps, bool dir) {
stepper_run(steps, dir, stepB_stepPin, stepB_dirPin);
}
void stepper_run(int steps, bool dir, int stepPin, int dirPin) {
for (int i = 0; i < steps; i++) {
digitalWrite(dirPin, dir);
digitalWrite(stepPin, HIGH);
delayMicroseconds(step_delay);
digitalWrite(stepPin, LOW);
delayMicroseconds(step_delay);
}
}
void loop() {
stepB_run(steps_per_revolution/4, stepB_dir_left);
stepA_run(steps_per_arm*0.8, stepA_dir_in);
stepB_run(steps_per_revolution/4, stepB_dir_right);
stepA_run(steps_per_arm*0.8, stepA_dir_out);
}