Library for the barometric sensors BMP180 via a two-wire (also known as I2C) bus interface.
- It is compatible with sensor
BMP085. - The sensor address,
0x77, is hard-coded and cannot be changed by any library method. - The library provides measured temperature in degrees Celsius and air pressure in Pascal.
- For conversion between various temperature units and for calculating dew point temperature use library
gbjAppHelpers. - The sensor has temperature resolution of
0.1 °Cand pressure resolution10 Pa(0.01 hPa).
- Connect microcontroller's pin
D0to sensor's pin SDA (Serial Data). - Connect microcontroller's pin
D1to sensor's pin SCL (Serial Clock).
- Connect microcontroller's pin
A4to sensor's pin SDA (Serial Data). - Connect microcontroller's pin
A5to sensor's pin SCL (Serial Clock).
- Connect microcontroller's pin
D2to sensor's pin SDA (Serial Data). - Connect microcontroller's pin
D1to sensor's pin SCL (Serial Clock).
- Particle.h: Includes alternative (C++) data type definitions.
- Arduino.h: Main include file for the Arduino SDK version greater or equal to 100.
- inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
- TwoWire: I2C system library loaded from the file
Wire.h.
- gbjTwoWire: I2C custom library loaded from the file
gbj_twowire.h, which provides common bus functionality.
- GBJ_BMP180_TEST: If this preprocessor macro is defined before including the library header file in a sketch, the library utilizes all calibration as well as temperature and pressure uncompensated values from the datasheet instead of real received values from the sensor. That mode serves for testing the compensation algorithm implemented in the library.
The library does not have specific error codes. Error codes as well as result code are inherited from the parent library gbjTwoWire only. The result code and error codes can be tested in the operational code with its method getLastResult(), isError() or isSuccess().
- Oversamplings::ULTRA_LOW_POWER_1X: Ultra low power mode.
- Oversamplings::STANDARD_RESOLUTION_2X: Standard mode.
- Oversamplings::HIGH_RESOLUTION_4X: High resolution mode.
- Oversamplings::ULTRA_HIGH_RESOLUTION_8X: Ultra high resolution mode.
In a sketch the constants can be referenced in the following forms:
- Static constant in the form
gbj_bmp180::<enumeration>::<constant>or shortlygbj_bmp180::<constant>, e.g., gbj_bmp180::ClockSpeeds::CLOCK_400KHZ or gbj_bmp180::CLOCK_400KHZ. - Instance constant in the form
<object>.<constant>, e.g., sensor.CLOCK_400KHZ.
gbj_bmp180 sensor = gbj_bmp180(sensor.CLOCK_400KHZ)- setOversamplingLow()
- setOversamplingStandard()
- setOversamplingHigh()
- setOversamplingHighUltra()
- setOversampling()
Other possible setters and getters are inherited from the parent library gbjTwoWire and described there.
The library does not need special constructor and destructor, so that the inherited ones are good enough and there is no need to define them in the library, just use it with default or specific parameters as defined at the constructor of the parent library gbjTwoWire.
- Constructor sets parameters specific to the two-wire bus in general.
- All the constructor parameters can be changed dynamically with corresponding setters later in a sketch.
gbj_bmp180(uint32_t clockSpeed, uint8_t pinSDA, uint8_t pinSCL)
-
clockSpeed: Two-wire bus clock frequency in Hertz.
- Valid values:ClockSpeeds::CLOCK_100KHZ, ClockSpeeds::CLOCK_400KHZ
- Default value: ClockSpeeds::CLOCK_100KHZ
-
pinSDA: Microcontroller's pin for serial data. It is not a board pin but GPIO number. For hardware two-wire bus platforms it is irrelevant and none of the methods utilizes this parameter for such platforms for communication on the bus. On the other hand, for those platforms the parameters might be utilized for storing some specific attribute in the class instance object.
- Valid values: positive integer
- Default value: 4 (GPIO4, D2)
-
pinSCL: Microcontroller's pin for serial clock. It is not a board pin but GPIO number. For hardware two-wire bus platforms it is irrelevant and none of the methods utilize this parameter for such platforms. On the other hand, for those platforms the parameters might be utilized for storing some specific attribute in the class instance object.
- Valid values: positive integer
- Default value: 5 (GPIO5, D1)
An object performing the sensor management. The constructor cannot return a result or error code directly, however, it stores them in the instance object.
The method has all arguments defaulted and calling without any parameters is equivalent to the calling with all arguments set by corresponding constant with default value:
gbj_bmp180 sensor = gbj_bmp180(); // It is equivalent to
gbj_bmp180 sensor = gbj_bmp180(sensor.CLOCK_100KHZ, D2, D1)The method creates class instance object and initiates two-wire bus and sensor.
ResultCodes begin()
None
Some of result or error codes.
The method resets the sensor to power-up state without need of power outage.
ResultCodes reset()
None
Some of result or error codes.
The method measures temperature only.
- The method is useful when barometric pressure is not needed.
- The final temperature value is compensated with calibration data hard-coded in the sensor.
float measureTemperature()
None
Temperature in Celsius or erroneous value returned by getErrorValue(). The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess().
The overloaded method measures barometric pressure alongside with temperature at once, because the temperature is needed for pressure compensation calculation.
- The temperature is returned through referenced input parameter if present.
- The final pressure value is compensated with calibration data hard-coded in the sensor.
float measurePressure()
float measurePressure(float &temperature)
- temperature: Referenced variable for placing a temperature value in Celsius.
- Valid values: sensor specific
- Default value: none
Pressure in Pascal or erroneous value returned by getErrorValue(). The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess(). If the method with referenced temperature parameter is called, the measured temperature is written in it.
gbj_bmp180 sensor = gbj_bmp180();
float tempValue, pressValue;
setup()
{
if (sensor.isSuccess(sensor.begin()))
{
pressValue = sensor.measurePressure(tempValue);
}
}The method measures barometric pressure only and skips a new temperature measurement.
- It uses the latest previously calculated temperature compensation value.
- The method is useful for frequent pressure sampling when temperature changes slowly.
float measurePressureOnly()
None
Pressure in Pascal or erroneous value returned by getErrorValue(). The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess().
setOversamplingLow(), setOversamplingStandard(), setOversamplingHigh(), setOversamplingHighUltra(), setOversampling()
The particular method sets corresponding oversampling rate and related conversion time period for subsequent measurement according to the data sheet.
- The oversampling rate is determined either by the suffix in a method's name or in the argument.
- The method with input argument is suitable for setting an oversampling from previous obtained value by the corresponding getter.
void setOversamplingLow()
void setOversamplingStandard()
void setOversamplingHigh()
void setOversamplingHighUltra()
void setOversampling(Oversamplings oss)
- oss: Oversampling setting of pressure measurement rate. It is limited by the data type oversamplings to the valid range.
- Valid values: Oversamplings::ULTRA_LOW_POWER_1X ~ Oversamplings::ULTRA_HIGH_RESOLUTION_8X
- Default value: none
None
The method returns a pointer to the calibration coefficients all converted to unsigned integers and number of those coefficients in its referencing argument.
- The order of the coefficients in the array is reversed in comparison to the order stated in the data sheet. It is due to MSB first in the NVM (EEPROM).
- So, the order is: MD, MC, MB, B2, B1, AC6, AC5, AC4, AC3, AC2, AC1.
uint16_t *getCalibration(uint8_t &items)
- items: Pointer (reference) to a variable receiving the number of calibration coefficients.
- Valid values: address space
- Default value: none
A pointer to the array of calibration coefficients.
uint8_t calibCnt;
uint16_t *calibTable;
gbj_bmp180 sensor = gbj_bmp180();
setup()
{
...
calibTable = sensor.getCalibration(calibCnt);
...
}The method calculates barometric pressure at sea level from provided pressure and altitude.
- The input pressure is usually just measured value by the method measurePressure(), but the method can be used for general calculations.
- The measurement unit of the local pressure can be arbitrary. The method returns the sea level pressure in the same unit.
float getPressureSea(float pressure, float altitude)
-
pressure: Local barometric pressure in arbitrary measurement unit, usually Pascal or hectoPascal.
- Valid values: decimal number
- Default value: none
-
altitude: Local altitude in meters for which the equivalent sea level pressure should be calculated.
- Valid values: decimal number
- Default value: none
Sea level barometric pressure.
The method calculates local altitude from provided local barometric pressure and corresponding sea level pressure.
- The input local pressure is usually just measured value by the method measurePressure(), but the method can be used for general calculations.
- Both input pressures should be in the same measurement unit. However that unit can be arbitrary, usually Pascal or hectoPascal.
float getAltitude(float pressure, float pressureSea)
-
pressure: Local barometric pressure in arbitrary measurement unit, usually Pascal or hectoPascal.
- Valid values: decimal number
- Default value: none
-
pressureSea: Sea level barometric pressure in arbitrary but the same as the first argument.
- Valid values: decimal number
- Default value: none
Altitude in meters.
The method provides code of currently set oversampling rate for pressure measuring.
uint8_t getOversampling()
None
Code of oversampling rate in the range 0 ~ 3.
The method provides a human-readable text label for provided oversampling mode code.
String txtOversampling(Oversamplings oss)
- oss: Oversampling mode code.
- Valid values: 0 ~ 3 represented by
Oversamplingsenumeration constants - Default value: none
- Valid values: 0 ~ 3 represented by
Text label of oversampling mode.
The method returns a dummy value of temperature or barometric pressure during an erroneous measurement usually in the event of a failure of the two-wire bus.
float getErrorValue()
None
Erroneous temperature and/or barometric pressure value. The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess().