Bosch BMP085 Barometer FP Pres. Cal.


Author Message
DuinoMiteMegaAn
Senior Member

Joined: 17/11/2011
Location: Australia
Posts: 231
Posted: 02:08pm 06 Mar 2012      

This sensor provides barometric pressure and temperature. It can also be used to calculate altitude. Both Sparkfun and Adafruit vendors have this precision sensor. ($20 USD) This BMP085 is an excellant choice for use in a weather station for predicting weather. I just might add it to my Outback Dot Clock project!

The BMP085 I2C 3.3v barometric sensor mates well with the MaxiMite.
The complex floating point (instead of integer math) can be easily done in MMBasic.

Below is the precision floating point "test" code I converted to MMBasic.
The I2C communicating code will be posted later after my BMP085 hardware arrives.

Ref. Doc.

2012-03-07_000021_BMP085-Calcs.pdf


'File: BMP085R1.bas
'Project: Outback Dot Clock Rev. 1.0b
'Author: Hacker - DuinoMiteMegaAndy
'Date: 3/6/2012
'App. Version: Rev. 1.0b
'MMBasic Firmware: 3.1 MaxiMite CGMMStick1
'Platform: Win XP/SP3
'===========================================================
'Bosch BMP085 Barometer Floating Point Pressure Calculations
'April 25, 2011
'===========================================================

'==========================================
' BMP085 Calibration Data - device specific
'==========================================
BMP085_AC1 = 7911
BMP085_AC2 = -934
BMP085_AC3 = -14306
BMP085_AC4 = 31567
BMP085_AC5 = 25671
BMP085_AC6 = 18974
BMP085_B1 = 5498
BMP085_B2 = 46
BMP085_MB = -32768
BMP085_MC = -11075
BMP085_MD = 2432

'===============================
'BMP085 Derived Calibration Data
'===============================

'This data remains constant for any given sensor and need not be read and
'computed every time the sensor is powered on. Once all values are computed,
'it is not necessary to retain the values of BMP085_c3, BMP085_c4, BMP085_b1.

'The first three values are only used
'in computing the final constants below and can be discarded afterwards.

BMP085_c3 = 160*2^-15*BMP085_AC3
? "BMP085_c3 = ", BMP085_c3
BMP085_c4 = 10^-3*2^-15*BMP085_AC4
? "BMP085_c4 = ", BMP085_c4
BMP085_b1 = 160^2*2^-30*BMP085_B1
? "BMP085_b1 = ", BMP085_b1

'The next four constants are used in the computation of temperature.

BMP085_c5 = 2^-15/160*BMP085_AC5
? "BMP085_c5 = ", BMP085_c5
BMP085_c6 = BMP085_AC6
? "BMP085_c6 = ", BMP085_c6
BMP085_mc = 2^11/160^2*BMP085_MC
? "BMP085_mc = ", BMP085_mc
BMP085_md = BMP085_MD/160
? "BMP085_md = ", BMP085_md

'Three second order polynomials are used to compute pressure, and they
'require another nine constants (three for each polynomial).

BMP085_x0 = BMP085_AC1
? "BMP085_x0 = ", BMP085_x0
BMP085_x1 = 160*2^-13*BMP085_AC2
? "BMP085_x1 = ", BMP085_x1
BMP085_x2 = 160^2*2^-25*BMP085_B2
? "BMP085_x2 = ", BMP085_x2

BMP085_y0 = BMP085_c4*2^15
? "BMP085_y0 = ", BMP085_y0
BMP085_y1 = BMP085_c4*BMP085_c3
? "BMP085_y1 = ", BMP085_y1
BMP085_y2 = BMP085_c4*BMP085_b1
? "BMP085_y2 = ", BMP085_y2

BMP085_p0 = (3791-8)/1600
? "BMP085_p0 = ", BMP085_p0
BMP085_p1 = 1-(7357*2^-20)
? "BMP085_p1 = ", BMP085_p1
BMP085_p2 = 3038*100*2^-36 ' This constant is wrong in the PDF !!!!
? "BMP085_p2 = ", BMP085_p2

'The coefficients above have been scaled so that the final results will be
'temperature (BMP085_T) in degrees Celsius, and pressure (BMP085_P) in millibars (a.k.a hecto-
'Pascals)

'This wraps up the calculation of floating point constants that are used for
'converting the raw, integer temperature and pressure data into degrees Celsius
'and millibars.

'================
' BMP085 Formulas
'================

'The real-time data from the BMP085 will be represented by tu for temperature
'and pu for pressure. The temperature value is just equal to the integer
'value that is read from the barometer. The pressure reading is formatted a bit
'different however; it is treated like a fixed point fraction with the radix point just
'to the right of the LSB. After these integer values are acquired, all remaining
'calculations below are floating point. These first two formulas treat the integer
'register values as unsigned quantities.

'0x69EC I2C Temperature
'BMP085_tu = 256 ·MSB + LSB
BMP085_tu = 256*&H69 + &hEC
? "BMP085_tu = ", BMP085_tu

'0x982FC0 I2C Pressure
'BMP085_pu = 256 ·MSB + LSB + XLSB/256
BMP085_pu = (256*&H98)+&H2F+(&HC0/256)
? "BMP085_pu = ", BMP085_pu

'Defining pu in this way alleviates the need to make any further adjustments
'for the over-sampling ratio (OSS). If OSS is zero, it is not necessary to read the
'XLSB register and its value can be set to zero.

'The temperature computation is quite simple. First we define a new value,
'and then compute temperature in terms of this new variable:

BMP085_a = BMP085_c5*(BMP085_tu - BMP085_c6)
BMP085_T = BMP085_a + (BMP085_mc / (BMP085_a + BMP085_md))
BMP085_Tc = BMP085_T
? "BMP085_Tc degrees C = ", BMP085_Tc

BMP085_Tf = 1.8 * BMP085_T + 32
? "BMP085_Tf degrees F = ", BMP085_Tf


'Computing pressure requires the temperature (BMP085_T) computed above, and uses
'three second-order polynomials. The first two generate offset (BMP085_x) and scaling
'factors (y) which are functions of the difference between the current temperature
'and 25C (which we’ll call BMP085_s).

BMP085_s = BMP085_T - 25
? "BMP085_s = ", BMP085_s

BMP085_x = BMP085_x2*BMP085_s^2 + BMP085_x1*BMP085_s + BMP085_x0
? "BMP085_x = ", BMP085_x

BMP085_y = BMP085_y2*BMP085_s^2 + BMP085_y1*BMP085_s + BMP085_y0
? "BMP085_y = ", BMP085_y

'These two factors are now used to compute an initial pressure value, BMP085_z:

BMP085_z = (BMP085_pu - BMP085_x) / BMP085_y
? "BMP085_z = ", BMP085_z

'A polynomial in BMP085_z gives the final corrected pressure value.

BMP085_P = BMP085_p2*BMP085_z^2 + BMP085_p1*BMP085_z + BMP085_p0
? "BMP085_P millibars = ", BMP085_P
End




Test results


BMP085_c3 = -69.8535
BMP085_c4 = 0.000963348
BMP085_b1 = 0.131083
BMP085_c5 = 0.00489635
BMP085_c6 = 18974
BMP085_mc = -886
BMP085_md = 15.2
BMP085_x0 = 7911
BMP085_x1 = -18.2422
BMP085_x2 = 0.0350952
BMP085_y0 = 31.567
BMP085_y1 = -0.0672933
BMP085_y2 = 0.000126278
BMP085_p0 = 2.36438
BMP085_p1 = 0.992984
BMP085_p2 = 4.42087e-06
BMP085_tu = 27116
BMP085_pu = 38959.8
BMP085_Tc degrees C = 23.7764
BMP085_Tf degrees F = 74.7975
BMP085_s = -1.22363
BMP085_x = 7933.37
BMP085_y = 31.6495
BMP085_z = 980.311
BMP085_P millibars = 980.045


Enjoy Edited by DuinoMiteMegaAn 2012-03-08