Replies: 2 comments 1 reply
-
FastAccelStepper is built to support non-blocking operations, even so blocking mode can be used, too: the move operations support a second parameter called block, which avoids the while-loop for Non-blocking mode is fantastic, but way more complex to develop for. If non-blocking mode is used, this means, that more or less the whole loop() should be non-blocking. And this starts already with reading serial data. In the supplied code, blocking serial reads are used. Imagine, a received serial command requests stepper1 to run to position 1000. After the moveTo-command, the loop is starting again and is blocked waiting for serial input. If the motor is stopping during this wait, it is not possible to print something out. So you need to start with polling bytes from serial, assembling the bytes into a buffer and on newline evaluate the buffer. If no byte has been received, the code can proceed with checking the motor state. Eventually print out, that motor has stopped, or the home position has been reached and motor needs to stop immediately…. You may check, the StepperDemo in the examples-directory, which gives some insights, even though it may be difficult to read due to its complexity. |
Beta Was this translation helpful? Give feedback.
-
Looked to that StepperDemo before and frankly can't understand it. The code I wrote is practically chatgpt-4o written, I just made few tweeks. I have full code from chatgpt with sequential steppers moves made, but that part of code is buggy and sometimes causes unwanted sequence of moves. So I thought I will rewrite code myself, but it looks like I'm not going anywhere with my level of skills. |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm trying to control two steppers via serial. How do I Serial.print something after moveTo has finished its move? For now I tried While(isRunning()) loop with nothing in it, which works but I loose ability to stop stepper or give it new command to move to other position. Like example if I write command "swing 50" stepper starts moving and if in middle of its movement I give it "swing 10" it doesn't stop nor it moves to new position. Only after it finishes first move it Serial.prints me a feedback and starts second movement. In future I will also need function to move stepper1 and after it finished move stepper2. Without that function I'm risking to break vertical blinds mechanism or even worse to break a window. Even tho I'm playing with AVR chips and arduino for 17 years I'm still very novice and things is hard to understand. So I would like to get some help.
Beta Was this translation helpful? Give feedback.
All reactions