Hi,
I have managed to get my NEMA 17 motor running via my Uno and 3 Axis shield with A4988. The project will eventually control 3 steppers, all running with the same settings, slowly turning at about 15RPM, which is output to drive shaft via 5:1 reduction, thus final output is approx 3 rpm. For now I'm just working with one, to tyr and get the settings correct.
The aim is to drive a nut along a 1M shaft, m8x1mm ,travelling approximately 900mm, then reversing back to home and repeating, 24/7. If I can figure out the number of steps to move 900mm, which I think I can...
[3rpm*(900mm*200step/rpm) =18,000]*5 for reduction = 90,000 steps??? (90,000 seems to be the maximium permitted or the motor just does nothing)?) then I believe I will only require one limit switch, with the nut (which is pulling an assembly along a track) homing, before beginning the continuous cycle. I attached my animation of how it operates.
The other option is to use two switches at each end of travel... My issue is I am having trouble getting a limit switch to reverse the motor when its running. Is the some code I need?
Here is what I have so far:
#define EN 8
//Direction pin
#define X_DIR 5
//Step pin
#define X_STP 2
//A498
int delayTime = 90000;
int stps=90000;
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i< steps; i++)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup()
{
pinMode(X_DIR, OUTPUT); pinMode(X_STP,OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN,LOW);
}
void loop()
{
step(false, X_DIR, X_STP, stps);
delay(1000);
step(true, X_DIR, X_STP, stps);
delay(1000);
}
This drives the output shaft CW for about 20mins before pausing, and then continuing CW instead of reversing to CCW which seems odd... The reversing action was working when the step/delay numbers were much smaller...
If any of this babble makes any sense, then a little assistance would be great