I am working on a project in which I use a phone app that I built in order to use Google's Speech Recognizer, connect my phone with my Arduino via Bluetooth and then when I say a word it sends the word in order to display it in a LCD.
The phone App works great with no problems. The problem is in the Arduino code. When I say the word hello for example the Arduino receives ello. I know that it receives it because I also use the Serial monitor to display the data in my computer screen except the LCD. Then after Arduino receives the first chunk of data if I send a second word like world Arduino receives elloorld. So it not only misses again the first letter of the word but also the Serial Port is not empty it in the end of the loop.
I tried with data += c;
instead of data.concat(c);
and the difference is that the second word isn't elloorld and it is just orld
Here is my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 9, 8, 7, 6, 5, 4, 3, 2);
char c;
String data = "";
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
lcd.clear(); //clean the lcd
lcd.home(); // set the cursor in the up left corner
while(Serial.available() > 0){
c = Serial.read();
data.concat(c);
}
if(data.length() > 0){
Serial.println(data);
}
lcd.print(data);
delay(3000);
data = "";
}
If in the end of the loop I try to clean the Serial Port with this code:
while(Serial.available() > 0){
Serial.read();
}
Then the arduino doesn't receive data at all.