Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
BMP180.h
00001 /* 00002 @file BMP180.h 00003 00004 @brief Barometric Pressure and Temperature Sensor BMP180 Breakout I2C Library 00005 00006 @Author spiridion (http://mailme.spiridion.net) 00007 00008 Tested on LPC1768 and FRDM-KL25Z 00009 00010 Copyright (c) 2014 spiridion 00011 Released under the MIT License (see http://mbed.org/license/mit) 00012 00013 Documentation regarding the BMP180 can be found here: 00014 http://mbed.org/media/uploads/spiridion/bst-bmp180-ds000-09.pdf 00015 */ 00016 00017 #ifndef BMP180_H 00018 #define BMP180_H 00019 00020 #include "mbed.h" 00021 00022 /// default address is 0xEF 00023 #define BMP180_I2C_ADDRESS 0xEF 00024 00025 // Oversampling settings 00026 #define BMP180_OSS_ULTRA_LOW_POWER 0 // 1 sample and 4.5ms for conversion 00027 #define BMP180_OSS_NORMAL 1 // 2 samples and 7.5ms for conversion 00028 #define BMP180_OSS_HIGH_RESOLUTION 2 // 4 samples and 13.5ms for conversion 00029 #define BMP180_OSS_ULTRA_HIGH_RESOLUTION 3 // 8 samples and 25.5ms for conversion 00030 00031 #define UNSET_BMP180_PRESSURE_VALUE 0.F 00032 #define UNSET_BMP180_TEMPERATURE_VALUE -273.15F // absolute zero 00033 00034 /** BMP180 class. 00035 * Read Pressure and temperature from the BMP180 Breakout I2C sensor 00036 * 00037 * Example: 00038 * @code 00039 * #include "mbed.h" 00040 * #include "BMP180.h" 00041 * 00042 * #if defined(TARGET_LPC1768) 00043 * #define PIN_SDA p9 00044 * #define PIN_SCL p10 00045 * #elif defined(TARGET_KL25Z) // watch out for the PTE0/PTE1 mixed up in the KL25Z doc 00046 * #define PIN_SDA PTE0 00047 * #define PIN_SCL PTE1 00048 * #endif 00049 * 00050 * int main() 00051 * { 00052 * BMP180 bmp180(PIN_SDA, PIN_SCL); 00053 * float pressure, temperature; 00054 * 00055 * // bmp180.Initialize(); // no altitude compensation and normal oversampling 00056 * bmp180.Initialize(64, BMP180_OSS_ULTRA_LOW_POWER); // 64m altitude compensation and low power oversampling 00057 * 00058 * while(1) 00059 * { 00060 * if (bmp180.ReadData(&pressure, &temperature)) 00061 * printf("Pressure(hPa): %8.2f \t Temperature(C): %8.2f\n", pressure, temperature); 00062 * wait(1); 00063 * } 00064 * } 00065 * @endcode 00066 */ 00067 class BMP180 00068 { 00069 00070 public: 00071 00072 /** Create a BMP180 instance 00073 * @param i2c object 00074 * @param address: I2C slave address 00075 */ 00076 BMP180(I2C *i2c, int address = BMP180_I2C_ADDRESS); 00077 00078 /** Initialization: set member values and read BMP180 calibration parameters 00079 * @param altitude (in meter) 00080 * @param overSamplingSetting 00081 */ 00082 int Initialize(float altitude = 0.F, int overSamplingSetting = BMP180_OSS_NORMAL); 00083 00084 /** Read pressure and temperature from the BMP180. 00085 * @param pressure (hPa) 00086 * @param temperature (C) 00087 * @returns 00088 * 1 on success, 00089 * 0 on error 00090 */ 00091 int ReadData(float* pTemperature = NULL, float* pPressure = NULL); 00092 double ReadAltitude(double sealevelPressure=1029.5); 00093 /** Get temperature from a previous measurement 00094 * 00095 * @returns 00096 * temperature (C) 00097 */ 00098 float GetTemperature() {return m_temperature;}; 00099 00100 /** Get pressure from a previous measurement 00101 * 00102 * @returns 00103 * pressure (hPa) 00104 */ 00105 float GetPressure() {return m_pressure;}; 00106 00107 protected: 00108 00109 /** Perform temperature measurement 00110 * 00111 * @returns 00112 * temperature (C) 00113 */ 00114 int ReadRawTemperature(long* pUt); 00115 00116 /** Perform pressure measurement 00117 * 00118 * @returns 00119 * temperature (C) 00120 */ 00121 int ReadRawPressure(long* pUp); 00122 00123 /** Calculation of the temperature from the digital output 00124 */ 00125 float TrueTemperature(long ut); 00126 00127 /** Calculation of the pressure from the digital output 00128 */ 00129 float TruePressure(long up); 00130 00131 int m_oss; 00132 float m_temperature; 00133 float m_pressure; 00134 float m_altitude; 00135 00136 I2C *m_i2c; 00137 int m_addr; 00138 char m_data[4]; 00139 00140 short ac1, ac2, ac3; 00141 unsigned short ac4, ac5, ac6; 00142 short b1, b2; 00143 short mb, mc, md; 00144 long x1, x2, x3, b3, b5, b6; 00145 unsigned long b4, b7; 00146 00147 }; 00148 00149 #endif
Generated on Tue Sep 13 2022 05:19:36 by
1.7.2
