Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbj_bmp180

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 °C and pressure resolution 10 Pa (0.01 hPa).

Particle hardware configuration

  • Connect microcontroller's pin D0 to sensor's pin SDA (Serial Data).
  • Connect microcontroller's pin D1 to sensor's pin SCL (Serial Clock).

Arduino UNO hardware configuration

  • Connect microcontroller's pin A4 to sensor's pin SDA (Serial Data).
  • Connect microcontroller's pin A5 to sensor's pin SCL (Serial Clock).

Espressif - ESP8266, ESP32 default hardware configuration

  • Connect microcontroller's pin D2 to sensor's pin SDA (Serial Data).
  • Connect microcontroller's pin D1 to sensor's pin SCL (Serial Clock).

Dependency

Particle platform

  • Particle.h: Includes alternative (C++) data type definitions.

Arduino platform

  • 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.

Custom Libraries

  • gbjTwoWire: I2C custom library loaded from the file gbj_twowire.h, which provides common bus functionality.

Constants

  • 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().

Custom enumerations

Oversampling settings codes

  • 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.

Referencing constants and enumerations

In a sketch the constants can be referenced in the following forms:

  • Static constant in the form gbj_bmp180::<enumeration>::<constant> or shortly gbj_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)

Interface

Main

Setters

Getters

Other possible setters and getters are inherited from the parent library gbjTwoWire and described there.

gbj_bmp180()

Description

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.

Syntax

gbj_bmp180(uint32_t clockSpeed, uint8_t pinSDA, uint8_t pinSCL)

Parameters

  • 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)

Returns

An object performing the sensor management. The constructor cannot return a result or error code directly, however, it stores them in the instance object.

Example

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)

Back to interface

begin()

Description

The method creates class instance object and initiates two-wire bus and sensor.

Syntax

ResultCodes begin()

Parameters

None

Returns

Some of result or error codes.

Back to interface

reset()

Description

The method resets the sensor to power-up state without need of power outage.

Syntax

ResultCodes reset()

Parameters

None

Returns

Some of result or error codes.

Back to interface

measureTemperature()

Description

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.

Syntax

float measureTemperature()

Parameters

None

Returns

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().

See also

measurePressure()

Back to interface

measurePressure()

Description

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.

Syntax

float measurePressure()
float measurePressure(float &temperature)

Parameters

  • temperature: Referenced variable for placing a temperature value in Celsius.
    • Valid values: sensor specific
    • Default value: none

Returns

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.

Example

gbj_bmp180 sensor = gbj_bmp180();
float tempValue, pressValue;
setup()
{
  if (sensor.isSuccess(sensor.begin()))
  {
    pressValue = sensor.measurePressure(tempValue);
  }
}

See also

measureTemperature()

Back to interface

measurePressureOnly()

Description

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.

Syntax

float measurePressureOnly()

Parameters

None

Returns

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().

See also

measureTemperature()

measurePressure()

Back to interface

setOversamplingLow(), setOversamplingStandard(), setOversamplingHigh(), setOversamplingHighUltra(), setOversampling()

Description

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.

Syntax

void setOversamplingLow()
void setOversamplingStandard()
void setOversamplingHigh()
void setOversamplingHighUltra()
void setOversampling(Oversamplings oss)

Parameters

  • 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

Returns

None

See also

getOversampling()

Back to interface

getCalibration()

Description

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.

Syntax

uint16_t *getCalibration(uint8_t &items)

Parameters

  • items: Pointer (reference) to a variable receiving the number of calibration coefficients.
    • Valid values: address space
    • Default value: none

Returns

A pointer to the array of calibration coefficients.

Example

uint8_t calibCnt;
uint16_t *calibTable;
gbj_bmp180 sensor = gbj_bmp180();
setup()
{
  ...
  calibTable = sensor.getCalibration(calibCnt);
  ...
}

Back to interface

getPressureSea()

Description

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.

Syntax

float getPressureSea(float pressure, float altitude)

Parameters

  • 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

Returns

Sea level barometric pressure.

See also

getAltitude()

Back to interface

getAltitude()

Description

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.

Syntax

float getAltitude(float pressure, float pressureSea)

Parameters

  • 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

Returns

Altitude in meters.

See also

getPressureSea()

Back to interface

getOversampling()

Description

The method provides code of currently set oversampling rate for pressure measuring.

Syntax

uint8_t getOversampling()

Parameters

None

Returns

Code of oversampling rate in the range 0 ~ 3.

See also

setOversampling()

Back to interface

txtOversampling()

Description

The method provides a human-readable text label for provided oversampling mode code.

Syntax

String txtOversampling(Oversamplings oss)

Parameters

  • oss: Oversampling mode code.
    • Valid values: 0 ~ 3 represented by Oversamplings enumeration constants
    • Default value: none

Returns

Text label of oversampling mode.

See also

getOversampling()

setOversampling()

Back to interface

getErrorValue()

Description

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.

Syntax

float getErrorValue()

Parameters

None

Returns

Erroneous temperature and/or barometric pressure value. The error code can be tested in the operational code with the method getLastResult(), isError(), or isSuccess().

See also

measureTemperature()

measurePressure()

Back to interface

About

Library for the temperature and barometric pressure sensors BMP180 communicating on two-wire (I2C) bus.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages