I'm using android app and arduino in our project. The android app will send a string of data to the arduino. The receive data will be displayed in the Serial monitor of the arduino IDE. The receiving process is okay since the arduino correctly receive the string of data. The only problem is the data receive keeps repeating in the arduino Serial monitor. I'm a beginner in arduino programning.
hi! I try moving the } in the end part of the loop function. The data stops repeating but it does not display it only once. Sometimes it displays twice, thrice but not only once.
In my code here, If the receive data length is greater than 13 characters, it will print in whatever the letters it compose. Is this correct?
if (val.length() >= 13 ) {
Serial.println("DATE,TIME,");
Serial.println(val);
Serial.println(",");
I try moving the } in the end part of the loop function. The data stops repeating but it does not display it only once. Sometimes it displays twice, thrice but not only once.
You changed your code. It does not do what you want. Yet, you want us to guess what is wrong. No, thanks.
Okay,when the arduino receive the word "faculty", it displays the word "Faculty" in the serial monitor but when I send again the word "faculty", the receive data is more than 13 characters (facultyfaculty) in which the first IF statement is valid. I used serial.flush to erased the serial buffer but it doesn't work. What is the method in deleting the previous buffer data?
I used serial.flush to erased the serial buffer but it doesn't work.
That function blocks until the outgoing serial buffer is empty. It did exactly what it was supposed to do, so your definition or "work" is wrong.
What is the method in deleting the previous buffer data?
The proper method is to understand what available() and read() are doing. available() tells you how much data is in the buffer. read() removes one byte from the buffer. There is no function to delete the previous data because there is no previous data.
The problem is that after printing the value in the dreaded String, you are not deleting THAT data. It has NOTHING to do with the Serial buffer - incoming or outgoing.