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: BOX_1
BME280.h
00001 /** 00002 * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science 00003 * https://www.switch-science.com/catalog/2236/ 00004 * 00005 * For more information about the BME280: 00006 * http://ae-bst.resource.bosch.com/media/products/dokumente/bme280/BST-BME280_DS001-10.pdf 00007 */ 00008 00009 #ifndef MBED_BME280_H 00010 #define MBED_BME280_H 00011 00012 #include "mbed.h" 00013 00014 #define DEFAULT_SLAVE_ADDRESS (0x76 << 1) 00015 00016 #ifdef _DEBUG 00017 //extern Serial pc; 00018 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) 00019 #else 00020 #define DEBUG_PRINT(...) 00021 #endif 00022 00023 /** Interface for controlling BME280 Combined humidity and pressure sensor 00024 * 00025 * @code 00026 * #include "mbed.h" 00027 * #include "BME280.h" 00028 * 00029 * Serial pc(USBTX, USBRX); 00030 * 00031 * #if defined(TARGET_LPC1768) 00032 * BME280 sensor(p28, p27); 00033 * #else 00034 * BME280 sensor(I2C_SDA, I2C_SCL); 00035 * #endif 00036 * 00037 * int main() { 00038 * 00039 * while(1) { 00040 * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity()); 00041 * wait(1); 00042 * } 00043 * } 00044 * 00045 * @endcode 00046 */ 00047 00048 /** BME280 class 00049 * 00050 * BME280: A library to correct environmental data using Boshe BME280 environmental sensor device 00051 * 00052 */ 00053 class BME280 00054 { 00055 public: 00056 00057 /** Create a BME280 instance 00058 * which is connected to specified I2C pins with specified address 00059 * 00060 * @param sda I2C-bus SDA pin 00061 * @param scl I2C-bus SCL pin 00062 * @param slave_adr (option) I2C-bus address (default: 0x76) 00063 */ 00064 BME280(PinName sda, PinName sck, char slave_adr = DEFAULT_SLAVE_ADDRESS); 00065 00066 /** Create a BME280 instance 00067 * which is connected to specified I2C pins with specified address 00068 * 00069 * @param i2c_obj I2C object (instance) 00070 * @param slave_adr (option) I2C-bus address (default: 0x76) 00071 */ 00072 BME280(I2C &i2c_obj, char slave_adr = DEFAULT_SLAVE_ADDRESS); 00073 00074 /** Destructor of BME280 00075 */ 00076 virtual ~BME280(); 00077 00078 /** Initializa BME280 sensor 00079 * 00080 * Configure sensor setting and read parameters for calibration 00081 * 00082 */ 00083 void initialize(void); 00084 00085 /** Read the current temperature value (degree Celsius) from BME280 sensor 00086 * 00087 */ 00088 float getTemperature(void); 00089 00090 /** Read the current pressure value (hectopascal)from BME280 sensor 00091 * 00092 */ 00093 float getPressure(void); 00094 00095 /** Read the current humidity value (humidity %) from BME280 sensor 00096 * 00097 */ 00098 float getHumidity(void); 00099 00100 private: 00101 00102 I2C *i2c_p; 00103 I2C &i2c; 00104 char address; 00105 uint16_t dig_T1; 00106 int16_t dig_T2, dig_T3; 00107 uint16_t dig_P1; 00108 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9; 00109 uint16_t dig_H1, dig_H3; 00110 int16_t dig_H2, dig_H4, dig_H5, dig_H6; 00111 int32_t t_fine; 00112 00113 }; 00114 00115 #endif // MBED_BME280_H
Generated on Sat Jul 16 2022 00:45:31 by
1.7.2