Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: BMP085 pressure and temperature readings via a 28X2

  1. #1
    Senior Member
    Join Date
    Jan 1970
    Location
    Queensland AUSTRALIA
    Posts
    116

    Smile BMP085 pressure and temperature readings via a 28X2

    This is a working solution. I am using the BMP085 to provide pressure data in a remote weather station setup.
    I have used the Q16.16 Arithmetic Module by Jeremy Leach and a paper Floating Point Calculations for the BMP085

    The readings were a little variable so I used the oversampling to reduce the noise, the BMP085 takes 8 readings and returns the less noisy result.
    The code size is 3233 bytes but on a 28X2 this is only one slot....

    I have yet to really go into the accuracy of all the trickery to make a pressure reading pop out, and I did have to apply a -6.2 hPa fudge factor at the end, but it does seems to work.


    Weather station 3G P1050182 50.JPG

    BMP085 with FractionalMaths.bas

  2. #2
    Senior Member
    Join Date
    Sep 2011
    Location
    Bath,UK
    Posts
    728

    Default

    Out of interest, I use the pressure sensor mpx4115a and get very good results, exactly the same a my Davis 6150 weather station and it tracks all of the local METAR stations exactly. I don't bother with anything less than 0.1hPa resolution. What is your altitude (from Google Earth maybe), as that will affect the calibration hence an offset of 6.2 needing to be introduced.

  3. #3
    Senior Member
    Join Date
    Jan 1970
    Location
    Queensland AUSTRALIA
    Posts
    116

    Default

    yes I do realize that sitting on floor 5 at work at about 100m above sea level will affect the reading.
    The thing that does worry me is that using the same module in a Arduino I used a +3.9 to get a reading same as met office.
    When I feed the data straight into the formulas provided, I get 1015.6 to which I add 3.9 to get 1019.5, same a met office.
    Whereas this code calculates 1026.4 to which i add -6.3 to get 1020.1
    So I need to recheck all the calculations.
    Terry

  4. #4
    Senior Member
    Join Date
    Jan 1970
    Location
    Queensland AUSTRALIA
    Posts
    116

    Default bug fix

    I found one place to increase accuracy.
    Replace the lines for calculating y0 with these.
    I was doing a 2 step
    Code:
    C4 = BMP_AC4 / 2^15 / 1000  
    y0 = C4 * s^15
    Now
    Code:
    y0 = BMP_C4/1000
    which makes more accurate value for y0


    so replace the code for calculating y0 (around lines 615-640) with the lines below

    Code:
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    'Sertxd(cr,lf,"y0 = C4 * s^15")
    'Sertxd(cr,lf,"y0 = BMP_C4/1000/2^15 * 2^15")
    'Sertxd(cr,lf,"y0 = BMP_C4/1000 ")
    'get stored result
    'Address = FPC_C4:PEEK Address, Word AMSW,Word ALSW
    
    AMSW = BMP_AC4 // 1000
    ALSW = 0    
    BMSW = 1000
    BLSW = 0
    Operator = Op_Div
    Gosub Calculate        'calculate fraction part of C4/1000
        
    'Sertxd (cr,lf," = "):GoSub DispResult
    
    RMSW = BMP_AC4 /  1000    'integer part of C4/1000
    RLSW = RLSW            'fractional part of C4/1000
    
    'save result
    Address = FPC_y0:POKE Address, Word RMSW,Word RLSW
    #IFDEF ShowDebug 
    Sertxd (cr,lf,"FPC_y0 = "):GoSub DispFullResult
    #ENDIF

  5. #5
    Senior Member
    Join Date
    Jan 1970
    Location
    Queensland AUSTRALIA
    Posts
    116

    Default Another Bug Fix

    I found that the calculations would occasionally lock up.

    One additional check is needed in the division routine.
    The second line needs to be added after the first line
    Code:
            If FLSW >= EndThreshold Then Exit 'Exit when Fn has converged to 1.
            If FLSW = 0 and FMSW=1  Then Exit 'Exit when Fn has converged to 1.

  6. #6
    Senior Member
    Join Date
    Sep 2011
    Location
    Bath,UK
    Posts
    728

    Default

    I have now been reading pressure (and temperature) from a BMP085 and note a similar offset to Simmicht, I have to add 5.8hPA to get close to the average of all the local weather stations in Pa. I have found a good article on the sparkfun webpage that explains why this is happening, but I have yet to write a routine to calcualte true altitude from the BMP085 pressure reading, I'll do that in the next few days. It's not a sensor issue, it's a conversion problem and the need to normalise the results.

    Another good source of explanations is: https://github.com/adafruit/Adafruit-BMP085-Library

    Essentially use the following: altitude = 44330 * (1-(BMP085PressureResult/TodaysAirPressureAtYourLocation)^(1/5.255))

    Using Average Sea level air pressure for 'TodaysAirPressure' does not give the correct result (real altitude), it gives it relative to sea level - confusing I know!

    e.g. Currently the local air pressure is 100815pa, the BMP085 reads 100325pa the calculated altitude is therefore 41.08M. Google maps says 40M, my GPS says 39M, so an error of 4% relative to the average of those sources, not bad.
    Last edited by g6ejd; 07-05-2012 at 22:15.

  7. #7
    New Member
    Join Date
    Apr 2012
    Location
    Netherlands
    Posts
    27

    Default

    Simmicht,
    thanks for this post on BMP085 calculus with fractional math.
    I've used / adapted it for a Pressure and Temp reader with a serial OLED/LCD unit for readout (AXE133Y).
    The following adaptations are made:
    • turned off 8x oversampling by hardware (OSS=0, or '1x' oversampling)
    • introduced 256x oversampling in software by a) accumulating 256 2-byte rawP and 256 rawT readings, b) then divide by 256, c) then do the Fractional Maths to calculate real P and T, d) then display
    • optimised P and T readings somewhat for speed by a) only doing FPC calculation at initialisation (as these don't change over time), b) clocking the 28X2 at 32MHz
    • red LED flashes when new results are displayed
    • me too, I needed a 'Fudge factor', I only need to add 0.6 hPa for my BMP085
    • rest is unchanged, some coding was visually compacted a bit

    The P and T results are displayed on the serial LCD every 3-4 seconds in resolution of 0.01 hPa and 0.01 degrees Celcius.
    I anticipated that these values would be too much and readings would go all over the place as they are quite below the speficied absolute and relative error of the BMP085 device.
    I was pleasantly surprised.
    I'm not claiming I can backup this by comparison with a laboratory test unit, but I do believe to see from the display readings an rms value of below <0.10 hPa for P and <0.05 C for T.
    For the range of 980-1040 hPa and 18-27 C.

    Attaching the .bas file for 28X2
    28X2_BMP085 with FractionalMaths 8.bas

    Next step I plan to use a 20X to read humidity with a DHT11, P and T with a BMP085 and to drive a 4x20 LCD display directly.

    Thierry

  8. #8
    New Member
    Join Date
    Apr 2012
    Location
    Netherlands
    Posts
    27

    Default

    I've now ported the BPM085 program from Terry Simmich to a 20X2, which was relatively straightforward except for the smaller RAM size compared to the 28X2, so I had to squeeze for a little bit of room.
    Plus added Humidity reading with a DHT11 unit using an external 555 timer IC, as described here:

    The code is attached.
    20X2_BMP085_DHT11_1.bas

    Next I'd like to try the same 20X2 to drive the LCD/OLED display directly rather than via SerialLCD unit, as is the case now.
    Not sure if I can reuse pins B.5 and B.7 also to directly drive an LCD as these are now also in use for I2C signals to BMP085. Anyone tried this?

    Thierry
    Last edited by ThierryP; 17-06-2012 at 10:24.

  9. #9

    Default

    Essentially use the following: altitude = 44330 * (1-(BMP085PressureResult/TodaysAirPressureAtYourLocation)^(1/5.255))


    Hi

    did you ever manage to write a routine using Q16.16 for the above equation? I am struggling breaking it down to base operators. Any help with this would be most appreciated

    Thanks

    Neil

  10. #10
    New Member
    Join Date
    Apr 2012
    Location
    Netherlands
    Posts
    27

    Default

    Neil,

    No, I've not tried that equation, as it has a fractional power.
    I did convert a similar pressure to height equation to a Taylor series or linear, quadratic or cubic approximation, which can then be done in Q16.16. E.g.
    H = a.P^3 + b.P^2 + c.P + d
    If you can give me the pressure and heights range you require and the maximum error you'd accept due to calculus approximation error, I can give it a try.

    Both should provide good results over a few km of height difference

    Thierry

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •