I would like to know how I can control the data from two analog inputs in my XBee Series 2. I have a sensor that sends data using a LDR (AD0) and a LM35(AD2) temperature sensor. I do not know how can I get the correct analog samples from the LM35. The LDR data seems to be correctly but the second two bytes that belong to LM35 data are read wrong.
I think that when the XBee sends the I/O data frames (with two analog inputs) it sends first the two bytes from AD0 and then the two bytes from AD2. Should I control other bytes like analog channel mask?
Here I copy a piece of code:
int analogValue = 0; //store data from LDR
int analogValueT = 0; //store data from LM35
float miliV = 0.0; //milivolts from LM35
int res = 10; // 10mV/C
float celsius = 0.0;
void loop()
{
// In API mode, the frame type is I/O data sample.So, if we have everything in the buffer
if (Serial.available() >= 23) {
// Looking the starter byte (0x7E)
if (Serial.read() == 0x7E) {
//blink debugLED when data is received
digitalWrite(debugLED, HIGH);
delay(10);
digitalWrite(debugLED, LOW);
//We have already read the start byte and then we discard bytes we are not using (20 data bytes are discard).
//We want to read only analog data from the sensor.
for (int i = 0; i<20; i++) {
byte discard = Serial.read();
}
// Copy analog samples
int analogHigh = Serial.read(); // data from LDR
int analogLow = Serial.read(); // data from LDR
int analogHighT = Serial.read(); // data from LM 35
int analogLowT = Serial.read(); // data from LM 35
analogValue = analogLow + (analogHigh256);
analogValueT = analogLowT + (analogHighT256);
miliV = (analogValueT*1200)/1024.0;
celsius = miliV/res;
}
}
Thank you in advance