Thing Innovations / BME280

Dependents:   mDot_TTN_OTAA_Node LoraGPSLogger mDot_TTN_OTAA_Node_send_data_as_string

Fork of BME280 by Toyomasa Watarai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BME280.h Source File

BME280.h

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