Class for using BMP180 Bosch Pressure sensor
Dependents: ILI9341_Clock_Nucleo IoT-Polytech-Upmc
BMP180.h
- Committer:
- harrypowers
- Date:
- 2013-11-26
- Revision:
- 0:b899fe37ce17
- Child:
- 1:4c6b41f1203d
File content as of revision 0:b899fe37ce17:
#ifndef BMP180_H #define BMP180_H /* BMP180 Digital Pressure Sensor Class for use with Mbed LPC1768 and other platforms * BMP180 from Bosch Sensortec * Copyright (c) 2013 Philip King Smith * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /** BMP180 Digital Pressure Sensor class using mbed's i2c class * * Example: * @code * // show how the BMP180 class works * #include "BMP180.h" * #include "mbed.h" * * Serial pc(USBTX, USBRX); // tx, rx for debug and usb pc comunications * * * @endcode */ #include "mbed.h" #define EEprom 22 // The EEPROM has 176bits of calibration data (176/8 = 22 Bytes) #define BMP180ADDR 0xEF // I2C address of BMP180 device #define BMP180FREQ 1000000 // Data sheet says 3.4 MHz is max but not sure what mbed can do here! #define CMD_READ_VALUE 0xF6 #define CMD_READ_CALIBRATION 0xAA #define OVERSAMPLING_ULTRA_LOW_POWER 0 #define OVERSAMPLING_STANDARD 1 #define OVERSAMPLING_HIGH_RESOLUTION 2 #define OVERSAMPLING_ULTRA_HIGH_RESOLUTION 3 class BMP180 { public: /** Create object connected to BMP180 pins ( remember both pins need pull up resisters) * * Ensure the pull up resistors are used on these pins. Also note there is no checking on * if you use thes pins p9, p10, p27, p28 so ensure you only use these ones on the LPC1768 device * * @param sda pin that DS1307 connected to (p9 or p28 as defined on LPC1768) * @param slc pin that DS1307 connected to (p10 or p27 ad defined on LPC1768) */ BMP180(PinName sda, PinName slc); // Constructor ~BMP180(); // Destructor int readTP(long *t, long *p, int oversample); // get both temperature and pressure fully compensated values! Note this only returns when measurements are complete int startTemperature(); // Start temperature measurement int readTemperature(long *t); // Get the temperature reading that was taken in startTemperature() but ensure 4.5 ms time has elapsed int startPressure(int oversample); // Start pressure measurement! Note oversample will vary the time to complete this measurement. See defines above for oversampling constants to use! int readPressure(long *p); // Get the pressure reading that was taken in startPressure() but ensure time for the measurement to complete protected: long x1; long x2; long x3; short ac1; short ac2; short ac3; unsigned short ac4; unsigned short ac5; unsigned short ac6; short b1; short b2; long b3; unsigned long b4; long b5; long b6; unsigned long b7; short mb; short mc; short md; int oversampling_setting; char rReg[3]; char wReg[2]; char cmd; char data[EEprom]; char w[2]; I2C bmp180i2c; // the I2C class for this bmp180 communication. //int rTemp(long *ut); // raw temperature reading. Note this returns when reading is done. //int rPressure(long *up); // raw pressure reading. Note this returns when reading is done. }; #endif