LPS25H sample

Dependencies:   AQM0802 LPS25H mbed

See http://developer.mbed.org/users/yasuyuki/notebook/LPS25H/

Committer:
yasuyuki
Date:
Sun Oct 12 02:44:32 2014 +0000
Revision:
0:f7ac3f4062cf
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:f7ac3f4062cf 1 //**********************
yasuyuki 0:f7ac3f4062cf 2 // Barometer and Altimeter
yasuyuki 0:f7ac3f4062cf 3 // LPS25H sample for mbed
yasuyuki 0:f7ac3f4062cf 4 //
yasuyuki 0:f7ac3f4062cf 5 // LPC1768 flash=512KB, ADC=12bits
yasuyuki 0:f7ac3f4062cf 6 // LPC11U35 flash=64KB, ADC=10bits
yasuyuki 0:f7ac3f4062cf 7 // Nucleo ADC=12bits
yasuyuki 0:f7ac3f4062cf 8 //
yasuyuki 0:f7ac3f4062cf 9 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:f7ac3f4062cf 10 // http://einstlab.web.fc2.com
yasuyuki 0:f7ac3f4062cf 11 //**********************
yasuyuki 0:f7ac3f4062cf 12 #include "mbed.h"
yasuyuki 0:f7ac3f4062cf 13 #include "AQM0802.h"
yasuyuki 0:f7ac3f4062cf 14 #include "LPS25H.h"
yasuyuki 0:f7ac3f4062cf 15
yasuyuki 0:f7ac3f4062cf 16 #if defined(TARGET_LPC1768)
yasuyuki 0:f7ac3f4062cf 17 I2C i2c(p28,p27);
yasuyuki 0:f7ac3f4062cf 18 #endif
yasuyuki 0:f7ac3f4062cf 19 // for TG-LPC11U35-501
yasuyuki 0:f7ac3f4062cf 20 #if defined(TARGET_LPC11U35_501)
yasuyuki 0:f7ac3f4062cf 21 I2C i2c(P0_5,P0_4);
yasuyuki 0:f7ac3f4062cf 22 #endif
yasuyuki 0:f7ac3f4062cf 23 // for Nucleo
yasuyuki 0:f7ac3f4062cf 24 #if defined(TARGET_NUCLEO_F401RE)
yasuyuki 0:f7ac3f4062cf 25 I2C i2c(D14,D15);
yasuyuki 0:f7ac3f4062cf 26 #endif
yasuyuki 0:f7ac3f4062cf 27
yasuyuki 0:f7ac3f4062cf 28 AQM0802 lcd(i2c);
yasuyuki 0:f7ac3f4062cf 29 LPS25H lps25h(i2c);
yasuyuki 0:f7ac3f4062cf 30
yasuyuki 0:f7ac3f4062cf 31 #define T0 288.15
yasuyuki 0:f7ac3f4062cf 32 #define dT 0.0065
yasuyuki 0:f7ac3f4062cf 33 #define P0 101325.0
yasuyuki 0:f7ac3f4062cf 34 #define g 9.80665
yasuyuki 0:f7ac3f4062cf 35 #define R 287.052
yasuyuki 0:f7ac3f4062cf 36 double GetAltitude(double p, double t){
yasuyuki 0:f7ac3f4062cf 37
yasuyuki 0:f7ac3f4062cf 38 return (t+273.15)/dT*(pow((P0/p),dT*R/g)-1);
yasuyuki 0:f7ac3f4062cf 39
yasuyuki 0:f7ac3f4062cf 40 }
yasuyuki 0:f7ac3f4062cf 41
yasuyuki 0:f7ac3f4062cf 42 int main() {
yasuyuki 0:f7ac3f4062cf 43
yasuyuki 0:f7ac3f4062cf 44 char msg[10];
yasuyuki 0:f7ac3f4062cf 45 int p, t, a;
yasuyuki 0:f7ac3f4062cf 46
yasuyuki 0:f7ac3f4062cf 47 sprintf(msg,"Barometer");
yasuyuki 0:f7ac3f4062cf 48 lcd.locate(0,0);
yasuyuki 0:f7ac3f4062cf 49 lcd.print(msg);
yasuyuki 0:f7ac3f4062cf 50 sprintf(msg,"Altimeter");
yasuyuki 0:f7ac3f4062cf 51 lcd.locate(0,1);
yasuyuki 0:f7ac3f4062cf 52 lcd.print(msg);
yasuyuki 0:f7ac3f4062cf 53 wait(1);
yasuyuki 0:f7ac3f4062cf 54
yasuyuki 0:f7ac3f4062cf 55 while(1) {
yasuyuki 0:f7ac3f4062cf 56
yasuyuki 0:f7ac3f4062cf 57 p = (double)lps25h.pressure()/40.96;
yasuyuki 0:f7ac3f4062cf 58 t = 42.5 + (double)lps25h.temperature()/480.0;
yasuyuki 0:f7ac3f4062cf 59 a = GetAltitude(p,t);
yasuyuki 0:f7ac3f4062cf 60
yasuyuki 0:f7ac3f4062cf 61 sprintf(msg,"%6dPa",p);
yasuyuki 0:f7ac3f4062cf 62 lcd.locate(0,0);
yasuyuki 0:f7ac3f4062cf 63 lcd.print(msg);
yasuyuki 0:f7ac3f4062cf 64 sprintf(msg,"%4dm%2dC", a, t);
yasuyuki 0:f7ac3f4062cf 65 lcd.locate(0,1);
yasuyuki 0:f7ac3f4062cf 66 lcd.print(msg);
yasuyuki 0:f7ac3f4062cf 67 wait(1);
yasuyuki 0:f7ac3f4062cf 68 }
yasuyuki 0:f7ac3f4062cf 69
yasuyuki 0:f7ac3f4062cf 70 }
yasuyuki 0:f7ac3f4062cf 71