Anyone used the Bosch BMP085 I2C baro sensor yet ?


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Martin

    I had a look to your excel sheet and , of course, got THE problem ...

    solution was to unlock the sheet , select the "F16" place and click on " place a formula " ( Fx button ) ...

    it automatically corrects the written formula and then it rolls fine !!!

    Are the Calibration values in the sheet those of YOUR Sensor ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Acetronics View Post
    Hi, Martin

    I had a look to your excel sheet and , of course, got THE problem ...

    solution was to unlock the sheet , select the "F16" place and click on " place a formula " ( Fx button ) ...

    it automatically corrects the written formula and then it rolls fine !!!

    Are the Calibration values in the sheet those of YOUR Sensor ???

    Alain
    Hi Alain, I suspect my friend didn't tell me that so I couldn't fiddle with his sheet

    Yes, that indeed is the calibration data out of my BMP085 sensor.

    Good news.
    Tonight I finished debugging the pressure calculations and got a correct result in Pascals. Boy it took some doing didn't it. :-)
    Tomorrow I'll tidy up the code and post the whole job after doing a little field testing.

    Now I need to find a sample of a 'good' way to do a look-up table to convert pressure to altitude without using Logs (as I understand is required)...

    Martin

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Martin

    Was an awful job to crack the sheet password I had to wait for the second attempt to get it open ...

    May be ...

    an excel sheet could easily produce the retrieve table to include in the program ???

    I already did that for a programmable electronic ignition project ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    May 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Red face Hi Martin

    Thanks for answer...
    I wonder if the calibration coefficients of BMP085 depend on something ... as either light, or are the same constants for all?
    And another thing, the uncompensated temperature varies a lot ... in the order of thousands or hundreds
    Thanks

  5. #5
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rore85 View Post
    Thanks for answer...
    I wonder if the calibration coefficients of BMP085 depend on something ... as either light, or are the same constants for all?
    And another thing, the uncompensated temperature varies a lot ... in the order of thousands or hundreds
    Thanks
    Mainly temperature dependant. I've not been able to show much sensitivity to light yet (indoors).
    Yes, the pressure reading is very 'active' so I used the maximum OSS and then 10x averaging as well. It could do with even more...

  6. #6
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default The complete opus in Longs

    Here it is. This works, and give you a corrected temperature and pressure reading from a Bosch BMP085 barometric pressure sensor.

    It requires a PIC18FXXXX MCU and use of PBPL compiler option. You'll need to change the configs for whatever PIC you choose and change the Serout2 statements to LCDOUT or whatever you want to display data on.

    The main point of this post is really to show the calculations and variable casting and manipulation required.

    Code:
    '******************************************************************************
    'MR.SNEEZY - test code for FrSky using Bosch BMP085 baro sensor.
    'This version is for PIC 18F4620 
    '
    'ADD/Do
    '
    'NOTES - 
    '
    'LAST ACTION - scratch my head...
    '
    'PIC 18F1220 port/pin alocations
    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    'PortA.0/Pin 2 = Serial TX
    'PortA.1/Pin 3 = LED
    'PortB.0/Pin 33 = I2C SCL clock
    'PortB.1/Pin 34 = I2C SDA data
     
    ' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    'Config Directive settings for MPASM (fuses) for 18F4620
     
    @    __CONFIG  _CONFIG1H, _IESO_OFF_1H & _FCMEN_OFF_1H & _OSC_INTIO7_1H
    @    __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L 
    @    __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    @    __CONFIG  _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H
    @    __CONFIG  _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVREN_OFF_4L & _XINST_OFF_4L
    @    __CONFIG  _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
    @    __CONFIG  _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @    __CONFIG  _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
    @    __CONFIG  _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    @    __CONFIG  _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
    @    __CONFIG  _CONFIG7H, _EBTRB_OFF_7H   
     
        DEFINE OSC 8 '8Mhz clock used.
         
    ' Define some constants if needed
            
    ' Software Defines (variables and pins)
        Cal_table   var word[11]         '11 word array to store calibration data
        lUpres      var long             'Long variable for Uncompensated Pressure
        lPres       var Long             'Long variable for Compensated Pressure
        lTemp_Var1  Var long             'Long temporary variable
        X1          var Long
        X2          var Long
        X3          var Long
        B3          var long
        B4          var long
        B5          var long
        B6          var Long
        B7          var long
        
        lAC1        var Long            'Long variables for cal values actually negative in my sensor
        lAC2        var long            'These are 'cast' from the Word vars into Long vars in code below
        lAC3        var Long 
        lAC4        var Long 
        lMB         var Long
        lMC         var Long
     
        bTemp_Var1  var byte             'Byte temp variable 
        wTemp_Var1  var Word	         'Word temp variable
        wTemp_Var2  var word             'Word temp variable
        lUTemp      var long             'Uncompensated temperature reading from sensor
        lCTemp      var Long             'Compensated (real) temperature x10 (1/10th of C) from sensor
        i2c_Reg     var Byte             'variable for target i2c register address
    
        CPIN        var     PortB.0       ' I2C clock pin 
        DPIN        var     PortB.1       ' I2C data pin
        SO          Var     PortA.0       'Serial out pin
        LED         var     PortA.1       'Indicator LED, via 500ohm to +3.3V
        
        OSS         con     $3          'This value is the Over Sampling Setting for the BMP085
                                        '0 = minimum, 3 = maximum. Also change value in Read_pres if you alter OSS 
    
    'Alias's for calibration data in the sensor to match the Bosch parameter list names
        AC1     var     Cal_table[0]        '
        AC2     var     Cal_table[1]        'BMP085 has 11 16bit values stored in EEPROM
        AC3     var     Cal_table[2]        'First byte is at $AA last at $BF, two bytes per cal value
        AC4     var     Cal_table[3]        'Lowbyte is MSB (e.g $AA), Highbyte is LSB (e.g. $AB)
        AC5     var     Cal_table[4]        '
        AC6     var     Cal_table[5]    
        B1      var     Cal_table[6]        'Warning - AC4, AC5, AC6 are UNSIGNED values, the rest are SIGNED
        B2      var     Cal_table[7]
        MB      var     Cal_table[8]
        MC      var     Cal_table[9]    
        MD      var     Cal_table[10]    
        
    ' Initialise Processor - check for each PIC type 
    ' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        ADCON1 = %00001111              'Turn off all AD's     
    '    OSCCON =  %01100111     'set INTRC to 4 MHZ    
        OSCCON = %01110111     'set INTRC to 8 MHZ
    '    OSCTUNE = 0                      'OSC trim set to Null 
    
    ' Set initial state of port pins as Input or Output if needed
    '    TRISA = %11111100    'Input(0 = output, 1 = Input)
    '    TRISB = %11111100    '
    '    TRISC = %11111111
    '    TRISD = %11111110
    '    TRISE = %11111111
        
    ' PIC initialization code
    '        Low So      'Start low, or you get rubbish on the LCD at PIC boot up.
            Gosub Alive                             'Go prove the PIC is running via LED
                       
            Serout2 SO,16780,[$FE,$01]               ' Clear LCD & home LCD cursor.
            pause 10                                 ' wait for LCD to catch up
            Serout2 SO,16780,["   FrSky Vario    "]  ' Serial print 
            Serout2 SO,16780,[$FE,$C0]               ' Shift cursor to line2
            Serout2 SO,16780,[" Development Jig  "]  ' Serial print 
            Pause   2000
            
            i2c_Reg =$AA                            'Start address of the BMP085 calibration data
            I2CREAD DPIN,CPIN,$EF,I2C_REG,[STR Cal_table\11],cal_error  'Read 11 reversed words out of sensor
    
            AC1 = (AC1.lowbyte<<8) + AC1.highbyte   'swap MSB and LSB of each to use in PBP (un-reverse then)    
            AC2 = (AC2.lowbyte<<8) + AC2.highbyte   'device stores the MSB in the Low byte, LSB in the High byte
            AC3 = (AC3.lowbyte<<8) + AC3.highbyte   
            AC4 = (AC4.lowbyte<<8) + AC4.highbyte          
            AC5 = (AC5.lowbyte<<8) + AC5.highbyte
            AC6 = (AC6.lowbyte<<8) + AC6.highbyte
            B1 = (B1.lowbyte<<8) + B1.highbyte
            B2 = (B2.lowbyte<<8) + B2.highbyte
            MB = (MB.lowbyte<<8) + MB.highbyte
            MC = (MC.lowbyte<<8) + MC.highbyte
            MD = (MD.lowbyte<<8) + MD.highbyte 
    
    'Cast (convert) signed PBP Word vars to signed PBP Long vars where needed by math routines below
            lAC1 = AC1                           'copy word to long   
            if AC1.15 then lAC1.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true 
    
            lAC2 = AC2                           'copy word to long   
            if AC2.15 then lAC2.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true 
    
            lAC3 = AC3                           'copy word to long
            if AC3.15 then lAC3.HIGHWORD = $FFFF 'Check for negative, set top 16bits to all 1's if true
    
            lMB = MB                            'copy word to long
            if MB.15 then lMB.HIGHWORD = $FFFF  'Check for negative, set top 16bits to all 1's if true
    
            lMC = MC                            'copy word to long
            if MC.15 then lMC.HIGHWORD = $FFFF  'Check for negative, set top 16bits to all 1's if true
    
    'Cast (convert) UN-signed PBP Word var to UN-signed PBP Long var for math routines below
            lAC4 = AC4                          'copy word to long, both unsigned
                                    
            Serout2 SO,16780,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10                              ' wait for LCD to catch up
    
    'Main loop -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Main:  
            Serout2 SO,16780,[$FE,$02]             'home LCD cursor, LCD not cleared.                           
             
            Gosub Read_temp                        'get Temp via I2C
            
            Serout2 SO,16780,["UT=",SDEC lUtemp," "]       'Send Word size number to LCD
            
            lTemp_Var1 = 0                          'Clear the last pressure reading
            For bTemp_Var1 = 0 to 9                 'Start of 10x averaging routine
            Gosub Read_pres                         'get Long uncompensated pressure via I2C
            lTemp_Var1 = lTemp_Var1 + lUpres
            Next bTemp_Var1
            lUpres = lTemp_Var1 / 10                'finish of the 10x Averaging routine   
    
            Serout2 SO,16780,["UP=",SDEC lUpres," "]       'Send Word size number to LCD
    
    'Calculate temperature in 1/10ths of Deg C  from lUTemp     ' Note 2^15 = 32768 Dec or $8000
            X1 = ((lUtemp - AC6) * AC5) / $8000     'find X1. 
            X2 = (lMC * $800) / (X1 + MD)           'Find X2.  Note:- math rounding results in X2 being in error by 1 ?
            B5 =  X1 + X2                           'Find B5 from X1 and X2.
            lCTemp = (B5 + 8) / 16                  'Hey presto, lCTemp appears... 
    
    'DISPLAY true temperature in C 
            X1 = lCTemp / 10                         'find value above decimal point
            Serout2 SO,16780,[$FE,$C0]               ' Shift cursor to line_2
            Serout2 SO,16780,["Temp= ",DEC X1,"."]   'Send Word size number to LCD        
            X1 = lCTemp // 10                        'Find decimal value
            Serout2 SO,16780,[DEC X1,"  "]           'Send Word size number to LCD 
             
    'Calculate pressure in Pascals from uncompensated pressure lUpres (1/100th's of hPa's)        
            B6 = b5 - 4000
    
            x1 = (b2 * (B6 * B6 / $1000)) / $800 
            x2 = (lac2 * B6) / $800
            x3 = x1 + x2
            B3 = ((lac1 * 4 + x3) << OSS + 2) / 4     'OSS = Over Sampling constant set above  
     
            x1 = (lac3 * b6) / $2000
            x2 = (b1 * (b6 * b6 / $1000)) / $10000
            x3 = ((x1 + x2) + 2) / 4
            B4 = (lac4 * (x3 + 32768)) / $8000        'Find B4, note lAC4 is an unsigned Long
    
            B7 = (lUPres - B3) * (50000 >> OSS)       'OSS = Over Sampling constant set above
     
            If B7 < $80000000 then                    'branch if value is above or below range
                lPres = (B7 * 2) / B4
                Else
                lPres = (B7 / B4) * 2
            Endif
    
            X1 = (lPres / 256) * (lPres / 256)
            X1 = (X1 * 3038) / $10000                 '$10000 = 2^16
            X2 = (-7357 * lPres) / $10000
            lPres = lPres + (X1 + X2 + 3791) / 16     'lPres is the true pressure in Pa
    
    'DISPLAY true pressure in hPa
            X1 = lPres / 100                          'find value above decimal point
            Serout2 SO,16780,[$FE,$94]                'Shift cursor to line_3   
            Serout2 SO,16780,["hPa= ",DEC X1,"."]     'Send Word size number to LCD        
            X1 = lPres // 100                         'find value below decimal point
            Serout2 SO,16780,[DEC X1,"  "]            'Send Word size number to LCD         
    
            pause 1000
            Toggle LED                                'flash the 'im alive' LED
            Goto main
            
    'SUBROUTINES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-      
    Read_pres: 
            i2c_Reg = $F4                               '$F4 is the control register address
            I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$F4]        ' Write $34+(oss << 6) to set pressure conversion 
            Pause 30                                    ' Delay 10ms after each write (30mS for HiRes results (oss=3))
            i2c_Reg = $F6                               '$F6 is the result register MSB
            I2CREAD DPIN,CPIN,$EF,I2C_REG,[lUpres],I2C_error  'Read pressure MSB, LSB, XLSB, $F9 ($F9 not actually wanted).
            lUpres = lUpres >> (16 - oss)               'remove $F9 from result (>>8), and left shift result back to 16 to 19 Bits (OSS value dependant)
                                                        'it's because PBP reads four bytes if [Var] is a long...
            return                                      'we only want top 19bits of the result.
                  
    Read_temp:
            i2c_Reg = $F4                               '$F4 is the control register address
            I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$2E]        ' Write $2E to set temperature conversion 
            Pause 10                                    ' Delay 10ms after each write
            i2c_Reg = $F6                               '$F6 is the result register MSB
            I2CREAD DPIN,CPIN,$EF,I2C_REG,[wTemp_Var1],I2C_error  'Read temperature MSB, LSB.
            lUTemp = wTemp_Var1                          'copy word to long. Note BMP085 UT is NOT a signed value   
            return
    
    'Prove it's alive
    Alive:
            High LED                                     'flash LED routine
            For btemp_var1 = 10 to 110 step 10
            Low LED
            Pause bTemp_Var1
            High LED
            Pause bTemp_Var1
            Next bTemp_Var1
            
            Return
    
    'trap and display I2C problems        
    I2C_error:     
            Serout2 SO,16780,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10                              ' wait for LCD to catch up
            Serout2 SO,16780,["i2c bus read error"]       'no ACK from I2C device        
            pause 2000        
            Toggle LED
            Goto main
             
    Cal_error:
            Serout2 SO,16780,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10 
            Serout2 SO,16780,["i2c cal read error "]       '        
            
    End

  7. #7
    Join Date
    May 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Problems with decimal point

    Quote Originally Posted by rore85 View Post
    Thanks for answer...
    I wonder if the calibration coefficients of BMP085 depend on something ... as either light, or are the same constants for all?
    And another thing, the uncompensated temperature varies a lot ... in the order of thousands or hundreds
    Thanks
    Hi everybody...
    The program in assembler works but I have problems generated in a division ratio, ie, it is rounded to an integer and the final value of the temperature goes too far in the real value, almost 80 degrees more ...
    Someone had the same problem?
    Thanks in advance!

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Here are some multi byte division functions for assembly: http://avtanski.net/projects/math/

  9. #9
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Martin

    Was an awful job to crack the sheet password I had to wait for the second attempt to get it open ...

    May be ...

    an excel sheet could easily produce the retrieve table to include in the program ???

    I already did that for a programmable electronic ignition project ...

    Alain
    Yes, I guess it could be done that way. I wonder how much data in the table is just enough, that might be hard to workout ?
    Yes the sensor would be mated by the table to one PIC for life, and make it impossible to give the HEX file to anyone else to use for an open project (if they can't use PBP). Unless the table can be forced into a known place in code space perhaps... Messy at the very least.

  10. #10
    Join Date
    Aug 2010
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Compile problems

    Hi Martin-
    Thanks for sharing the Bosch code with us- some undertaking.
    I'm just about to start a small project that could use this device and thought I'd just check I can compile it correctly using your posted code for the 18F4620 before proceeding further.

    Unfortunately I'm getting compile errors ("overwriting previous address contents 0000 to 0007 locations") and just wondering if you could give me the versions of Microstudio and PBP you are running- I'm running Microstudio 3.0.0.5 and PBP 2.50L (with the pbpl box checked!)
    Thanks for your time.
    Edward

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You need to set the configs correctly
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Aug 2010
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Thanks- all ok now.

  13. #13
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by eab123 View Post
    just wondering if you could give me the versions of Microstudio and PBP you are running- I'm running Microstudio 3.0.0.5 and PBP 2.50L (with the pbpl box checked!)
    Thanks for your time.
    Edward
    PBP 2.60 and MCS 4.0.0.0

    Martin
    PS. If you do something interesting with the code please let us in on it :-)

  14. #14
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: Anyone used the Bosch BMP085 I2C baro sensor yet ?

    Hello,

    I was wondering if someone did make a piece of PB code for converting the pressure to altitude?

    I'm far too bad in maths......
    Roger

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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