I want to read everything there is in the buffer on every loop run and add it to a String (or char array?).
The end of each message is indicated by .
So, my first question is, how can I read the ? Will a '\r' or '\n' simply be added to the string?
Also, I found the "serialEvent()" function, but it says "Currently, serialEvent() is not compatible with the Esplora, Leonardo, or Micro" and underneath "Mega only", so does it work with the due?
My main focus is reading the serialport asynchronous, without delaying other functions.
//zoomkat 7-30-13 simple delimited '\n' string parce test code
//from serial port input (via serial monitor with NL&CR enabled)
//and print result out serial port
// \n\r is the data packet delimiter
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like $SDMTW, 31.4, C*02
//followed by \n\r end of packet delimiter
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == '\n') { //looks for end of data packet marker
Serial.read(); //gets rid of following \r
Serial.println(readString); //prints string to serial port out
//do stuff with captured readString
readString=""; //clears variable for new input
}
else {
readString += c; //makes the string readString
}
}
}