Pages: 1 [2]   Go Down
Author Topic: XBEE communication problems  (Read 1492 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have xbee series 1, just as I want to make a network to send temperature data and the arduino receives them and likewise can be displayed on the serial monitor of arduino, know how to change the truth if my strength is hardware, but programming is difficult if I, if I say that line of source code will have to modify the appreciate in advance.

here it is:

/ * This program was written for the Arduino Uno The One has an XBee Series 2 RF Module connected to it as a coordinator. The One uses the XBee coordinator to comunicate with two router or end point XBees with temperature sensors. This program recieves the temperature readings from the two endpoint XBees and writes the data to the serial monitor * /

/ * Each Xbee has a unque 64 bit address. The first 32 bits are common to all XBee. The Following four ints (each holds an address byte int) hold the unique 32 bits of the second half of the XBee address * /
  int addr1;
  int addr2;
  addr3 int;
  addr4 int;
  sen3Counter int = 0; / / This variable counter is used print sensor 3 seconds every 5

void setup () {
  Serial.begin (9600); / / start the serial communication
}

void loop () {
   if (Serial.available ()> = 21) {/ / Wait for XBee coordinator to recieve full frame
     if (Serial.read () == 0x7E) {/ / Look for porque 7E is the start byte
       for (int i = 1; i <19; i + +) {/ / Skip through the frame to get to the unique 32-bit address
         / / get each byte of the XBee address
         if (i == smiley-cool {addr1 = Serial.read (); }
         else if (i == 9) {addr2 = Serial.read (); }
         else if (i == 10) {addr3 = Serial.read (); }
         else if (i == 11) {addr4 = Serial.read (); }
         else {byte discardByte Serial.read = (); } / / Else throwout byte we do not need it
       }
       Serial.read analogMSB = int (); / / Read the first byte analog data
       Serial.read analogLSB = int (); / / Read the second byte
       float volt = calculateXBeeVolt (analogMSB, analogLSB) ;/ / Convert values ​​to analog voltage values
       Serial.println (indentifySensor (addr1, addr2, addr3, addr4)); / / get identity of XBee and print it
       Serial.print ("Temperature in F:");
       Serial.println (calculateTempF (volt)); / / calculate temperature value from voltage value
     }
   }
   delay (10); / / delay to allow operations to complete
   / / This if else statement is used to print sensor 3 value every 5 second to match the XBee routers
   / / It uses the delay () function above to calculate 5 seconds
   if (sen3Counter <500) {+ + sen3Counter; }
   else {
     Serial.println ("Temperature sensor 3 from:") ;/ / This is sensor 3
     Serial.print ("Temperature in F:");
     / / Calculates the Following line voltage, then temperature, and then prints to serial monitor temp
     Serial.println (calculateTempF (calculateArduinoVolt (analogRead (A0))));
     sen3Counter = 0; / / reset counter back to zero to start another 5 seconds
   }
}

/ / Function Takes in the XBee address and returns the identity of the Xbee That sent the temperature data
IndentifySensor String (int a1, int a2, int a3, int a4) {
   Rout1 int [] = {64, 176, 163, 166}; / / Arrays are the 32 bit address of the two routers XBees
   rout2 int [] = {64, 177, 63, 221};
   if (a1 == Rout1
  • == a2 && Rout1 [1] && a3 == Rout1 [2] && a4 == Rout1 [3]) {/ / Check if Sensor 1
     return "from Temperature sensor 1:"; } / / Temp data is from one XBee
   else if (a1 == rout2
  • == a2 && rout2 [1] && a3 == rout2 [2] && a4 == rout2 [3]) {/ / Check if Sensor 2
     return "from Temperature Sensor 2"; } / / Temp data is from two XBee
   else {return "I do not know this sensor"; } / / Data is from an unknown XBee
}

/ / this function Calculates temp in F from temp sensor
calculateTempF float (float v1) {
  float temp = 0;
  / / calculate temp in C, .75 is 25 volts 10mV per degree C.
  if (v1 <.75) {temp = 25 - ((75-v1) / 01); } / / If below 25 C
  else if (v1 == 75) {temp = 25; }
  else {temp = 25 + ((v1 - .75) / .01); } / / If above 25
  / / convert to F
  temp = ((temp * 9) / 5) + 32;
  return temp;
}

/ / This function Takes an XBee analog pin reading and converts it to a voltage value
calculateXBeeVolt float (analogMSB int, int analogLSB) {
   analogReading analogLSB + = int (analogMSB * 256); / / Turn the two bytes into an integer value
   float volt = ((float) analogReading / 1023) * 1.23; / / Convert the analog voltage value to a value
   volt return;
}

/ / This function Takes an Arduino analog pin reading and converts it to a voltage value
calculateArduinoVolt float (int val) {
  float volt = (float) val * (5.0 / 1023.0); / / convert ADC value to voltage
  volt return;
}
Logged

Pages: 1 [2]   Go Up
Jump to: