Just trying some things out, as I want to use my Arduino Nano as an interface to my computer with a couple of LED's and buttons. So I need to send some commands and data to the Arduino from my PC. However i find the serial communication of the Arduino quite slow. In fact, from the moment I press Enter to send, my command in the Serial Monitor takes almost a second to execute (in this case to control an LED).
Is this a limitation or can it be sped up somehow?
Here's my simple code:
String cmd;
int loopNum;
int ledPin = 13;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(loopNum == 0) {
Serial.println("Waiting for commands"); // Only display this when sketch is initiated.
}
cmd = Serial.readString();
if(cmd == "LEDON") {
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
if(cmd == "LEDOFF") {
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
if(cmd == "HELP") {
Serial.println("Available commands:\nLEDON\nLEDOFF\nHelp");
}
loopNum++; // Counts the loop...
delay(50);
}
Changing the baud rate of the serial doesn't seem to change anything.
Some help would be appreciated! :)