How to prepare data for Serial Sending

L.S.,

I have found the tutorial "Serial Input Basics" written by Robin2. This tutorial is for receiving and encoding the data over a serial cnnection.

In my project I have 2 MEGA's which shoud 'talk' to each other.
So now I'm curious f there is a tutorial which explains how to prepare the data for sending.

I want to read the analog value of 5 Potmeters and the state of a number of switches at MEGA(1). And send this data to MEGA(2).
.AND.
I want to send some bytes, int's from MEGA(2) to MEGA(1) back.

with regards,
Willie

connect tx - rx , rx-tx

and you should be good to go.

//in void loop()
if(Serial.available{}){//checks serial buffer for incoming data
char receivedChar = Serial.read();
}

You don't need to 'prepare' like getting all the data into one line or something. Just send the pieces one-at-a-time.

void sendSerialMessage() {
  Serial.print(serialStartMarkerYouSelected);
  int temp = analogRead(analogPinNameChosenByYou);
  Serial.print(temp);

  Serial.print(seperatorMarker_ProbablyAComma);
  temp = analogRead(anotherAnalogPin);
  Serial.print(temp);
  
  Serial.print(seperatorMarker_ProbablyAComma);
  temp = digitalRead(oneOfYourDigitalPins);
  Serial.print(temp);

  Serial.print(serialEndMarker);
}

I agree with @MorganS.

Assuming you are receiving with my unchanged code the start marker will be

Serial.print('<');

and the end marker will be

Serial.print('>');

...R