A modified library for BME280 sensor.
Dependents: Auto_pilot_prototype_3_2
BME280.h
00001 /** 00002 ****************************************************************************** 00003 * @file BME280.h 00004 * @author Toyomasa Watarai 00005 * @version V1.0.0 00006 * @date 11 March 2017 00007 * @brief This file contains the class of a BME280 Combined humidity and pressure sensor library with I2C interface 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a copy 00012 * of this software and associated documentation files (the "Software"), to deal 00013 * in the Software without restriction, including without limitation the rights 00014 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 * copies of the Software, and to permit persons to whom the Software is 00016 * furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included in 00019 * all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 * THE SOFTWARE. 00028 */ 00029 00030 /** 00031 * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science 00032 * https://www.switch-science.com/catalog/2236/ 00033 * 00034 * For more information about the BME280: 00035 * http://ae-bst.resource.bosch.com/media/products/dokumente/bme280/BST-BME280_DS001-10.pdf 00036 */ 00037 00038 #ifndef MBED_BME280_H 00039 #define MBED_BME280_H 00040 00041 #include "mbed.h" 00042 00043 #define DEFAULT_SLAVE_ADDRESS (0x76 << 1) 00044 00045 #ifdef _DEBUG 00046 extern Serial pc; 00047 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) 00048 #else 00049 #define DEBUG_PRINT(...) 00050 #endif 00051 00052 /** Interface for controlling BME280 Combined humidity and pressure sensor 00053 * 00054 * @code 00055 * #include "mbed.h" 00056 * #include "BME280.h" 00057 * 00058 * Serial pc(USBTX, USBRX); 00059 * 00060 * #if defined(TARGET_LPC1768) 00061 * BME280 sensor(p28, p27); 00062 * #else 00063 * BME280 sensor(I2C_SDA, I2C_SCL); 00064 * #endif 00065 * 00066 * int main() { 00067 * 00068 * while(1) { 00069 * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity()); 00070 * wait(1); 00071 * } 00072 * } 00073 * 00074 * @endcode 00075 */ 00076 00077 /** BME280 class 00078 * 00079 * BME280: A library to correct environmental data using Boshe BME280 environmental sensor device 00080 * 00081 */ 00082 class BME280 00083 { 00084 public: 00085 00086 /** Create a BME280 instance 00087 * which is connected to specified I2C pins with specified address 00088 * 00089 * @param sda I2C-bus SDA pin 00090 * @param scl I2C-bus SCL pin 00091 * @param slave_adr (option) I2C-bus address (default: 0x76) 00092 */ 00093 BME280(PinName sda, PinName sck, char slave_adr = DEFAULT_SLAVE_ADDRESS); 00094 00095 /** Create a BME280 instance 00096 * which is connected to specified I2C pins with specified address 00097 * 00098 * @param i2c_obj I2C object (instance) 00099 * @param slave_adr (option) I2C-bus address (default: 0x76) 00100 */ 00101 BME280(I2C &i2c_obj, char slave_adr = DEFAULT_SLAVE_ADDRESS); 00102 00103 /** Destructor of BME280 00104 */ 00105 virtual ~BME280(); 00106 00107 /** Initializa BME280 sensor 00108 * 00109 * Configure sensor setting and read parameters for calibration 00110 * 00111 */ 00112 void initialize(void); 00113 00114 /** Read the current temperature value (degree Celsius) from BME280 sensor 00115 * 00116 */ 00117 float getTemperature(void); 00118 00119 /** Read the current pressure value (hectopascal)from BME280 sensor 00120 * 00121 */ 00122 float getPressure(void); 00123 00124 /** Read the current humidity value (humidity %) from BME280 sensor 00125 * 00126 */ 00127 float getHumidity(void); 00128 00129 private: 00130 00131 I2C *i2c_p; 00132 I2C &i2c; 00133 char address; 00134 uint16_t dig_T1; 00135 int16_t dig_T2, dig_T3; 00136 uint16_t dig_P1; 00137 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9; 00138 uint16_t dig_H1, dig_H3; 00139 int16_t dig_H2, dig_H4, dig_H5, dig_H6; 00140 int32_t t_fine; 00141 00142 }; 00143 00144 #endif // MBED_BME280_H
Generated on Thu Jul 14 2022 07:31:25 by 1.7.2