Hello guys,
Let me explain what I want to do.
I have 5 steppers which are controlled with AccelStepper library.
Actually I have and multidimensional array which contains all the data that I need to operate the stepper.
long stepper0_data_[5][6]{
{0, 3000, 200, 100, 1500, 2000}, //DELAY
{600, 600, 700, 500, 600, 300}, //MAXSPEED
{3000, 600, 3000, 600, 3000, 600}, //ACCELERATION
{3000, 1500, 1900, 1000, 1500, 0}, //MOVE TO
{false, true, true, true, true, true} //MOTION COMPLETED
};
and my sketch to read this
#include "AccelStepper.h"
#include <SPI.h>
#include <MCP23S17.h>
MCP mcp(0, 49);
const int stepperAmount = 5;
AccelStepper stepper0(1, 31, 30);
AccelStepper stepper1(1, 29, 28);
AccelStepper stepper2(1, 27, 26);
AccelStepper stepper3(1, 25, 24);
AccelStepper stepper4(1, 23, 22);
AccelStepper* steppers[stepperAmount] ={&stepper0, &stepper1, &stepper2, &stepper3, &stepper4};
long enable_pin_[stepperAmount] = {1, 3, 5, 7, 9};
long stepper0_data_[5][6]{
{0, 3000, 200, 100, 1500, 2000}, //DELAY
{600, 600, 700, 500, 600, 300}, //MAXSPEED
{3000, 600, 3000, 600, 3000, 600}, //ACCELERATION
{3000, 1500, 1900, 1000, 1500, 0}, //MOVE TO
{false, true, true, true, true, true} //MOTION COMPLETED
};
unsigned long previousMillis=0;
void setup() {
mcp.begin();
mcp.pinMode(1, OUTPUT); //FOR OTHER STEPPERS I WILL DO AFTER
mcp.digitalWrite(1, HIGH); //FOR OTHER STEPPERS I WILL DO AFTER
Serial.begin(9600);
delay(3000);
}
void loop()
{
stepper_move();
stepper0.run();
stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
}
void stepper_move()
{
unsigned long currentMillis = millis();
if (stepper0.distanceToGo() == 0 ){
mcp.digitalWrite(enable_pin_[0], HIGH);
} else {
mcp.digitalWrite(enable_pin_[0], LOW);
}
for (int coord_id=0; coord_id < 6; coord_id++){
unsigned long next_coord_id = coord_id + 1;
if ((unsigned long)(currentMillis - previousMillis) >= stepper0_data_[0][coord_id]) {
if (!stepper0_data_[4][coord_id]){
stepper0.setMaxSpeed(stepper0_data_[1][coord_id]);
stepper0.setAcceleration(stepper0_data_[2][coord_id]);
stepper0.moveTo(stepper0_data_[3][coord_id]);
if (stepper0.distanceToGo() == 0 ){
stepper0_data_[4][coord_id] = true;
stepper0_data_[4][next_coord_id] = false;
previousMillis = currentMillis;
//Serial.println("Coord ID :");
//Serial.println(stepper0_data_[3][coord_id]);
}
}
}
}
}
Also I have SD card module installed.
Now what I want to do is to have on SD card files containing different multidimensional arrays (with different rows and columns)
- -01.TXT
- -02.TXT
- …
- -99.TXT
and I want to have a SETTINGS.TXT which will contain the name of files to get coords ( for example if I want to move the stepper with this coords 01,02,05,08…) and after I have the possibility to activate or deactivate them.
What you can advise?
Is this a good approach?
Thank you!