I don't reckon it's practical to send individual steps over a serial connection. Much better to send a message to the Arduino telling it how many steps to move and allow the Arduino to take care of the individual step timing.
And if you are sending individual steps you should not send a separate message for HIGH and LOW. Just send a message for a step and let the Arduino do HIGH followed by a LOW. Most stepper drivers only need a very short duration pulse - less than 10 microsecs.
I think the only solution is to do it direct on Arduino.
I want the Arduino to do two tasks:
Let 2 motors be controlled automatically with data from one sensor.
Manually control the stepper mtors.
My question for you is:
Can I have a loop with arduino to automatically control the motors and at the same time, in the background, control the motors via serial?
I am new to Arduino, I know that with a Raspberry pi you can because it has a lot of capacity, but, I don't know if it is on an Arduino.
Referring to Reply #2 ...
You seem to be sending 3 values to the Arduino but you have not told us what they are and the performance of the motor depends on the values.
Serial.readString() can be very slow. It would make a lot more sense to send all three values in one message. Have you looked at the parse example in Serial Input Basics. Which also has the advantage of not using the String class.
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
raym3d:
I think the only solution is to do it direct on Arduino.
Please slow down. Allow time for us to answer one question before asking another.
Can I have a loop with arduino to automatically control the motors and at the same time, in the background, control the motors via serial?
Please explain what you want to happen in more detail. I don't understand how motors could operate automatically and manually at the same time - surely it must be one or the other?
It's much easier to give useful advice if you tell us what your project is all about.
It's certainly possible to control a motor with serial input and sensor or other program input or routines. You have already been directed to Serial Input Basics
It is important that to keep the program responsive you want to eliminate long for() loops, and delay(). The code needs to be "non blocking" and there are plenty of tutorials. For example Demonstration Code for Several Things at the Same Time.
But, the most it goes through is 400 steps with 2 milliseconds after HIGH and after LOW.
I'm not clear about what you mean, but if the program is halting after the constantly repeated String.toInt operations it's not a surprise.
I am new to Arduino, I know that with a Raspberry pi you can because it has a lot of capacity, but, I don't know if it is on an Arduino.
An Arduino has very limited capacity compared to a Raspberry Pi but there are programming techniques to use with the Arduino which can take you a long way.
raym3d:
I will put an example, it does not mean that it is what I will do, it is just an example:
When you feel able to tell us what you really want to do I will see if I can help.
When people are coy about their projects I assume they are either illegal, anti-social or a commercial developer looking to make more profit from free advice.
However I would now recommend using my SafeString library's non-blocking reads for handling user input. The SafeString library has multiple examples of parsing commands from Serial inputs (non-blocking of course)