Library for Bosch BMP280 temperature and pressure sensor
Dependents: ELEC350-LCD-DEMO ELEC350-CWTEMPLATE-2017 ELEC351_v1 ELEC350-CWTEMPLATE-2017 ... more
Fork of BMP280 by
Library for Temperature and Pressure Sensor Bosch BMP280.
Breakoutboard for example from Adafruit
Revision 8:d22ecbef9b90, committed 2017-05-25
- Comitter:
- charly
- Date:
- Thu May 25 20:22:32 2017 +0000
- Parent:
- 7:c72b726c7dc9
- Commit message:
- Buxfix in readTemperature
Changed in this revision
BMP280.cpp | Show annotated file Show diff for this revision Revisions of this file |
BMP280.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r c72b726c7dc9 -r d22ecbef9b90 BMP280.cpp --- a/BMP280.cpp Tue Apr 19 02:03:35 2016 +0000 +++ b/BMP280.cpp Thu May 25 20:22:32 2017 +0000 @@ -5,6 +5,8 @@ * @version 1.0 * @date 06-April-2015 * + * bugfixing by charly + * * Library for "BMP280 temperature, humidity and pressure sensor module" from Switch Science * https://www.switch-science.com/catalog/2236/ * @@ -19,7 +21,7 @@ : i2c_p(new I2C(sda, scl)), i2c(*i2c_p), - address(slave_adr), + address(slave_adr<<1), t_fine(0) { initialize(); @@ -29,7 +31,7 @@ : i2c_p(NULL), i2c(i2c_obj), - address(slave_adr), + address(slave_adr<<1), t_fine(0) { initialize(); @@ -45,16 +47,17 @@ { char cmd[18]; - cmd[0] = 0xf2; // ctrl_hum - cmd[1] = 0x01; // Humidity oversampling x1 - i2c.write(address, cmd, 2); + //cmd[0] = 0xf2; // ctrl_hum + //cmd[1] = 0x01; // Humidity oversampling x1 + //i2c.write(address, cmd, 2); cmd[0] = 0xf4; // ctrl_meas - cmd[1] = 0x27; // Temparature oversampling x1, Pressure oversampling x1, Normal mode + //cmd[1] = 0x27; // Temparature oversampling x1, Pressure oversampling x1, Normal mode + cmd[1] = 0b01010111; // Temparature oversampling x2 010, Pressure oversampling x16 101, Normal mode 11 i2c.write(address, cmd, 2); cmd[0] = 0xf5; // config - cmd[1] = 0xa0; // Standby 1000ms, Filter off + cmd[1] = 0b10111100; // Standby 1000ms, Filter x16 i2c.write(address, cmd, 2); cmd[0] = 0x88; // read dig_T regs @@ -65,7 +68,8 @@ dig_T2 = (cmd[3] << 8) | cmd[2]; dig_T3 = (cmd[5] << 8) | cmd[4]; - DEBUG_PRINT("dig_T = 0x%x, 0x%x, 0x%x\n", dig_T1, dig_T2, dig_T3); + DEBUG_PRINT("dig_T = 0x%x, 0x%x, 0x%x\n\r", dig_T1, dig_T2, dig_T3); + DEBUG_PRINT("dig_T = %d, %d, %d\n\r", dig_T1, dig_T2, dig_T3); cmd[0] = 0x8E; // read dig_P regs i2c.write(address, cmd, 1); @@ -103,7 +107,7 @@ float BMP280::getTemperature() { - uint32_t temp_raw; + int32_t temp_raw; float tempf; char cmd[4]; @@ -112,17 +116,19 @@ i2c.read(address, &cmd[1], 3); temp_raw = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4); + DEBUG_PRINT("\r\ntemp_raw:%d",temp_raw); - int32_t temp; + int32_t temp1, temp2,temp; - temp = - (((((temp_raw >> 3) - (dig_T1 << 1))) * dig_T2) >> 11) + - ((((((temp_raw >> 4) - dig_T1) * ((temp_raw >> 4) - dig_T1)) >> 12) * dig_T3) >> 14); - - t_fine = temp; - temp = (temp * 5 + 128) >> 8; + temp1 =((((temp_raw >> 3) - (dig_T1 << 1))) * dig_T2) >> 11; + temp2 =(((((temp_raw >> 4) - dig_T1) * ((temp_raw >> 4) - dig_T1)) >> 12) * dig_T3) >> 14; + DEBUG_PRINT(" temp1:%d temp2:%d",temp1, temp2); + t_fine = temp1+temp2; + DEBUG_PRINT(" t_fine:%d",t_fine); + temp = (t_fine * 5 + 128) >> 8; tempf = (float)temp; - + DEBUG_PRINT(" tempf:%f",tempf); + return (tempf/100.0f); }
diff -r c72b726c7dc9 -r d22ecbef9b90 BMP280.h --- a/BMP280.h Tue Apr 19 02:03:35 2016 +0000 +++ b/BMP280.h Thu May 25 20:22:32 2017 +0000 @@ -18,7 +18,9 @@ #include "mbed.h" //#define _DEBUG -#define DEFAULT_SLAVE_ADDRESS (0x77 << 1) +// default address with SDO High 0x77 +// address with SDO LOW 0x76 +#define DEFAULT_SLAVE_ADDRESS (0x77) #ifdef _DEBUG extern Serial pc; @@ -30,7 +32,8 @@ /** BME280 class * - * BME280: A library to correct environmental data using Boshe BME280 device + * BME280: A library to read environmental data using Bosch BME280 device + * Readds temperature and pressure * * BME280 is an environmental sensor * @endcode @@ -45,7 +48,7 @@ * * @param sda I2C-bus SDA pin * @param scl I2C-bus SCL pin - * @param slave_adr (option) I2C-bus address (default: 0x76) + * @param slave_adr (option) I2C-bus address (default: 0x77) */ BMP280(PinName sda, PinName sck, char slave_adr = DEFAULT_SLAVE_ADDRESS); @@ -53,7 +56,7 @@ * which is connected to specified I2C pins with specified address * * @param i2c_obj I2C object (instance) - * @param slave_adr (option) I2C-bus address (default: 0x76) + * @param slave_adr (option) I2C-bus address (default: 0x77) */ BMP280(I2C &i2c_obj, char slave_adr = DEFAULT_SLAVE_ADDRESS);