Analog comms with xbee. Program for the Coordinator.

Dependencies:   C12832_lcd mbed xbeeLibDannelly

Fork of Xbee_Hello_World_B by Tristan Hughes

Revision:
1:4ce1378831fe
Parent:
0:122702c9168a
Child:
2:9b7d98c295d9
--- a/main.cpp	Fri Aug 31 14:47:12 2012 +0000
+++ b/main.cpp	Sun Feb 15 16:40:31 2015 +0000
@@ -1,14 +1,57 @@
 #include "mbed.h"
-#include "xbee.h"
-
-xbee xbee1(p9,p10,p11); //Initalise xbee_lib
+#include "xbee.h" // Include for xbee code
+#include "C12832_lcd.h" // Include for LCD code
+#include <string.h> //Iclude for string handeling
+xbee xbee1(p9,p10,p30); //Initalise xbee_lib varName(rx,tx,reset)
+DigitalOut rst1(p30);
+Serial pc(USBTX, USBRX); //Initalise PC serial comms
+C12832_LCD lcd; //Initialize LCD Screen
 
 int main()
 {
-    char read_data[202]; //Xbee buffer size is 202 bytes
+    //In AT mode we are constantly transmitting so it is 
+    //necessary to implement an external protocol 
+    //see https://developer.mbed.org/users/dannellyz/notebook/at-vs-api-when-why-how/# 
+    
+    //For this we will use two buffers one for each 
+    //expected reading from the appBoard pot1/pot2
+    char readData1[202]; //Xbee buffer size is 202 bytes
+    char readData2[202]; //Xbee buffer size is 202 bytes
 
+    // reset the xbees (at least 200ns)
+    rst1 = 0;
+    wait_ms(1); 
+    rst1 = 1;
+    wait_ms(1);
+    
+    //Setup LCD screen
+    lcd.cls();      
+    lcd.locate(0,1);
+    
+    
     while(1) {
-        xbee1.RecieveData(read_data,0); //Read data from the XBee
-        xbee1.SendData(read_data); //Send data to XBee
+        
+        //RecieveDataChar allows you to read data in until the
+        //seperator which is the second argument
+        
+        //Recieve data format POT2a
+        xbee1.RecieveDataChar(readData1,'a'); //Read data from the XBee
+        //Recieve data format POT1b
+        xbee1.RecieveDataChar(readData2,'b'); //Read data from the XBee
+        //Needed to keep in sync with other xbee
+        wait(0.1);
+        
+        //Clean data by removing delimeter
+        readData1[strlen(readData1)-1] = 0;
+        readData2[strlen(readData2)-1] = 0;
+        
+        //Change values back to floats for possible use later
+        float pot1 = atof(readData2);
+        float pot2 = atof(readData1);
+        
+        //Echo data 
+        pc.printf("Pot1= %.2f Pot2= %.2f \n\r",pot1,pot2);
+        lcd.printf("Pot1= %.2f Pot2= %.2f \n\r",pot1,pot2);
     }
-}
\ No newline at end of file
+}
+