BMP085 test

Dependencies:   mbed

Fork of bmp085_lib by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
khaledelmadawi
Date:
Sun Apr 05 19:17:27 2015 +0000
Parent:
1:1d88eb9f5bbd
Commit message:
Bmp085 test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1d88eb9f5bbd -r 5a2a1d891d40 main.cpp
--- a/main.cpp	Thu Oct 14 11:27:32 2010 +0000
+++ b/main.cpp	Sun Apr 05 19:17:27 2015 +0000
@@ -5,15 +5,57 @@
 
 DigitalOut myled(LED1);
 Serial pc(USBTX, USBRX);
+float get_altitude(float pressure);
+Timer t;
+Serial xbee1(p13, p14);
 
-int main() {
-    while(1) {
-        myled = 1;
+LocalFileSystem local("local");                    //////setting the destination of the file that will be saved
+float altitude,Max_altitude,altitude_node,pressure,Temperature;
+int main()
+{
+    pc.baud(9600);
+    xbee1.baud(9600);
 
-        bmp085.update();
-        pc.printf("p:%6.2f hPa / t:%6.2f C\n", bmp085.get_pressure(), bmp085.get_temperature());
-
-        myled = 0;
-        wait(3);
+    while(1)
+    {  xbee1.printf("select any button to start operation\r\n");
+       while(!xbee1.readable()/*||!pc.readable()*/);
+            xbee1.getc();
+    
+        t.reset();
+        t.start();
+        FILE *fp=fopen("/local/out.xls","a");
+         bmp085.update();
+        //Temperature=alt_sensor.get_temperature();
+        //pressure=alt_sensor.get_pressure();
+        altitude_node=get_altitude(bmp085.get_pressure());
+        Max_altitude=0;
+        while(1){
+            if(xbee1.readable()) {
+                xbee1.getc();
+                break;
+                }
+                bmp085.update();
+                //Temperature=alt_sensor.get_temperature();
+                //pressure=alt_sensor.get_pressure();
+                altitude=get_altitude(bmp085.get_pressure())-altitude_node;
+                if(Max_altitude<altitude){
+                     Max_altitude=altitude;
+                }
+                xbee1.printf("altitude:%f Max_alt%f t:%f\r\n",altitude,Max_altitude,t.read());                  
+                fprintf(fp,"%f \t %f \t %f \t %f \t %f\r\n",altitude,Max_altitude,pressure,Temperature,t.read());
+                pc.printf("altitude:%f Max_alt%f t:%f\r\n",altitude,Max_altitude,t.read());  
+            }
+            fclose(fp);
     }
 }
+
+
+
+float get_altitude(float pressure){
+    const float p0 = 1013.25;     // Pressure at sea level (Pa)
+    float altitude;
+
+    // Add this into loop(), after you've calculated the pressure
+    altitude = (float)44330 * (1 - (float)pow(((double) pressure/p0), 0.190295));
+    return altitude;
+    }