This program is for Cansat made with BreadBoard which have pressure sensor LPS331. This program is based on http://mbed.org/users/nyamfg/code/LPS331_HelloWorld/

Dependencies:   mbed

Revision:
9:3285ed711197
Parent:
8:505d06bba7b1
Child:
10:40521f3084ba
--- a/main.cpp	Mon Sep 08 06:06:04 2014 +0000
+++ b/main.cpp	Mon Sep 08 07:43:57 2014 +0000
@@ -15,9 +15,12 @@
 
 Timer t;
 
+float ground_height;
+
 LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); // 気圧センサ
 
 int main() {
+    float temp, pres;
     JPlow = 0;
     JP.mode(PullUp);
 
@@ -32,15 +35,19 @@
     telem.printf("BBsat start. **********\r\n");  // テレメトリ用出力
 
     t.start();
+
+    pres = lps331.getPressure();    // 気圧
+    temp = lps331.getTemperature(); //
+    ground_height = lps331.getAltitude(P0, TEMP, pres);
     
     while(1) {
         int ms=0;       // リセットからの経過時間(単位:ミリ秒(MilliSecond)
-        float pres=lps331.getPressure();    // 気圧
-        float temp=lps331.getTemperature(); // 気温
         float height;                       // 高度
+        pres=lps331.getPressure();    // 気圧
+        temp=lps331.getTemperature(); // 気温
 
         // 高度算出
-        height = ( (powf((P0/pres),1/5.257f)-1)*(TEMP+273.15) ) / 0.0065f;
+        height = lps331.getAltitude(P0, TEMP, pres);
         
         if(JP==0) {     // JPが0(GND)だったら、
             break;      //whileのループを終了
@@ -49,10 +56,10 @@
         ms = t.read_ms(); //現在時刻を取得
 
         FILE *fp = fopen("/local/data.txt", "a");
-        fprintf(fp,  "%10d,%6.2f,%4.1f,%5.1f\r\n", ms, pres, temp, height);   // 時刻,気圧,気温を出力
+        fprintf(fp,  "%10d,%6.2f,%4.1f,%5.1f\r\n", ms, pres, temp, height-ground_height);   // 時刻,気圧,気温を出力
         fclose(fp);
 
-        telem.printf("%10d,%6.2f,%4.1f,%5.1f\r\n", ms, pres, temp, height);   // 時刻,気圧,気温を出力
+        telem.printf("%10d,%6.2f,%4.1f,%5.1f\r\n", ms, pres, temp, height-ground_height);   // 時刻,気圧,気温を出力
         wait(0.05);     // LED点滅
         myled = 1;
         wait(0.05);