18m2+ BMP085

ken1991

New Member
Hello

I have been looking at the Barometric sensor BMP085 and 18m2+

I have viewed "BillBWann 09-11-2012 " work on BMP085 (ok on my pc via Sertxd)

and have converted some of the code to work on lcd display except UP to Pressure ?


Also I am not good at maths and the Bosch short, Unsigned long and long leaves me stumped ?


any help would be appreciated :)
 

ken1991

New Member
http://www.picaxeforum.co.uk/showthread.php?21794-I2C-with-realtime-clock-DS1307-and-Barometric-Pressure-Sensor-BMP085&highlight=billbwann

Code:
#rem
Reads the BMP085 breakout board and converts the readings to temperature & pressure.  The raw value of UT & UP are also displayed (order UT,T,UP,P).
#endrem


#terminal 4800
#picaxe 18m2
#no_data


hi2csetup i2cmaster, %11101110, i2cslow_8, i2cbyte  ; set up bmp085 i2c device
pause 100

'hi2cin $AA,(b3,b2) : sertxd("AA=",#w1,cr,lf)

lp:
'w1=23153    'ac6  -----------------------------------------------------
hi2cin $B4,(b3,b2)
pause 10
'w2=27898    'ut  -----------------------------------------------------
hi2cout $F4,($2E)
pause 50
hi2cin $F6,(b5,b4)
pause 10
'w2=24730    '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sertxd(#w2,", ")
'w3=32757    'ac5  -----------------------------------------------------
hi2cin $B2,(b7,b6)
pause 10
w4=w2-w1*2**w3
'sertxd("X1=",#w4,cr,lf)

'w1=-8711    'mc  -----------------------------------------------------
hi2cin $BC,(b3,b2)
pause 10
if w1>32768 then: w1=0-w1: endif

'w2=2868    'md --------------------------------------------------------
hi2cin $BE,(b5,b4)    '2432
pause 10

w2=w4+w2    '(x1+MD)
w3=w1/w2
for b0=1 to 11
    w3=w3*2
    w1=w1//w2*2
    w3=w1/w2+w3
next b0
'w3=w3+1/2    'round up last digit
'w1=-8711    'mc  -----------------------------------------------------
hi2cin $BC,(b3,b2)
pause 10
if w1>32768 then: w3=0-w3: endif
'sertxd("X2=",#w3,cr,lf)

w2=w3+w4
'sertxd("b5=",#w2,cr,lf)

w1=w2+8/16
sertxd(#w1,", ")
' --------------------------------------------
w3=w2-4000
'sertxd("b6=",#w3,cr,lf)

w5=w3
if w5>32768 then: w5=0-w5: endif
w5=w5*4
w5=w5**w5
w5=w5*4
'w6=4    'b2 ------------------------------------------------------------
hi2cin $B8,(b13,b12)
pause 10
w5=8*w6**w5
'sertxd("X1=",#w5,cr,lf)

'w4=-72    'ac2 ---------------------------------------------------------
hi2cin $AC,(b9,b8)
pause 10
w7=w4
if w4>32768 then: w7=0-w7: endif
w6=w3
if w6>32768 then: w6=0-w6: endif
w7=w7*8
w6=4*w6**w7
if w4<32768 or w3<32768 then: w6=0-w6: endif    'if either is positive then negate
'sertxd("X2=",#w6,cr,lf)

w7=w5+w6
'sertxd("X3=",#w7,cr,lf)

'w8=408    'ac1 ----------------------------------------------------------
hi2cin $AA,(b17,b16)
pause 10
w8=w8*4+w5+w6+2/4
'sertxd("B3=",#w8,cr,lf)

'w9=-14383    'ac3 ------------------------------------------------------
hi2cin $AE,(b19,b18)
pause 10
w9=0-w9    'assumes that this will always be negative
w10=w3
if w10>32768 then: w10=0-w10: endif
w5=w10*8**w9
'sertxd("X1=",#w5,cr,lf)

w9=w10*4
'w10=6190    'b1 ------------------------------------------------------------
hi2cin $B6,(b21,b20)
pause 10
w6=w9**w9**w10
'sertxd("X2=",#w6,cr,lf)

w7=w5+w6+2/4
'sertxd("X3=",#w7,cr,lf)

'w10=32741    'ac4 -------------------------------------------------------------
hi2cin $B0,(b21,b20)
pause 10
w9=32768+w7
w11=w9**w10
w10=w9*w10
w9=w11*2
w10=w10/32768
w9=w9+w10
'sertxd("B4=",#w9,cr,lf)

'w10=23843    'UP ----------------------------------------------------------------

'24730    213    40204    95329

hi2cout $F4,($F4)
pause 100
hi2cin $F6,(b21,b20)
pause 10
sertxd(#w10,", ")
'w10=40204    '++++++++++++++++++++++++++++++++++++++++++++++++++++++
w10=w10-w8
w8=w10**50000    'high word of B7
w7=w10*50000    'low word of B7
'sertxd("B7=",#w8," : ",#w7,cr,lf)

if w9>32768 then    'need to be able to double the divisor so halve it now
    w9=w9/2
    b1=1
else
    if w8<32768 then    'if can double B7 now, can maintain a higher accuracy
        b1=1
        w8=w8*2
        if w7<32768 then
            w7=w7*2
        else
            w7=w7*2
            w8=w8+1
        endif
    else
        b1=0    'remember that doubling hasn't happened so do it later
    endif
endif

'w2 will be the LS word of p, w3 will be the MS word
w3=0
w2=w8/w9
for b0=1 to 16
'sertxd ("B7/ ",#w8,", ",#w7,", ",#w3,", ",#w2,cr,lf)
    w3=w3*2
    if w2>32768 then: w3=w3+1: endif
    w2=w2*2
    w8=w8//w9*2
    if w7>32767 then: w8=w8+1: endif
    w7=w7*2
    w2=w8/w9+w2
next b0
'sertxd ("B7/ ",#w8,", ",#w7,", ",#w3,", ",#w2,cr,lf)

if b1=0 then
    w3=w3*2
    if w2<32768 then
        w2=w2*2
    else
        w2=w2*2
        w3=w3+1
    endif
endif

'sertxd("p=",#w3," : ",#w2,cr,lf)

b9=b6
b8=b5
w5=w4**w4
w4=w4*w4
'sertxd("X1=",#w5," : ",#w4,cr,lf)

w5=w5*3038
w5=w4**3038+w5
'sertxd("X1=",#w5,cr,lf)
    
w6=w3*7357
w6=w2**7357+w6
'w7=w2*7357
'sertxd ("low=",#w7,cr,lf)
'if w7<32768 then: w6=w6+1: endif    'because its a neg no, it trunctes opposite way

'sertxd("X2=",#w6,cr,lf)
    
w5=w5-w6+3791
'sertxd("W5=",#w5,cr,lf)

w7=w3
if w5>32768 then
    w5=0-w5/16
    w6=w2-w5
    if w6>w2 then: w7=w7-1: endif
else
    w5=w5/16
    w6=w2+w5
    if w6<w2 then: w7=w7+1: endif
endif
'sertxd("p=",#w7," : ",#w6,cr,lf)

b7=b14
b6=b13
b4=b12

bptr=28
b5=w3//10
@bptrinc=w2//10
w2=w2/10
w3=w3/10
b5=b6

do until w2=0
@bptrinc=w2//10
w2=w2/10
loop

bptr=bptr-1
'sertxd ("Pressure (Pa)= ")
do until bptr <28
sertxd (#@bptrdec)
loop
sertxd (",  ",#b24,cr,lf)
b24=b24+1
if b24=60 then: b24=0: endif
b25=b24//30
if b25=0 then
    sertxd ("--------------",cr,lf)
endif
'sertxd (cr,lf)
'sertxd (cr,lf)

'pause 500
goto lp
i added this to code to above code for LCD

serout b.7,N2400_4(254,212)
serout b.7,N2400, ("Up",#w10) 'different word for UT / T / UP

which works for all except "Pressure"



I presume this is the "pressure" code ?

bptr=bptr-1
'sertxd ("Pressure (Pa)= ")
do until bptr <28
sertxd (#@bptrdec)
loop
 
Last edited by a moderator:

ken1991

New Member
on your post you said "I've made minor edits [ / and so on,"
where is the version you edited? have you edited on my post?
 

BillBWann

Member
I presume this is the "pressure" code ?

bptr=bptr-1
'sertxd ("Pressure (Pa)= ")
do until bptr <28
sertxd (#@bptrdec)
loop
Yes ken1991, that bit of code simply displays the calculated value of the pressure which is stored in 3 bytes because its too large to store in a single word. Each iteration of the do loop displays a single decimal digit of the calculated pressure. So all you need to do is display each of these digits on your LCD.

Regards

Bill
 
Top