Analog comms with xbee. Program for the End Device.

Dependencies:   C12832_lcd Xbee_Hello_world_A mbed xbeeLibDannelly

Fork of Xbee_Hello_world_A by Tristan Hughes

Files at this revision

API Documentation at this revision

Comitter:
dannellyz
Date:
Sun Feb 15 16:42:43 2015 +0000
Parent:
0:9cbddcc86466
Commit message:
round 1

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
Xbee_Hello_world_A2.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
xbeeLibDannelly.lib Show annotated file Show diff for this revision Revisions of this file
xbee_lib.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Sun Feb 15 16:42:43 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Xbee_Hello_world_A2.lib	Sun Feb 15 16:42:43 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/tristanjph/code/Xbee_Hello_world_A/#9cbddcc86466
--- a/main.cpp	Fri Aug 31 14:46:32 2012 +0000
+++ b/main.cpp	Sun Feb 15 16:42:43 2015 +0000
@@ -1,18 +1,48 @@
 #include "mbed.h"
-#include "xbee.h"
+#include "xbee.h" // Include for xbee code
+#include "C12832_lcd.h" // Include for LCD code
+#include <stdio.h> //Include for sprintf
 
-xbee xbee1(p9,p10,p11); //Initalise xbee_lib
+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 
 
+
+//Initialize Potentiaometers 
+AnalogIn pot1(p19); 
+AnalogIn pot2(p20); 
 int main()
 {
-    char send_data[202]; //Xbee buffer size is 202 bytes
-    char read_data[202]; //Xbee buffer size is 202 bytes
+    char send_data1[202]; //Xbee buffer size is 202 bytes
+    
+    // reset the xbees (at least 200ns)
+    rst1 = 0;
+    wait_ms(1); 
+    rst1 = 1;
+    wait_ms(1);
 
+    //Give time for other Xbee to come online
+    wait(1);
+    
     while(1) {
-        pc.scanf("%s",send_data); //Read data from serial console
-        xbee1.SendData(send_data); //Send data to XBee
-        xbee1.RecieveData(read_data,0); //Read data from the XBee
-        pc.printf("You said:%s",read_data);
+        //Set up LCD and print
+        lcd.cls(); 
+        lcd.locate(0,2);
+        lcd.printf("Pot 1 = %.2f", (float)pot1);
+        lcd.locate(0,14);
+        lcd.printf("Pot 2 = %.2f", (float)pot2);
+        
+        wait(0.1);
+
+        //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/# 
+        
+        //Format is aPOT1bPOT2 to send 
+        sprintf (send_data1, "a%.2fb%.2f", (float)pot1,(float)pot2);
+        xbee1.SendData(send_data1); //Send data to XBee
+        
+        
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbeeLibDannelly.lib	Sun Feb 15 16:42:43 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/dannellyz/code/xbeeLibDannelly/#ea7028edb762
--- a/xbee_lib.lib	Fri Aug 31 14:46:32 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/tristanjph/code/xbee_lib/#ede20c047d8b