BME280 Combined humidity and pressure sensor library with I2C interface

Dependents:   BME280_LCD BME280_Hello IFTTT_BME280_demo TweetTest ... more

Committer:
MACRUM
Date:
Sat Mar 11 04:21:14 2017 +0000
Revision:
5:c1f1647004c4
Parent:
4:ddcaa259e65b
Update doxygen comment

Who changed what in which revision?

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