秋月電子通商のBME280温湿度気圧モジュールにて高度を測定しました。 ボードはSTM32L152REを使いました。 meas attitude by BME280 Module of Akiduki and STM32L152RE. http://akizukidenshi.com/catalog/g/gK-09421/ http://www.st.com/content/st_com/ja/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-nucleo/nucleo-l152re.html

Dependencies:   BME280 mbed

Fork of BME280_Hello by Toyomasa Watarai

秋月電子通商のBME280温湿度気圧モジュールにて高度を測定しました。 ボードはSTM32L152REを使いました。 Meas altitude by BME280 Module of Akiduki and STM32L152RE. http://akizukidenshi.com/catalog/g/gK-09421/ http://www.st.com/content/st_com/ja/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-nucleo/nucleo-l152re.html

Revision:
4:36164592a7ea
Parent:
0:2c9585cecfde
Child:
5:41f74665164b
--- a/main.cpp	Fri Jun 26 06:42:06 2015 +0000
+++ b/main.cpp	Tue Jun 28 15:22:35 2016 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "BME280.h"
 
-Serial pc(USBTX, USBRX);
+Serial pc(SERIAL_TX, SERIAL_RX);
 
 #if defined(TARGET_LPC1768)
 BME280 sensor(p28, p27);
@@ -9,10 +9,41 @@
 BME280 sensor(I2C_SDA, I2C_SCL);
 #endif
 
-int main() {
+static double t0,p0;
+
+void altitude_setup()
+{
+    t0 = sensor.getTemperature();
+    p0 = sensor.getPressure();
+
+}
+
+double altitude_calc()
+{
+    double altitude;
+
+    altitude = ((pow( p0 / sensor.getPressure() , 1 / 5.257) - 1) * (t0 + 273.15) ) / 0.0065;
+
+    return altitude;
+}
+
+
+int main()
+{
+
+    float altitude;
     
+    altitude_setup();
+
+
     while(1) {
-        pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity());
-        wait(1);
+
+        altitude = altitude_calc();
+
+        pc.printf("%.1nlf\n\r",altitude);
+        pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n\r", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity());
+
+        wait(0.2);
+
     }
 }