Why is my code not returning all of the serial data being given to it?

I do not quite know if your code makes sense to me.

  1. There is a chance that String data1 = Serial.readString(); just reads one or two bytes.
  2. while (Serial.available()) Serial.read(); throws anything away that might be useful.
  3. while (Serial.read() >= 0) ; does the same as (2)

I suggest that you study Serial Input Basics - updated to get some ideas for your serial communication.

1 Like