Class for using BMP180 Bosch Pressure sensor

Dependents:   ILI9341_Clock_Nucleo IoT-Polytech-Upmc

Committer:
harrypowers
Date:
Tue Nov 26 08:29:44 2013 +0000
Revision:
1:4c6b41f1203d
Parent:
0:b899fe37ce17
Child:
2:4749ef781396
First complete class for using BMP180 .  Need to do testing to ensure it all works and other adjustments maybe!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
harrypowers 0:b899fe37ce17 1 #ifndef BMP180_H
harrypowers 0:b899fe37ce17 2 #define BMP180_H
harrypowers 0:b899fe37ce17 3
harrypowers 0:b899fe37ce17 4 /* BMP180 Digital Pressure Sensor Class for use with Mbed LPC1768 and other platforms
harrypowers 0:b899fe37ce17 5 * BMP180 from Bosch Sensortec
harrypowers 0:b899fe37ce17 6 * Copyright (c) 2013 Philip King Smith
harrypowers 0:b899fe37ce17 7 *
harrypowers 0:b899fe37ce17 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
harrypowers 0:b899fe37ce17 9 * of this software and associated documentation files (the "Software"), to deal
harrypowers 0:b899fe37ce17 10 * in the Software without restriction, including without limitation the rights
harrypowers 0:b899fe37ce17 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
harrypowers 0:b899fe37ce17 12 * copies of the Software, and to permit persons to whom the Software is
harrypowers 0:b899fe37ce17 13 * furnished to do so, subject to the following conditions:
harrypowers 0:b899fe37ce17 14 *
harrypowers 0:b899fe37ce17 15 * The above copyright notice and this permission notice shall be included in
harrypowers 0:b899fe37ce17 16 * all copies or substantial portions of the Software.
harrypowers 0:b899fe37ce17 17 *
harrypowers 0:b899fe37ce17 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
harrypowers 0:b899fe37ce17 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
harrypowers 0:b899fe37ce17 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
harrypowers 0:b899fe37ce17 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
harrypowers 0:b899fe37ce17 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
harrypowers 0:b899fe37ce17 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
harrypowers 0:b899fe37ce17 24 * THE SOFTWARE.
harrypowers 0:b899fe37ce17 25 */
harrypowers 0:b899fe37ce17 26
harrypowers 0:b899fe37ce17 27 /** BMP180 Digital Pressure Sensor class using mbed's i2c class
harrypowers 0:b899fe37ce17 28 *
harrypowers 0:b899fe37ce17 29 * Example:
harrypowers 0:b899fe37ce17 30 * @code
harrypowers 0:b899fe37ce17 31 * // show how the BMP180 class works
harrypowers 0:b899fe37ce17 32 * #include "BMP180.h"
harrypowers 0:b899fe37ce17 33 * #include "mbed.h"
harrypowers 0:b899fe37ce17 34 *
harrypowers 0:b899fe37ce17 35 * Serial pc(USBTX, USBRX); // tx, rx for debug and usb pc comunications
harrypowers 0:b899fe37ce17 36 *
harrypowers 0:b899fe37ce17 37 *
harrypowers 0:b899fe37ce17 38 * @endcode
harrypowers 0:b899fe37ce17 39 */
harrypowers 0:b899fe37ce17 40
harrypowers 0:b899fe37ce17 41 #include "mbed.h"
harrypowers 0:b899fe37ce17 42
harrypowers 1:4c6b41f1203d 43 #define EEprom 22 // The EEPROM has 176bits of calibration data (176/8 = 22 Bytes)
harrypowers 1:4c6b41f1203d 44 #define BMP180ADDR 0xEF // I2C address of BMP180 device
harrypowers 0:b899fe37ce17 45 #define BMP180FREQ 1000000 // Data sheet says 3.4 MHz is max but not sure what mbed can do here!
harrypowers 0:b899fe37ce17 46 #define CMD_READ_VALUE 0xF6
harrypowers 0:b899fe37ce17 47 #define CMD_READ_CALIBRATION 0xAA
harrypowers 0:b899fe37ce17 48 #define OVERSAMPLING_ULTRA_LOW_POWER 0
harrypowers 0:b899fe37ce17 49 #define OVERSAMPLING_STANDARD 1
harrypowers 0:b899fe37ce17 50 #define OVERSAMPLING_HIGH_RESOLUTION 2
harrypowers 0:b899fe37ce17 51 #define OVERSAMPLING_ULTRA_HIGH_RESOLUTION 3
harrypowers 0:b899fe37ce17 52
harrypowers 0:b899fe37ce17 53 class BMP180
harrypowers 0:b899fe37ce17 54 {
harrypowers 0:b899fe37ce17 55 public:
harrypowers 0:b899fe37ce17 56 /** Create object connected to BMP180 pins ( remember both pins need pull up resisters)
harrypowers 0:b899fe37ce17 57 *
harrypowers 0:b899fe37ce17 58 * Ensure the pull up resistors are used on these pins. Also note there is no checking on
harrypowers 0:b899fe37ce17 59 * if you use thes pins p9, p10, p27, p28 so ensure you only use these ones on the LPC1768 device
harrypowers 0:b899fe37ce17 60 *
harrypowers 0:b899fe37ce17 61 * @param sda pin that DS1307 connected to (p9 or p28 as defined on LPC1768)
harrypowers 0:b899fe37ce17 62 * @param slc pin that DS1307 connected to (p10 or p27 ad defined on LPC1768)
harrypowers 0:b899fe37ce17 63 */
harrypowers 0:b899fe37ce17 64 BMP180(PinName sda, PinName slc); // Constructor
harrypowers 0:b899fe37ce17 65
harrypowers 0:b899fe37ce17 66 ~BMP180(); // Destructor
harrypowers 0:b899fe37ce17 67
harrypowers 0:b899fe37ce17 68 int readTP(long *t, long *p, int oversample); // get both temperature and pressure fully compensated values! Note this only returns when measurements are complete
harrypowers 0:b899fe37ce17 69
harrypowers 0:b899fe37ce17 70 int startTemperature(); // Start temperature measurement
harrypowers 0:b899fe37ce17 71 int readTemperature(long *t); // Get the temperature reading that was taken in startTemperature() but ensure 4.5 ms time has elapsed
harrypowers 0:b899fe37ce17 72 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!
harrypowers 0:b899fe37ce17 73 int readPressure(long *p); // Get the pressure reading that was taken in startPressure() but ensure time for the measurement to complete
harrypowers 0:b899fe37ce17 74
harrypowers 0:b899fe37ce17 75 protected:
harrypowers 0:b899fe37ce17 76 long x1;
harrypowers 0:b899fe37ce17 77 long x2;
harrypowers 0:b899fe37ce17 78 long x3;
harrypowers 0:b899fe37ce17 79 short ac1;
harrypowers 0:b899fe37ce17 80 short ac2;
harrypowers 0:b899fe37ce17 81 short ac3;
harrypowers 0:b899fe37ce17 82 unsigned short ac4;
harrypowers 0:b899fe37ce17 83 unsigned short ac5;
harrypowers 0:b899fe37ce17 84 unsigned short ac6;
harrypowers 0:b899fe37ce17 85 short b1;
harrypowers 0:b899fe37ce17 86 short b2;
harrypowers 0:b899fe37ce17 87 long b3;
harrypowers 0:b899fe37ce17 88 unsigned long b4;
harrypowers 0:b899fe37ce17 89 long b5;
harrypowers 0:b899fe37ce17 90 long b6;
harrypowers 0:b899fe37ce17 91 unsigned long b7;
harrypowers 0:b899fe37ce17 92 short mb;
harrypowers 0:b899fe37ce17 93 short mc;
harrypowers 0:b899fe37ce17 94 short md;
harrypowers 0:b899fe37ce17 95 int oversampling_setting;
harrypowers 0:b899fe37ce17 96 char rReg[3];
harrypowers 0:b899fe37ce17 97 char wReg[2];
harrypowers 0:b899fe37ce17 98 char cmd;
harrypowers 0:b899fe37ce17 99 char data[EEprom];
harrypowers 0:b899fe37ce17 100 char w[2];
harrypowers 0:b899fe37ce17 101
harrypowers 0:b899fe37ce17 102 I2C bmp180i2c; // the I2C class for this bmp180 communication.
harrypowers 1:4c6b41f1203d 103 int oversampleCheck(int oversample);
harrypowers 0:b899fe37ce17 104 };
harrypowers 0:b899fe37ce17 105
harrypowers 0:b899fe37ce17 106 #endif