BME 280 library files

Committer:
Swabey89
Date:
Sun Nov 04 23:12:22 2018 +0000
Revision:
0:34bca8bf2146
BME280 library files added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Swabey89 0:34bca8bf2146 1 /**
Swabey89 0:34bca8bf2146 2 ******************************************************************************
Swabey89 0:34bca8bf2146 3 * @file BME280.h
Swabey89 0:34bca8bf2146 4 * @author Toyomasa Watarai
Swabey89 0:34bca8bf2146 5 * @version V1.0.0
Swabey89 0:34bca8bf2146 6 * @date 11 March 2017
Swabey89 0:34bca8bf2146 7 * @brief This file contains the class of a BME280 Combined humidity and pressure sensor library with I2C interface
Swabey89 0:34bca8bf2146 8 ******************************************************************************
Swabey89 0:34bca8bf2146 9 * @attention
Swabey89 0:34bca8bf2146 10 *
Swabey89 0:34bca8bf2146 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
Swabey89 0:34bca8bf2146 12 * of this software and associated documentation files (the "Software"), to deal
Swabey89 0:34bca8bf2146 13 * in the Software without restriction, including without limitation the rights
Swabey89 0:34bca8bf2146 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Swabey89 0:34bca8bf2146 15 * copies of the Software, and to permit persons to whom the Software is
Swabey89 0:34bca8bf2146 16 * furnished to do so, subject to the following conditions:
Swabey89 0:34bca8bf2146 17 *
Swabey89 0:34bca8bf2146 18 * The above copyright notice and this permission notice shall be included in
Swabey89 0:34bca8bf2146 19 * all copies or substantial portions of the Software.
Swabey89 0:34bca8bf2146 20 *
Swabey89 0:34bca8bf2146 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Swabey89 0:34bca8bf2146 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Swabey89 0:34bca8bf2146 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Swabey89 0:34bca8bf2146 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Swabey89 0:34bca8bf2146 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Swabey89 0:34bca8bf2146 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Swabey89 0:34bca8bf2146 27 * THE SOFTWARE.
Swabey89 0:34bca8bf2146 28 */
Swabey89 0:34bca8bf2146 29
Swabey89 0:34bca8bf2146 30 /**
Swabey89 0:34bca8bf2146 31 * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science
Swabey89 0:34bca8bf2146 32 * https://www.switch-science.com/catalog/2236/
Swabey89 0:34bca8bf2146 33 *
Swabey89 0:34bca8bf2146 34 * For more information about the BME280:
Swabey89 0:34bca8bf2146 35 * http://ae-bst.resource.bosch.com/media/products/dokumente/bme280/BST-BME280_DS001-10.pdf
Swabey89 0:34bca8bf2146 36 */
Swabey89 0:34bca8bf2146 37
Swabey89 0:34bca8bf2146 38 #ifndef MBED_BME280_H
Swabey89 0:34bca8bf2146 39 #define MBED_BME280_H
Swabey89 0:34bca8bf2146 40
Swabey89 0:34bca8bf2146 41 #include "mbed.h"
Swabey89 0:34bca8bf2146 42
Swabey89 0:34bca8bf2146 43 #define DEFAULT_SLAVE_ADDRESS (0x76 << 1)
Swabey89 0:34bca8bf2146 44
Swabey89 0:34bca8bf2146 45 #ifdef _DEBUG
Swabey89 0:34bca8bf2146 46 extern Serial pc;
Swabey89 0:34bca8bf2146 47 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
Swabey89 0:34bca8bf2146 48 #else
Swabey89 0:34bca8bf2146 49 #define DEBUG_PRINT(...)
Swabey89 0:34bca8bf2146 50 #endif
Swabey89 0:34bca8bf2146 51
Swabey89 0:34bca8bf2146 52 /** Interface for controlling BME280 Combined humidity and pressure sensor
Swabey89 0:34bca8bf2146 53 *
Swabey89 0:34bca8bf2146 54 * @code
Swabey89 0:34bca8bf2146 55 * #include "mbed.h"
Swabey89 0:34bca8bf2146 56 * #include "BME280.h"
Swabey89 0:34bca8bf2146 57 *
Swabey89 0:34bca8bf2146 58 * Serial pc(USBTX, USBRX);
Swabey89 0:34bca8bf2146 59 *
Swabey89 0:34bca8bf2146 60 * #if defined(TARGET_LPC1768)
Swabey89 0:34bca8bf2146 61 * BME280 sensor(p28, p27);
Swabey89 0:34bca8bf2146 62 * #else
Swabey89 0:34bca8bf2146 63 * BME280 sensor(I2C_SDA, I2C_SCL);
Swabey89 0:34bca8bf2146 64 * #endif
Swabey89 0:34bca8bf2146 65 *
Swabey89 0:34bca8bf2146 66 * int main() {
Swabey89 0:34bca8bf2146 67 *
Swabey89 0:34bca8bf2146 68 * while(1) {
Swabey89 0:34bca8bf2146 69 * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity());
Swabey89 0:34bca8bf2146 70 * wait(1);
Swabey89 0:34bca8bf2146 71 * }
Swabey89 0:34bca8bf2146 72 * }
Swabey89 0:34bca8bf2146 73 *
Swabey89 0:34bca8bf2146 74 * @endcode
Swabey89 0:34bca8bf2146 75 */
Swabey89 0:34bca8bf2146 76
Swabey89 0:34bca8bf2146 77 /** BME280 class
Swabey89 0:34bca8bf2146 78 *
Swabey89 0:34bca8bf2146 79 * BME280: A library to correct environmental data using Boshe BME280 environmental sensor device
Swabey89 0:34bca8bf2146 80 *
Swabey89 0:34bca8bf2146 81 */
Swabey89 0:34bca8bf2146 82 class BME280
Swabey89 0:34bca8bf2146 83 {
Swabey89 0:34bca8bf2146 84 public:
Swabey89 0:34bca8bf2146 85
Swabey89 0:34bca8bf2146 86 /** Create a BME280 instance
Swabey89 0:34bca8bf2146 87 * which is connected to specified I2C pins with specified address
Swabey89 0:34bca8bf2146 88 *
Swabey89 0:34bca8bf2146 89 * @param sda I2C-bus SDA pin
Swabey89 0:34bca8bf2146 90 * @param scl I2C-bus SCL pin
Swabey89 0:34bca8bf2146 91 * @param slave_adr (option) I2C-bus address (default: 0x76)
Swabey89 0:34bca8bf2146 92 */
Swabey89 0:34bca8bf2146 93 BME280(PinName sda, PinName sck, char slave_adr = DEFAULT_SLAVE_ADDRESS);
Swabey89 0:34bca8bf2146 94
Swabey89 0:34bca8bf2146 95 /** Create a BME280 instance
Swabey89 0:34bca8bf2146 96 * which is connected to specified I2C pins with specified address
Swabey89 0:34bca8bf2146 97 *
Swabey89 0:34bca8bf2146 98 * @param i2c_obj I2C object (instance)
Swabey89 0:34bca8bf2146 99 * @param slave_adr (option) I2C-bus address (default: 0x76)
Swabey89 0:34bca8bf2146 100 */
Swabey89 0:34bca8bf2146 101 BME280(I2C &i2c_obj, char slave_adr = DEFAULT_SLAVE_ADDRESS);
Swabey89 0:34bca8bf2146 102
Swabey89 0:34bca8bf2146 103 /** Destructor of BME280
Swabey89 0:34bca8bf2146 104 */
Swabey89 0:34bca8bf2146 105 virtual ~BME280();
Swabey89 0:34bca8bf2146 106
Swabey89 0:34bca8bf2146 107 /** Initializa BME280 sensor
Swabey89 0:34bca8bf2146 108 *
Swabey89 0:34bca8bf2146 109 * Configure sensor setting and read parameters for calibration
Swabey89 0:34bca8bf2146 110 *
Swabey89 0:34bca8bf2146 111 */
Swabey89 0:34bca8bf2146 112 void initialize(void);
Swabey89 0:34bca8bf2146 113
Swabey89 0:34bca8bf2146 114 /** Read the current temperature value (degree Celsius) from BME280 sensor
Swabey89 0:34bca8bf2146 115 *
Swabey89 0:34bca8bf2146 116 */
Swabey89 0:34bca8bf2146 117 float getTemperature(void);
Swabey89 0:34bca8bf2146 118
Swabey89 0:34bca8bf2146 119 /** Read the current pressure value (hectopascal)from BME280 sensor
Swabey89 0:34bca8bf2146 120 *
Swabey89 0:34bca8bf2146 121 */
Swabey89 0:34bca8bf2146 122 float getPressure(void);
Swabey89 0:34bca8bf2146 123
Swabey89 0:34bca8bf2146 124 /** Read the current humidity value (humidity %) from BME280 sensor
Swabey89 0:34bca8bf2146 125 *
Swabey89 0:34bca8bf2146 126 */
Swabey89 0:34bca8bf2146 127 float getHumidity(void);
Swabey89 0:34bca8bf2146 128
Swabey89 0:34bca8bf2146 129 private:
Swabey89 0:34bca8bf2146 130
Swabey89 0:34bca8bf2146 131 I2C *i2c_p;
Swabey89 0:34bca8bf2146 132 I2C &i2c;
Swabey89 0:34bca8bf2146 133 char address;
Swabey89 0:34bca8bf2146 134 uint16_t dig_T1;
Swabey89 0:34bca8bf2146 135 int16_t dig_T2, dig_T3;
Swabey89 0:34bca8bf2146 136 uint16_t dig_P1;
Swabey89 0:34bca8bf2146 137 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9;
Swabey89 0:34bca8bf2146 138 uint16_t dig_H1, dig_H3;
Swabey89 0:34bca8bf2146 139 int16_t dig_H2, dig_H4, dig_H5, dig_H6;
Swabey89 0:34bca8bf2146 140 int32_t t_fine;
Swabey89 0:34bca8bf2146 141
Swabey89 0:34bca8bf2146 142 };
Swabey89 0:34bca8bf2146 143
Swabey89 0:34bca8bf2146 144 #endif // MBED_BME280_H