Go Down

Topic: How to prepare data for Serial Sending (Read 112 times) previous topic - next topic

wideko

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

tzijie

connect tx - rx , rx-tx

and you should be good to go.

Code: [Select]

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

MorganS

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

Code: [Select]

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);
}


 
"The problem is in the code you didn't post."

Robin2

#3
Oct 19, 2017, 10:41 am Last Edit: Oct 19, 2017, 10:43 am by Robin2
I agree with @MorganS.

Assuming you are receiving with my unchanged code the start marker will be
Code: [Select]
Serial.print('<');
and the end marker will be
Code: [Select]
Serial.print('>');


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up