Ok so i tried using a for loop to turn each stepper one step at a time for the length of the amount of steps in my case 200 steps at 1.8 degrees per turn but it was horrible the drone vibrates along the floor, so instead of making that circuit to join the two together i just went through the Stepper library code and made my own based on the library that does two motors at the same time or just one. it nothing special and because i am using the 200 stepper motors only i did not include the part the swaps between motor types though that would be simple. FYI i am using two TB6612 drivers boards and two stepper motor - NEMA-17 size - 200 steps/rev, 12V 350mA. All is working perfectly if you want to use the code below
int step_number = 0;
int direction = 0;
unsigned long last_step_time = 0;
unsigned long step_delay;
unsigned long steps = 200;
const byte stepperOnePin_1 = 4;
const byte stepperOnePin_2 = 5;
const byte stepperOnePin_3 = 6;
const byte stepperOnePin_4 = 7;
const byte stepperTwoPin_1 = 8;
const byte stepperTwoPin_2 = 9;
const byte stepperTwoPin_3 = 10;
const byte stepperTwoPin_4 = 11;
int speed = 30;
unsigned long currentMillis;
void setup() {
Serial.begin(115200);
step_delay = ((60000UL / steps) / speed);
Serial.print("step_delay ");
Serial.println(step_delay);
}
void loop() {
stepTwo(200, true, true, false); // steps, select motor 1, select motor 2, invert directions "turn opposite direction to each other"
delay(3000); // not needed, just added to slow down loop !
stepTwo(-200, true, true, false); // now test the steppers in reverse
delay(3000); // not needed, just added to slow down loop !
}
void stepTwo(int step, bool selectMotorOne, bool selectMotorTwo, bool invert) {
int steps_left = abs(step);
if (step > 0) {
direction = 1;
Serial.print("steps_left ");
Serial.println(steps_left);
}
else if (step < 0) {
direction = 0;
Serial.print("steps_right ");
Serial.println(steps_left);
}
while (steps_left > 0) {
currentMillis = millis();
if (currentMillis - last_step_time >= step_delay) {
//Serial.println("timer met");
last_step_time = currentMillis;
if (direction == 1)
{
step_number++;
if (step_number == steps) {
step_number = 0;
}
}
else
{
if (step_number == 0) {
step_number = steps;
}
step_number--;
}
// decrement the steps left:
steps_left--;
int thisStep = step_number % 4;
//Serial.println(step_number % 4);
if (!invert) {
switch (thisStep) {
case 0: // 1010
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, HIGH);
digitalWrite(stepperOnePin_2, LOW);
digitalWrite(stepperOnePin_3, HIGH);
digitalWrite(stepperOnePin_4, LOW);
}
if (selectMotorTwo) {// motor 2
digitalWrite(stepperTwoPin_1, HIGH);
digitalWrite(stepperTwoPin_2, LOW);
digitalWrite(stepperTwoPin_3, HIGH);
digitalWrite(stepperTwoPin_4, LOW);
}
break;
case 1: // 0110
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, LOW);
digitalWrite(stepperOnePin_2, HIGH);
digitalWrite(stepperOnePin_3, HIGH);
digitalWrite(stepperOnePin_4, LOW);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, LOW);
digitalWrite(stepperTwoPin_2, HIGH);
digitalWrite(stepperTwoPin_3, HIGH);
digitalWrite(stepperTwoPin_4, LOW);
}
break;
case 2: // 0101
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, LOW);
digitalWrite(stepperOnePin_2, HIGH);
digitalWrite(stepperOnePin_3, LOW);
digitalWrite(stepperOnePin_4, HIGH);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, LOW);
digitalWrite(stepperTwoPin_2, HIGH);
digitalWrite(stepperTwoPin_3, LOW);
digitalWrite(stepperTwoPin_4, HIGH);
}
break;
case 3: // 1001
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, HIGH);
digitalWrite(stepperOnePin_2, LOW);
digitalWrite(stepperOnePin_3, LOW);
digitalWrite(stepperOnePin_4, HIGH);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, HIGH);
digitalWrite(stepperTwoPin_2, LOW);
digitalWrite(stepperTwoPin_3, LOW);
digitalWrite(stepperTwoPin_4, HIGH);
}
break;
}
}
else {
Serial.println("inverted");
switch (thisStep) {
case 0: // 1001
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, HIGH);
digitalWrite(stepperOnePin_2, LOW);
digitalWrite(stepperOnePin_3, HIGH);
digitalWrite(stepperOnePin_4, LOW);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, HIGH);
digitalWrite(stepperTwoPin_2, LOW);
digitalWrite(stepperTwoPin_3, LOW);
digitalWrite(stepperTwoPin_4, HIGH);
}
break;
case 1: // 0101
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, LOW);
digitalWrite(stepperOnePin_2, HIGH);
digitalWrite(stepperOnePin_3, HIGH);
digitalWrite(stepperOnePin_4, LOW);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, LOW);
digitalWrite(stepperTwoPin_2, HIGH);
digitalWrite(stepperTwoPin_3, LOW);
digitalWrite(stepperTwoPin_4, HIGH);
}
break;
case 2: //0101
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, LOW);
digitalWrite(stepperOnePin_2, HIGH);
digitalWrite(stepperOnePin_3, LOW);
digitalWrite(stepperOnePin_4, HIGH);
}
if (selectMotorTwo) {
digitalWrite(stepperTwoPin_1, LOW);
digitalWrite(stepperTwoPin_2, HIGH);
digitalWrite(stepperTwoPin_3, HIGH);
digitalWrite(stepperTwoPin_4, LOW);
}
break;
case 3: // 1001
if (selectMotorOne) { // motor 1
digitalWrite(stepperOnePin_1, HIGH);
digitalWrite(stepperOnePin_2, LOW);
digitalWrite(stepperOnePin_3, LOW);
digitalWrite(stepperOnePin_4, HIGH);
}
if (selectMotorTwo) {// motor 2
digitalWrite(stepperTwoPin_1, HIGH);
digitalWrite(stepperTwoPin_2, LOW);
digitalWrite(stepperTwoPin_3, HIGH);
digitalWrite(stepperTwoPin_4, LOW);
}
break;
}
}
}
}
}