I understand people says using if (Serial.available()) to determine if serial is transmitting.
There is a problem which is when I received data only in if (Serial.available()) and start to work on my code, because of the time delay, I receive the data in incomplete pieces.
For example I send "Hello world", it might be received in "el wrd" with missing letters in between.
So in order to get a complete sets of char, I use a loop to collect all data. problem is when is use that while data are not sending, arduino still chunk out �. How do I differential this? What exactly is �?
One of the big challenges in programming is that you have limited amounts of processing time.
To handle real-time data of any sort, you need to buffer the incoming data as well as processing it when the computer has time to - not when you’re ready to.
These are harsh rules, but they’re the only rules.
That’s why getting rid of delay(), and other techniques are so important
+1 for the Serial input basics tutorial. It shows how to read the entire line into a buffer for later parsing. Use start and end markers to synchronize the sender and receiver and simple error detection.