Hello,
I have a stepper nema23 with a microstepper driver that works with 25000steps/revolution
Could you help me with the programming of the arduino, please?
I need a simple way to make 2850 full turns with the highest possible speed and after that to stop.
I tried "for in for" way but I can't "break" it so to go to the rest program after the turns.
You have not posted all of your code so the context is not clear, but considering that 25,000 * 2,850 is over 71 million iterations, each with a delay of 10 milliseconds it will take a while for the nested loops to complete.
Can I suggest that you post your whole program so that we can see where you are executing the nested for loops. I strongly suspect that you have them in the loop() function which, as its name suggests, loops forever and repeats the code within it unless you take steps to prevent it.
Are you sure that the stepper/driver combination does 25000 steps per revolution ?
Yes, you have right all these are in loop() function. Maybe this is the problem...
About the code it is very long to post it all here but I think the problem is that all are in loop() so it can not stop.
About the steps/revolution, we I tried to make 25000steps without "for" the motor turned 360degrees so I think I have right. I have tried many step numbers like 12500steps-180degrees e.t.c. to be sure. When I tried 50000steps it turned without stopping.
Maybe you can give me a way to stop these loops? Maybe a way as example to my code part?
To get a stepper upto full speed you will need smooth acceleration of steps within the
acceleration range the motor can handle. You can't just start sending pulses at full
rate, the motor has physical inertia and needs to build up momentum. I can't
remember if the AccelStepper library supports driving step&dir style stepper drivers,
if it does it will be a good place to start, but I think its not quick enough for microstepping
drivers.
What's the motor and driver (in other words what sort of physical performance is available?)
Maybe you can give me a way to stop these loops? Maybe a way as example to my code part?
If you will not post all of your code then it is difficult to give specific advice but maybe something like this
set OKtoRun variable true
start of loop()
if OKtoRun is true
outer for loop
inner for loop
do motor stuff here
end of inner loop
end of outer loop
set OKtoRun variable false
end of if
other code goes here
end of loop()
Here is the complete code.
It is not finished but I hope you can understand it (see the attached file).
As I am not expert in programming, please make the changes needed to my code directly.
I am reluctant to make changes to the code because you won't learn learn so much that way. It is better if you do it yourself.
There is, however, a problem either way because the code will not compile. I don't have PCD8544 the library, but even if I did, when I attempted to Auto Format your code it reports that there are too many right curly braces. This needs to be fixed.
If you look at the pseudo code that I posted, then the OKtoRun variable should be checked before calling the Bstepper() function then, after the function is run it should be set to false until some action sets it to true, at which point the motor will run again.
You also need to take into account the fact that the motor may need to be accelerated up to speed as suggested in other posts.
It is not finished but I hope you can understand it (see the attached file).
Posting a bazillion lines of incomplete code to illustrate a hardware problem is the wrong way to go. Forget that sketch. Create a new one that does NOTHING but make the stepper move the way that you want it to. If THAT doesn't work, feel free to post it for help.