This code is from the Arduino site, I only added the command to print data to a LCD.
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
lcd.clear();
lcd.print(inputString); //prints the string on a LCD
// clear the string:
inputString = "";
stringComplete = false;
}
}
void serialEvent(){
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}