Serial Communication: Sending 3 Integers

dwalden
Posts: 2
Joined: Mon Mar 01, 2021 7:11 am

Serial Communication: Sending 3 Integers

Postby dwalden » 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.

DrMickeyLauer
Posts: 168
Joined: Sun May 22, 2022 2:42 pm

Re: Serial Communication: Sending 3 Integers

Postby DrMickeyLauer » Sun Mar 03, 2024 11:24 am

That's what framing protocols are for. For payloads small as these, I'd use json on the serial console.

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Serial Communication: Sending 3 Integers

Postby lbernstone » Sun Mar 03, 2024 5:04 pm

yep, json, or send them all as a single record with a defined structure.

Code: Select all

Serial.printf("%d\t%d\t%d\n", Int1, Int2, Int3);

dwalden
Posts: 2
Joined: Mon Mar 01, 2021 7:11 am

Re: Serial Communication: Sending 3 Integers

Postby dwalden » Sun Mar 03, 2024 10:54 pm

Thanks for the help. I've never used Json before, but I'm looking into it now. Question: is there a speed limit when sending Integers like this between boards using serial communication? For example, could I send/receive 3 Integers every 10 microseconds if I wanted to? At what point would the communication start to fail, or messages get dropped? Also, does the distance between the boards matter? Ideally I want to place the boards about 15 ft apart.

DrMickeyLauer
Posts: 168
Joined: Sun May 22, 2022 2:42 pm

Re: Serial Communication: Sending 3 Integers

Postby DrMickeyLauer » Mon Mar 04, 2024 9:00 am

You can easily compute how long it takes to send your data, you have all the variables like UART bitrate and number of bits to send, etc.

Who is online

Users browsing this forum: No registered users and 106 guests