Library for the barometric sensors BMP180 with two-wire (also known as I2C) bus interface.
- It is compatible with sensor
BMP085. - Sensor address is
0x77hardcoded and cannot be changed by any library method. - The library provides measured temperature in degrees of Celsius and air pressure in Pascal.
- For conversion among various temperature unit scales and for calculating dew point temperature use library
gbjAppHelpers. - The sensor has temperature resolution
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 and temprature and pressure uncompensated values from the datasheet instead of real received values from the sensor. That mode serves for testing compensating 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().
In a sketch the constants can be referenced in 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 constructor of 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 methods utilizes this parameter for such as 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 methods utilizes this parameter for such as 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)
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 hardcoded in the sensor.
float measureTemperature()
None
Temperature in centigrade or erroneous value returned by getErrorValue(). The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess().
The 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.
- The final presure value is compensated with calibration data hardcoded in the sensor.
float measurePressure(float &temperature)
- temperature: Referenced variable for placing a temperature value in centigrade.
- Valid values: sensor specific
- Default value: none
Relative humidity truncated and compensated to range 0 - 100 °C or erroneous value returned by getErrorRHT().
gbj_bmp180 sensor = gbj_bmp180();
float tempValue, pressValue;
setup()
{
if (sensor.isSuccess(sensor.begin()))
{
pressValue = sensor.measurePressure(tempValue);
}
}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(uint8_t oss)
- oss: Oversampling set of pressure measurement rate. It is sanitized to the valid range.
- Valid values: non-negative integer 0 ~ 3
- Default value: none
None
The method calculates barometric pressure at sea level from provided pressure and altitude.
- The input pressure is usually just measured one by the method measurePressure(), but the method calculates in general.
- The measurement unit of the local pressure can be arbitrary. However the methods 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 one by the method measurePressure(), but the method calculates in general.
- 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 measurement unit, but the same as the first argument has.
- 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 returns virtually wrong temperature or barometric pressure value at erroneous measurement usually at failure of 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().