BMP085/180 Barometer Unit

This is a new library unit for reading the BMP085 barometric pressure sensor. It should also be compatible with the newer BMP180, though I don't have one of those to confirm. Note that this unit calls upon the Software I2C library unit.

Overview


There are three commands that the calling program can use:

BMP_Init;
BMP_Temp(Celsius, Fahrenheit);
BMP_Pressure(Pascals, Station, MSLP);

The first loads in the calibration constants from the sensor which need be done only once at power-up. The next fetches the temperature, while the last gets the atmospheric pressure readings in Pascals, the station pressure in inches of mercury, and the mean sea-level pressure in inches of mercury.

BMP_Temp() should be called each time before (BMP_Pressure), since  atmospheric pressure depends upon the current temperature.

Compilation Constants


The calling program may also set the following conditional compilation constants, shown here with sample values. They're explained more fully in the source code.

{$DEFINE BMP_ALTITUDE 237}    
      // required: your altitude in meters 
{$DEFINE BMP_MODE 3}           
      // optional: oversampling mode desired
{$DEFINE BMP_FUDGE_FACTOR1 -1}
      // optional: tweak station pressure
{$DEFINE BMP_FUDGE_FACTOR2 1}
      // optional: tweak MSLP
{$DEFINE BMP_EOC_PORT 'PortA'}
      // optional: End-Of-Conversion port
{$DEFINE BMP_EOC_PIN 0}       
      // optional: its pin number

The two fudge-factors can be used to diddle the pressure to match  an existing nearby barometer, else just use the defaults  of zero. The numbers are in hundredths of an inch of mercury.

If the EOC pin on the BMP085 is not used, then fixed conversion times  are employed. They depend on the oversampling mode in play.

Finally, don't forget to set the I2C pins (required). For example,

{$DEFINE SDA_PORT 'PortB'}   // I2C SDA port
{$DEFINE SDA_PIN 0}          // and its pin number
{$DEFINE SCL_PORT 'PortB'}   // I2C SCL port
{$DEFINE SCL_PIN 1}          // and its pin number

The data direction register (TRIS) of any pins used is set automatically.

Commands


Here are the details on the commands:

procedure BMP_Init;
This should be called at power-up (reset). The calibration constants, some signed and some unsigned, are read in as 16-bit values, but promoted to 32-bits.

procedure BMP_Temp(var BMPCels, BMPFahr : integer);
Return temperature in Celsius and in Fahrenheit, in units of 0.1 degree.

procedure BMP_Pressure(var pascals : longword;  var station, mslp : integer); Fetch atmospheric pressure:

pascals  : atmospheric pressure in Pascals
station  : station pressure in hundredths of inches of mercury
mslp     : mean sea level pressure in hundredths of inches of mercury

Add It to Your Library Collection


And here's the new library unit, "BMP085_180.pas" for you to download:


Be sure to read over the source code for additional details on how to use it.

Try It Out


If you'd like to see it in operation, then head over to the exercises to try out the barometer sensor project. Click here to go to it.

No comments:

Post a Comment