While experimenting with ways to implement a command line interpreter, I discovered that the following code (on a Mega 2560) runs amazingly slowly. I've seen other reports of this problem, but not seen any satisfactory closure to it.
The code simply reads a string supplied to the serial buffer, and echoes it back. But it's taking all of 1000mS to do so!
Can anyone help please? There's got to be a way of getting response time to well below one second per string! What's going on? Thanks...
// Simple string comms I/O test.
// Why does it take around 1000mS to reply?!?
String command_in = "";
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
while (Serial.available() > 0) {
command_in = Serial.readString();
Serial.print("The Arduino received ");
Serial.println(command_in);
}
}