Hello,
I m a student and I m working on a temperature sensor network with Xbee modules. I m using Xbee Pro Serie 1 modules, and I'm getting my datas transmitted correctly but not converted correctly ....
I'm using a LM35DZ temp sensor, which is an analog sensor without offset, and a scale of 10 mV per degree . This is a celsius sensor, so in my output sensor pin I have 0.31 V, which means 31°C , everything's good . But my problem is here . I have a data value at 85 (0x54), and converted, I have 98.53, and divided by 10, I have 9.85 following the formula . I m using a zigbee pro serie 1 .... and I have read this :
http://www.digi.com/wiki/developer/index.php/Voltage_Readings_in_XBee_Module
but I still have the same problem ..... Can you help me please ....
here is my code :
#define NUM_ANALOG_SAMPLES 5 // On définit la variable NUM_ANALOG_SAMPLES égale à 5
int packet[32];
int analogSamples[NUM_ANALOG_SAMPLES];
//=================== SETUP =================================
void setup() {
Serial.begin(9600);
delay(1000);
Serial.print("Starting..........");
Serial.println();
}
//==================== LOOP =================================
void loop() {
readPacket();
}
//==================== podprogramy XBEE ======================
void readPacket() { // fonction readPacket lit les paquets de données transmis
if (Serial.available() > 0) {
int b = Serial.read();
if (b == 0x7E) {
packet[0] = b; // On lit les trois premiers paquets puis on définit la taille des données transmises
packet[1] = readByte();
packet[2] = readByte();
int dataLength = (packet[1] << 8) | packet[2]; // Ici grace à datalength qui correspond a la concatenation du paquet 1 et 2
for(int i=1;i<=dataLength;i++) {
packet[2+i] = readByte(); // Ici on lit la suite des paquets reçus
}
int apiID = packet[3]; // On définit l ID API avec le paquet 3 .
int moduleID;
//0x83 signifie que c'est une réception en mode d'adressage 16 bits
if (apiID == 0x83) {
//int analogSampleIndex = 19;
moduleID = (packet[4] << 8) | packet[5];
int SgnlPwr = packet[6];
int SampleNumber = packet[8];
int i;
if (SampleNumber >= 1) {
for (i=1;i<=SampleNumber;i++) {
analogSamples[i] = (packet[10+i] << 8) | packet[11+i];
}
}
else {
analogSamples[i]=-1;
}
}
int reading = analogSamples[1]; // On lit la valeur de la broche 19
// On converti la valeur lue en millivolts
float v = ((float)reading / 1023.0) * 1200.0; //la valeur renvoyée ( 2 bits) dans le paquet représente une valeur entiere sur une échelle de 0 à 1023 (0x0 - 0x3FF)
// le maximum de tension sur les broches analogiques est de 1200 mV
// convert to Celcius. 10mv per Celcius degree
float c = v / 10.0;
printPacket(dataLength+4);
Serial.print("data: ");
Serial.println(reading);
Serial.print("valeur convertie : ");
Serial.println(v);
Serial.print("Module ");
Serial.println(moduleID);
Serial.print("Temperature: ");
Serial.println(c);
Serial.println();
Serial.println();
}
}
}
void printPacket(int l) {
for(int i=0;i < l;i++) {
if (packet[i] < 0xF) {
// print leading zero for single digit values
Serial.print(0);
}
Serial.print(packet[i], HEX);
Serial.print(" ");
}
Serial.println("");
}
int readByte() { // prog pour lire les données sur le port série. il renvoie la valeur serial.read
while (true) { // si le port série est dispo et a une information
if (Serial.available() > 0) {
return Serial.read();
}
}
}
and here my results :
7E 00 0A 83 00 03 58 00 01 04 00 00 53 00
data: 83
valeur convertie : 97.36
Module 3
Temperature: 9.74
7E 00 0A 83 00 04 50 00 01 04 00 00 54 00
data: 84
valeur convertie : 98.53
Module 4
Temperature: 9.85
7E 00 0A 83 00 03 57 00 01 04 00 00 53 00
data: 83
valeur convertie : 97.36
Module 3
Temperature: 9.74
7E 00 0A 83 00 04 51 00 01 04 00 00 54 00
data: 84
valeur convertie : 98.53
Module 4
Temperature: 9.85
