How to serial read many wireless data?

Dear All,

I have design a sensor data acquisition system. There are two sets of arduino UNO board and Xbee module. UNO board A for sensor data acquisition and then sent all sensor's data to UNO board B
through Xbee module.

The data show below:

Light: 82 lux Presure = 0.00Pa

Humidity: 62.50 % Temperature: 23.10 *C

My question is how UNO board B serial read all the value I need, not need words, just need value.

82 0.00 62.5 23.1

Are there any methods to do this?

My question is how UNO board B serial read all the value I need, not need words, just need value.

If you don't need the words, why send them?

Are both lines received every time? If so, why is it not one line?

Thx, I changed ,just send the four data.
I how to distinguish them?

I just need this four data can use in board b and update every time when board a sent the update data.

For example, l=82 p=0.00 h=62.5. t=23.1

Not just read the string char, I need the float value.

Have a look at this thread. It explains the basics of how to do what you want and a whole lot more.

Basically what you want to do is read your serial stream character by character. IF the character you get is an I and the next character is an = then read everything else until you hit a space into a char buffer and then convert that char buffer into a number with atoi or atof or whatever.

Are there any methods to do this?

Probably. If you have control over how the data is sent, then develop the decoding scheme first, then send the data in that format. Below is some receiving servo test code that has the numeric data first, then a servo identifying character, followed by a comma that marks the end of the data packet. You might send your temperature data in the format 23.10*T, where the numeric value comes first, followed by the * indicating the end of the temperature, followed by the T to indicate that the data packet holds the temperature data, and finally followed by the , end of data packet marker. This data packet would then be easy to decode and use.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

To do this kind of work, you need to become familiar with the libc library, which includes many useful string functions. This is mentioned in point 13 of the sticky post at the top of this subforum.

http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html

You are interested in the strtok() function and in the type conversion functions atof() and atod().

Delta_G:
Have a look at this thread. It explains the basics of how to do what you want and a whole lot more.

Basically what you want to do is read your serial stream character by character. IF the character you get is an I and the next character is an = then read everything else until you hit a space into a char buffer and then convert that char buffer into a number with atoi or atof or whatever.

Thank you very much.
This link of information is very useful. But I don't know how to combine the code to become serial read data.
The code below:

// simple parse demo
char receivedChars[] = "This is a test, 1234, 45.3" ;

char messageFromPC[32] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;

char recvChar;
char endMarker = '>';
boolean newData = false;

void setup() {
Serial.begin(9600);
Serial.println("");

parseData();
showParsedData();
}

void loop() {

}

void parseData() {

// split the data into its parts

char * strtokIndx; // this is used by strtok() as an index

strtokIndx = strtok(receivedChars,","); // get the first part - the string
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC

strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC = atoi(strtokIndx); // convert this part to an integer

strtokIndx = strtok(NULL, ",");
floatFromPC = atof(strtokIndx); // convert this part to a float

}

void showParsedData() {
Serial.print("Message ");
Serial.println(messageFromPC);
Serial.print("Integer ");
Serial.println(integerFromPC);
Serial.print("Float ");
Serial.println(floatFromPC);
}

Any one can help me.

shanelle:
But I don't know how to combine the code to become serial read data.

I can't figure from your comment exactly what it is that you are having a problem with. There is a combined receive and parse example in Reply #72 in Serial Input Basics and I have mentioned that in Reply #1

...R

Thank you all of your help. I have fix this problem. Just have little unstable. Some times will miss the value.

This just in ... 85,4.88,66.00,23.80

Lux85.00
Air4.88
Hum66.00
Tem23.80

Lux85.00
Air0.00
Hum0.00
Tem0.00

shanelle:
Thank you all of your help. I have fix this problem. Just have little unstable. Some times will miss the value.

This just in ... 85,4.88,66.00,23.80

Lux85.00
Air4.88
Hum66.00
Tem23.80

Lux85.00
Air0.00
Hum0.00
Tem0.00

Another approach...

Try multiplying the floats by 100 and converting to an int and sending without the decimal constructed in a message like this:

8500,488,6600,2380;

then when you receive them:

use atoi() to convert string to integer
cast it back to a float
divide the integer by 100.0

shanelle:
Thank you all of your help. I have fix this problem. Just have little unstable. Some times will miss the value.

This just in ... 85,4.88,66.00,23.80

Lux85.00
Air4.88
Hum66.00
Tem23.80

Lux85.00
Air0.00
Hum0.00
Tem0.00

You did not print the "This just in " for the second set of data. I don't think there should be any problem parsing float values.

Also, post the complete program you are using.

...R