Programming XBee to transmit and receive data

The leading zero was stripped by the println(var, HEX) method. (The print(var, HEX) method would do the same). For extra data it doesn't matter, but what if the high nybble of either data_high or data_low was zero. The high nybble wouldn't be transmitted at all, breaking our data stream format. Unless we can figure out if one can suppress leading zero trimming with the print(var, HEX) method, we will have to roll our own function.

Noted. I noticed the omission of the zeros, and also that println() just sets the data in the next line.

Also, when I say XBeeRX.available() == 1 and then I say data_in = XBeeRX.read(); does this byte leave the Serial buffer and go into data_in or is it copied? I think its moved right?

To make sure I received the next byte should I put XBeeRX.available() == 2 (next byte along with already existing) or still XBeeRX.available() == 1 (new byte which came in)?

I couldn't work on this today due to other appointments. But I was thinking of trying :

if(XBeeRX.available() == 1 && readPosition == 0)
{
data_in = XBeeRX.read();
if (data_in == '*')
{
readPosition++;
}
}

if(XBeeRX.available() == 1 && readPosition == 1)      [b] // I assume the byte that went into data_in is moved and not copied.[/b]
{
data_high2 = XBeeRX.read();      [b] //higher nibble of data_high[/b]
readPosition++;
}

if(XBeeRX.available() == 1 && readPosition == 2)       
{
data_high1 = XBeeRX.read();       //lower nibble of data_high
readPosition++;
}

if(XBeeRX.available() == 1 && readPosition == 3)       
{
data_low2 = XBeeRX.read();       //higher nibble of data_low
readPosition++;
}

if(XBeeRX.available() == 1 && readPosition == 4)       
{
data_low1 = XBeeRX.read();       //lower nibble of data_low
readPosition++;
newReading = 1;
}

if (newReading == 1)
{
...
...
}

I could have enveloped a switch statement (switching the readPosition) into an if(XBeeRX.available() == 1) loop also I guess. But would this logic work?


what is the -0.01 for? I don't remember seeing anything about this in the temperature sensor datasheet. But I may have missed it.

The '-0.01' came from the code in various blogs I searched. The resolution of the MLX90614 is 0.02 and the half of it is some offset I guessed. In any case, I never gave it much thought because the resolution is good anyway.

What version of the IDE are you using?

I downloaded it from this website this year (in January).

Serial.begin(115200);
  XBeeRX.begin(9600);

Is it a better idea to set the Serial.begin() at a higher baud than the XBee.begin() baud? What difference does it make?

int frac; // what is this variable used for? Future use? Or can it be removed?

Removed I guess.

Let me run this and see what Celsius values I get.