Serial Communication: Sending 3 Integers
Posted: Sun Mar 03, 2024 6:44 am
Hello- I'm trying to send 3 Integers from an Esp32 Controller to an Esp32 Receiver. I'm having a hard time understanding how to identify each Integer, so that the Receiver interprets them in the correct order. Do I need to send some kind of identifier with each Integer? I'm sending these 3 Integers every millisecond.
Controller code:
Serial.println(Int1);
Serial.println(Int2);
Serial.println(Int3);
The Receiver code uses Serial.parseInt() to identify a received Integer. Question: How should the Receiver check each Integer, to make sure it is the intended one, and doesn't confuse Int1 with Int2, etc? For example, the Receiver code might start executing at Int2, and therefore reading the first Integer with Serial.parseInt() would return Int2 and not Int1. Therefore it is important to identify the start and end of each message, and receive each Integer in order. Any help with this would be greatly appreciated.
Controller code:
Serial.println(Int1);
Serial.println(Int2);
Serial.println(Int3);
The Receiver code uses Serial.parseInt() to identify a received Integer. Question: How should the Receiver check each Integer, to make sure it is the intended one, and doesn't confuse Int1 with Int2, etc? For example, the Receiver code might start executing at Int2, and therefore reading the first Integer with Serial.parseInt() would return Int2 and not Int1. Therefore it is important to identify the start and end of each message, and receive each Integer in order. Any help with this would be greatly appreciated.