Anyone used the Bosch BMP085 I2C baro sensor yet ?


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Well I've spent a few hours working on this over the weekend, and I've made good progress (for me) with communicating with the sensor. I have a PIC Serial LCD (20x4) attached to a PIC12F683, which has the BMP085 attached to GPIO.0 (clock) and GPIO.1(data).

    So far I can see the inbuilt temperature sensor value changing when I put a warm finger on the sensor, and also read out the eleven 16bit calibration parameters and display them (I think).

    I'm worried about two things.
    One is if I have the MSB and LSB of the calibration data in the right order when I'm storing them and then again using them. I not convinced the numbers look right on the LCD. The PBP manual I find confuses me somewhat when they talk about storing the LSB first in a word sized array of the i2c device (i2cread command description).

    The second is converting this math to PBP, given that the values of some seem to be signed and results of some operations are going to be 32bit size (unless I don't understand it at all, which is possible).
    To convert the raw temperature result UT to Deg C (T) is
    X1 = (UT - AC6) * AC5 / 2^15
    X2 = MC * 2^11 / (X1 + MD)
    B5 = X1 + X2
    T = (B5 + 8) / 2^4

    I'd love some help with some code to show how this can be done in PBP.
    Anybody ?

    Cheers,
    Martin

    Code:
    'PIC 12F683 port/pin allocations
    '-------------------------------
    'GPIO.0/Pin 7 = I2C SCL clock
    'GPIO.1/Pin 6 = I2C SDA data
    'GPIO.2/Pin 5 = spare
    'GPIO.3/Pin 4 = spare
    'GPIO.4/Pin 3 = LED
    'GPIO.5/Pin 2 = Serial TX
    
    '-----------------------
    ' PIC Defines
    ' ===========
    'Config bits set to INTERNAL OSC, Watch dog ON, Power up timer ON, Master Clear NOT used, BrownOut protection ON, 
    @ Device  pic12f683, intrc_osc, wdt_on, pwrt_on, mclr_off, bod_on ;Config switches, different from PBP default
    '@ __Config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF   ;USING MPASM ONLY
    
        Define Osc 4 '4Mhz clock used. Note - Set PIC config fuses on programmer to use Internal RC OSC
        
        Include "modedefs.bas"          ' Include serial modes
    
    ' Define some constants if needed
            
    ' Software Defines
        Cal_table   var word[11]         '11 word array to store calibration data
        Temp_Var    var byte             'temp variable 
        Temp_Var2   var Word	         'temp variable 
        i2c_Reg     var Byte             'variable for target i2c register address
        
        CPIN        var     GPIO.0       ' I2C clock pin 
        DPIN        var     GPIO.1       ' I2C data pin
        SO          Var     GPIO.5        'Serial out pin
        LED         var     GPIO.4        'Indicator LED, via 500ohm to +3.3V
        
    'Alias's for calibration data in the sensor to match the Bosch paramater 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
        AC4     var     Cal_table[3]     'Lowbyte is MSB, Highbyte is LSB
        AC5     var     Cal_table[4]     'some values are signed (not AC4, AC5, AC6)
        AC6     var     Cal_table[5]    
        B1      var     Cal_table[6]
        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 either 12F629 or 12F675
    ' --------------------
        VRCON.7 = %0    'Comparator voltage reference OFF
        CMCON0 = %111   'Comparator inputs to OFF, all pins normal I/O
        ANSEL = 0       'Turn off al AD's     rem out for PIC12F629, use for PIC12F675
    
    ' Set initial state of GPIO port pins as Input or Output
    
        TRISIO.0 = 0    'Input(0 = output, 1 = Input)
        TRISIO.1 = 0    '
        TRISIO.2 = 1    '
        TRISIO.3 = 0    '
        TRISIO.4 = 0    '
        TRISIO.5 = 1    '
    
    ' PIC initialization code
    
            Low LED     'LED on
            pause 500
            High LED    'LED off
     
            Serout SO,N2400,[$FE,$01]               ' Clear LCD & home LCD cursor.
            pause 10                                ' wait for LCD to catch up
            Serout SO,N2400,["   FrSky Vario    "]  ' Serial print 
            Serout SO,N2400,[$FE,$C0]               ' Shift cursor to line2
            Serout SO,N2400,[" development jig  "]  ' Serial print 
            Pause 3000
            
            i2c_Reg =$AA                            'Start address of calibration data
            I2CREAD DPIN,CPIN,$EF,I2C_REG,[STR Cal_table\11],read_error1  'Read 11 words out of sensor
            Serout SO,N2400,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10                              ' wait for LCD to catch up
    Main:  
            Serout SO,N2400,[$FE,$02]             'home LCD cursor.                           
                    
            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,[Temp_Var2],read_error  'Read temperature MSB, LSB.
    
            Serout SO,N2400,[#Temp_Var2," "]       'Send Word size number to LCD
    
    'lets see whats in the cal data array for a checking math   
            Serout SO,N2400,[$FE,$C0]               ' Shift cursor to line2
            Serout SO,N2400,[#AC1," ",#AC2," ",#AC3]
            Serout SO,N2400,[$FE,$94]               ' Shift cursor to line3
            Serout SO,N2400,[#AC4," ",#AC5," ",#AC6]
            Serout SO,N2400,[$FE,$D4]
            Serout SO,N2400,[#B1," ",#B2," ",#MB]
    '        ," ",#MC," ",#MD]                  '
            pause 1000
            Toggle LED
            Goto main
            
    Read_error:
            Serout SO,N2400,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10                              ' wait for LCD to catch up
            Serout SO,N2400,["i2c bus read error"]       '        
            pause 250        
           
            Toggle LED
            Goto main
             
    Read_error1:
            Serout SO,N2400,[$FE,$01]             ' Clear LCD & home LCD cursor. 
            Pause 10 
            Serout SO,N2400,["i2c cal read error "]       '        
            
    End

  2. #2
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Real values.
    If there happens to be a mathematician amongst us that likes puzzles like the one above, I have the raw values (as decimal) read out of my sensor to plug into the temperature equations as a test. The result should be around 21C.

    UT = 30814
    AC5 = 22882
    AC6 = 1368
    MC = 48596
    MD = 32777

  3. #3
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mr.sneezy View Post
    UT = 30814
    AC5 = 22882
    AC6 = 1368
    MC = 48596
    MD = 32777
    MC = -15828
    MD = -9

    A friend helped me use MS Excel to test the results I got out above. I missed that MC and MD are signed.
    If MC is now -15828 and MD is now -9 then I get a result of T= 214 (+21.4C) in my lounge room...
    So that would mean the MSB & LSB read out of the array IS the correct way around in my PIC code.
    Last edited by mr.sneezy; - 11th May 2010 at 05:40.

  4. #4
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Ignore the cr@p I posted above. I thought I had it worked out but noooo.

    PS. I hate the way you can't edit the post for more than a hour or so after putting up some info. What's with that anyway ?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mr.sneezy View Post
    PS. I hate the way you can't edit the post for more than a hour or so after putting up some info. What's with that anyway ?
    Edits to post do not trigger a notification to those following a thread.

    If edits were allowed to far back the whole context of the thread could be changed or useful information lost.

    So there is really no reason to allow edits for more than a few minutes to correct spelling, grammar, or typos in general.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default Barking at the hardest tree ?

    No the title is right....

    I've just done some reading at Melabs about Longs in the recent versions of PBP and how they work with 18F series PIC's. I now think I may be doing sensor this the hard way with trying to use a 12F or 16F PIC.

    A broad question: If the math involved in using this sensor only uses Longs and no floating point, can I use a 18FXXXX PIC to crunch the signed math, or is there a likely newbie Longs trap to fall into ?

    I'd copy/paste the data sheets equations here to show you, but it's copy/paste protected. I'll attach it as a file.
    It's only the last conversion from pressure to altitude that seems to use a float, and I can worry about that when I get that far (I hope). Page 12 is the guts of it.
    Attached Images Attached Images

  7. #7


    Did you find this post helpful? Yes | No

    Default LONGs with the Bosch sensor

    I have read the Bosch datasheet which is very similar to the Intersema MS5540 family. With the exception of absolute altitude, LONGs and a PIC18F part will handle those formulae easily.

    The mathematical gymnastics of handling the Bosch 19 bit variables with 16 bit PBP will consume much code space thus ruling out the 12F series. You will get it into a 16F part on code space grounds but you will have to invent your own way to extend WORD variables up to 19 bits. Why bother?

    The 18F series costs hardly any more, at least at hobby volumes, so cut your losses and go for a PIC18F part and take advantage of LONGs. This will automatically take care of negative temperatures which your altimeter will certainly need.

    Absolute Altitude needs LOG functions to handle the power 1/5.255 so avoid that by using a lookup table which you can make as accurate as you want by adjusting the size of the table and the interpolation method.

    HTH
    BrianT
    Last edited by BrianT; - 19th May 2010 at 01:31. Reason: math error

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