How to Sending multiple variables on Serial..

Hello everyone..

I have a question, How i could sends multiple variables on serial by software serial library using HC-12 module .
I have 2 sensors and need to sends their values , i have a problem in separating the byes from each other. Actually, I have made deep search and found some references about this problem but seems to me not understood what going on.

I am sending the variables like this

 hc.write("A"); hc.write(spo2); hc.write(" B"); hc.write(beatAvg); hc.write(" C"); hc.write(mlx90615.getTemperature(MLX90615_OBJECT_TEMPERATURE));

and receives them on the other side

if (Serial.available() > 0) {
    temp = Serial.read();
  }
  Serial.print(temp);
  Serial.println();
  delay(200);

Any suggestions please.. ?

Thanks alot

The write() method expects a byte as the argument. Are spo2, beatAvg, and mlx90615.getTemperature(MLX90615_OBJECT_TEMPERATURE) bytes?

What are you sending this binary data to?

In general, it is far easier to (debug if you) send ASCII data, and have the receiver parse the data.

The only reason for sending binary data is speed.

We can't see what speed you are sending the data, nor do we know what you are sending it to, nor do we know that you are sending data properly, nor do we know what your problem is. So, we can't help you.

Any suggestions please.. ?

Serial Input Basics tutorial will show you how to send, receive and parse the data.

cattledog:
Serial Input Basics tutorial will show you how to send, receive and parse the data.

I'm afraid this is not useful for me because i tried this before its just for data contains fixed [chars] or [values] not variables sent over SoftwareSerial.

PaulS:
The write() method expects a byte as the argument. Are spo2, beatAvg, and mlx90615.getTemperature(MLX90615_OBJECT_TEMPERATURE) bytes?

What are you sending this binary data to?

In general, it is far easier to (debug if you) send ASCII data, and have the receiver parse the data.

The only reason for sending binary data is speed.

We can't see what speed you are sending the data, nor do we know what you are sending it to, nor do we know that you are sending data properly, nor do we know what your problem is. So, we can't help you.

Simply, Two variables a,b,c needs to be sent over SoftwareSerial with HC-12 module, How i can separate the variables on the receiver?

I'm afraid this is not useful for me because i tried this before its just for data contains fixed [chars] or [values] not variables sent over SoftwareSerial.

You misunderstand. You can turn your numeric variables into ascii character strings with functions like itoa (convert an integer to a string), ltoa (convert a long integer to a string) and dtosrf (convert a floating point number into a string).

EDIT:
Paul S later post suggesting to convert the data at the receiver using the parsing techniques in Robin's tutorial is a better approach.

How i can separate the variables on the receiver?

By separating them at the transmitter.

See Robin2's serial basics thread.

Simply, Two variables a,b,c needs to be sent over SoftwareSerial with HC-12 module

Take your shoes off if you need to. a, b, and c are three variables.

How i can separate the variables on the receiver?

That depends on how you send them. If you user three calls to write(), to send the three low order bytes, then you have no way of knowing which byte was which, on the receiver.

If, on the other hand, you have something like:

int a = -278;
int b = 758;
int c = 4051;

Serial.print("<a:");
Serial.print(a);
Serial.print(", b:");
Serial.print(b);
Serial.print(", c:");
Serial.print(c);
Serial.print(">");

then, despite your convictions otherwise, Robin2's tutorial DOES show how to collect, parse, and use the values received.

mi_ds:
I'm afraid this is not useful for me because i tried this before its just for data contains fixed [chars] or [values] not variables sent over SoftwareSerial.

I left it for a homework test for YOU to figure out how to modify it for YOUR particular needs. If you have tried and got stuck then post the program that represents your best attempt and I will try to help.

A key skill in programming is the ability to see how an idea can be adapted to meet a somewhat different requirement.

...R

PaulS:
Take your shoes off if you need to. a, b, and c are three variables.
That depends on how you send them. If you user three calls to write(), to send the three low order bytes, then you have no way of knowing which byte was which, on the receiver.

If, on the other hand, you have something like:

int a = -278;

int b = 758;
int c = 4051;

Serial.print("<a:");
Serial.print(a);
Serial.print(", b:");
Serial.print(b);
Serial.print(", c:");
Serial.print(c);
Serial.print(">");



then, despite your convictions otherwise, Robin2's tutorial DOES show how to collect, parse, and use the values received.

It works very well..

I am able to sent 2 variables and separated on the receiver.

Thanks alot for all