BME280 Code Examples

marks

Senior Member
Digital Pressure Sensor- With Humidity.
The module I am using is the GYBMEP and can be had for about $10
default Hi2c address is $EC but can be rejumpered to use $EE also.

On the back has a 3.3v regulator .They suggest 1.8 to 5v can be used to supply this board.
I would perhaps prefer to feed it with about 4v but is working perfectly from my 3.3v supply.
And also a Hi2c translator chip so can be used @ 3.3v and 5v logic.

Hopefully the trim values I expect will be similar for all BME280 sensors the signed negative values may need
to be checked for compatibility .
This seems to be a good upgrade from the BMP180 the filter works surprising well!
attached is bosch api C driver for interest.
Code:
#picaxe 18m2 'marks
#no_data
pause 4000
#terminal 19200
SETFREQ M16
SYMBOL Calibrate_MSL_hPa = 0 ' No Adjust
'SYMBOL Calibrate_MSL_hPa = 38 ' Adjust to suit your elevation (3.8 hPa)at my location

SYMBOL T. = W0  SYMBOL F. = W0
SYMBOL UT = W0 SYMBOL UH = W1 SYMBOL UP = W0
SYMBOL C. = W0 SYMBOL H. = W1 SYMBOL P. = W0 SYMBOL Temp = W0
SYMBOL T1 = W1 SYMBOL H1 = W0 SYMBOL P1 = W1 SYMBOL P7 = W1
SYMBOL T2 = W2 SYMBOL H2 = W2 SYMBOL P2 = W2 SYMBOL rr = b4 SYMBOL r = b5
SYMBOL T3 = W3 SYMBOL H3 = W3 SYMBOL P3 = W3 SYMBOL P8 = W3
SYMBOL X1 = W4 SYMBOL H4 = W4 SYMBOL P4 = W4 SYMBOL P9 = W4
SYMBOL X2 = W5 SYMBOL H5 = W5 SYMBOL P5 = W5 SYMBOL p4Lsb = b10 SYMBOL index = b11
SYMBOL X3 = W6  SYMBOL H6 = W6  SYMBOL P6 = W6  SYMBOL inX2 = W6

SYMBOL Tfine = W12  'global
SYMBOL sign = b27 'global
SYMBOL xLsb  = b26  SYMBOL signF = b26

Initialize:
HI2CSETUP I2CMASTER, $EC, I2Cfast_16, I2CBYTE ' set to 400kbps BME280 @ 3.3v
    Hi2Cout $F2,($01) ' UHx1 sampling
    Hi2Cout $F5,($10) ' Filter x16 changes sampling UT and UP to 20bit

Main:
    Hi2Cout $F4,($56) ' UTx2 UPx16 sampling , force start of conversion

ConvertTemperatureBME280:
  Hi2Cin $88,(b2,b3,b4,b5,b6,b7) ' t1 t2 t3 compensation parameter values from BME280
  Hi2Cin $FA,(b1,b0,XLsb) ' UT bit data
  sign=" " : T2 = T2 *2
    T3 = T3 *2 ; BME280
    ; T3 = -T3 *2 ; BMP280 ?
X1 = UT -T1 : IF UT <T1 THEN : sign = "-" : X1 = -X1 : ENDIF
  xLsb = xLsb /64
    x2 = x1 +xLsb *x1 **4
    X2 = X1 +xLsb **X1 *4 +x2 **T3
  x3 = x1 +x1 +2 **t2
  X1 = X1 +X1 +xLsb **T2 +x3
IF sign = "-" THEN : X2 = -X2 :ENDIF
Tfine = X1 +X2 ; BME280
; Tfine = X1 -X2 ; BMP280 ?

ConvertPressureBME280:
T. = 16000 -Tfine : signF = "^"
IF sign = " " AND Tfine > 15999 THEN : T. = Tfine -16000 : signF = "+" : ENDIF
    IF sign = "-" THEN : T. = Tfine +16000 : ENDIF

  Hi2Cin  $94,(b8,b9,b10,b11,b12,b13)'p4 p5 p6 compensation parameter values from BME280
P6 = -P6 *2048 **T. **T.
P5 = P5 *512 **T.
IF signf = "^" THEN : P5 = P5 +P6 +8 /16: P5 = -P5 : ELSE : P5 = P5 -P6 +8 /16 : ENDIF
P4 = P4 *16 +P5
p4Lsb = P4//16 : P4 = P4 /16

Hi2Cin $8E,(b2,b3,b4,b5,b6,b7)'p1 p2 p3 compensation parameter values from BME280
P3 = P3 *5 **T. **T. **P1
P2 = -P2 *5 **T. *2 +1 **P1
IF signf = "^" THEN : P2 = P2 +P3 +5/10 : ELSE : P2 = P2 -P3 +5 /10 : P2 = -P2 : ENDIF
P1 = P1 +P2

  inX2 = $FFFF /P1 : Temp = $FFFF //P1 +1
     rr = P1 //10 : P1 = P1 /10
      FOR index = 1 TO 4
         inX2 = inX2 *10 : inX2 = Temp /P1 +inX2
         r = inX2 //10 *rr
         Temp = Temp //P1 *10 -r
      NEXT index

   Hi2Cin  $F7,(B1,b0,xLsb)         'Up data
P. = $FFFF -UP -P4 : xLsb = $10 -xLsb -p4Lsb
IF xLsb =16 THEN : P. = P.+2 : ENDIF
IF xLsb >15 THEN : xLsb = xLsb //16 : P. =P.-1 : ENDIF
P5 = p. *inX2 **1000'
P2 = xLsb *625 **inX2 **10486
P5 = P5 +P2 : P2 = P5 //1000 /100
P5 = P5 /1000
P.= P. **inX2 +P5
P4 = P2 *5 : P6 = P4 //10 /5
P4 = P4 /10
P5 = P. *5 +P4

Hi2Cin $9A,(b2,b3,b6,b7,b8,b9)'p7 p8 p9 compensation parameter values from BME280
P9 = P9 *8 **P5 +P6 **P5
P8 = -P8 *4 **P5
P7 = P8 -P7 -P9 /16
P5 = P7 //10
P7 = P7 /10
P2 = P2 +10 -P5
IF P2 <10 THEN: DEC P.:ENDIF
P2 = P2 //10
P. = P. -P7 +Calibrate_MSL_hPa
sertxd (#P.,#P2," hPa ")

  C.= Tfine **10240
  sertxd (" ",sign,#C.,"'C ")
    F.= Tfine **18432 +3200 : signF= " "
    IF sign = "-" THEN
     If Tfine <11380 THEN : F. = 6400 -F. ELSE signF = "-" : F. =F. -6400 : ENDIF
    ENDIF
    sertxd (" ",signF,#F.,"'F ")

ConvertHumidityBME280:
   Hi2Cin $E1,(b4,b5,w3) ' h2 h3 compensation parameter values from BME280
   Hi2Cin $E4,(w4,b10,b11,w6) ' h4 h5 h6 compensation parameter values from BME280
   b9=b10 and $0F : W4= b8*16+b9 ' adjust H4 12bit
                                        w5=w5/16 ' adjust H5 12bit
Hi2Cin $FD,(B3,b2)
  T. = 9600-Tfine : signF="^"
  IF sign = " " AND Tfine > 9599 THEN : T. = Tfine-9600 : signF="+" : ENDIF
  IF sign = "-" THEN : T. = Tfine+9600 : ENDIF
H4 = H4 *64
  H. = UH -H4 *2
   H5 = H5 *64 **T.
    IF signF="^" THEN :H. = H. +H5 ELSE H. = H. -H5 :ENDIF
    H6 = H6 +H3 *512 **H. **T.
    IF signF="^" THEN : H. = H. -H6 ELSE H. = H. +H6 :ENDIF
     Hi2Cin $A1,(w0) ' h1 compensation parameter values from BME280
      H2 = H2 *100 **H. *2
    H1 = H1 *512
   H1 = H2 **H2 **H1 /100
H. = H2 /4 -H1
sertxd (" ",#H.," %RH ",cr,lf)
pause 4000
GOTO main
 

Attachments

Last edited:

marks

Senior Member
Hi PhilHornby
Thanks for your interest!
I did skim over AllyCat's thread but I like to try and write my own as then understand a lot better
and learn a few new tricks along the way.

The picaxe code is using an 18m2 and at the moment 750 bytes long
with word variables w7 -w11 free for other use.
I have scaled down temperature but this does not seem to affect accuracy(about 100degreesC within a 16bit Word)

I have know done a excel spread sheet for checking.
For Temperature and Humidity , I am getting the same results 2 decimal accuracy
even the Fahrenheit code I added has two decimal accuracy.
When used with the BME280 sensor gives surprising steady results which I have not seen on other sensors.

For Pressure some checking I did I'm within between 0 to 3 pa of the spread sheet
and in use also seems to pole at about 3pa resolution so not getting the full 2 decimal place accuracy.
but for weather it is accurate to 1 decimal place just like the Bureau 1014.4Hpa

I believe the problem to be with Bosch API p = (p - (P4 / 4096)) * 6250 / P1;
On their 32bit api for p4 and p1 they are multiplying and dividing by 16bit just like my code
this is not accurate enough to give 1pa accuracy.
thats why they have a 64bit api lol.even then they are not placing in the full decimal but likely to
get close to the 1pa accuracy and in use may not be noticed.
So if I decide to improve on my code I know what to try first lol.
Even then noise could be a problem it may also fluctuate 1 or 2 pa
But the filter does seem to do a good job unlike the BMP180 more then a 10% improvement
so it does look worthwild to try (Then you know your getting the best out of the sensor).
 
Last edited:

AllyCat

Senior Member
Hi,

It's impressive to fit all the code into less than 1000 bytes, but of course it's often the (print) formatting, diagnostics, error-checking and general "maintainability" that takes up a lot of code space in a final program.

There are 3 lines in the .PDF listing which wrap and cause Syntax errors. However, there is no need to use a .PDF, the program easily fits within the forum limits, provided that you do NOT use the "Copy for Forum" option (because it copies all the [COLOR= ] commands), just use "Copy" within [code ] and [/code] tags ). The corrections seemed easy enough and the Temperature and Humidity results (shown at the foot of the code window) appear close to my own program (which I ran within a few minutes on the same BME280). But the pressure is about 7% high (the values of 1075.... instead of 1005... was easily overlooked).

I'm still concerned that the BME280's Humidity measurements are considerably lower than the (IMHO) "Market Leader" (Sensirion SHT30/1), used in semi-professional stations like Davis. My (indoor) humidity measurements are not currently comparable with any "meteo station" data, because it's below zero C outdoors at the moment (midday). :(

I'm not clear where the "Bosch API p = (p - (P4 / 4096)) * 6250 / P1" appears in the code, but I did note that they treat one division as a "special case" to give a 17 bit result (which might just give 1 Pa resolution). I modified my division routine to give a 24-bit result, although of course the raw data is at best 20 bits, which I then rounded in the 18th bit. But 1 Pa does only correspond to an "altitude" change of less than 10 cms. :)

Code:
'#picaxe 18m2 'marks
#picaxe 14m2	;
#no_data
pause 4000
high b.1		; For BME280supply pin
low b.2		; For BME280 Ground pin
#terminal 19200
SETFREQ M16
SYMBOL Calibrate_MSL_hPa = 0   ;43 ' Adjust to suit your elevation (4.3 hPa)
SYMBOL T. = W0 SYMBOL F. = W0
SYMBOL UT = W0 SYMBOL UH = W1 SYMBOL UP = W0
SYMBOL C. = W0 SYMBOL H. = W1 SYMBOL P. = W0 SYMBOL Temp = W0
SYMBOL T1 = W1 SYMBOL H1 = W0 SYMBOL P1 = W1 SYMBOL P7 = W1
SYMBOL T2 = W2 SYMBOL H2 = W2 SYMBOL P2 = W2 SYMBOL rr = b4 SYMBOL r = b5
SYMBOL T3 = W3 SYMBOL H3 = W3 SYMBOL P3 = W3 SYMBOL P8 = W3
SYMBOL X1 = W4 SYMBOL H4 = W4 SYMBOL P4 = W4 SYMBOL P9 = W4
SYMBOL X2 = W5 SYMBOL H5 = W5 SYMBOL P5 = W5 SYMBOL p4Lsb = b10 SYMBOL index = b11
SYMBOL X3 = W6 SYMBOL H6 = W6 SYMBOL P6 = W6 SYMBOL inX2 = W6
SYMBOL Tfine = W12 'global
SYMBOL sign = b27 'global
SYMBOL xLsb = b26 SYMBOL signF = b26
Initialize:
HI2CSETUP I2CMASTER, $EC, I2Cfast_16, I2CBYTE ' set to 400kbps BME280 @ 3.3v
Hi2Cout $F2,($01) ' UHx1 sampling
Hi2Cout $F5,($10) ' Filter x16 changes sampling UT and UP to 20bit
Main:
Hi2Cout $F4,($56) ' UTx2 UPx16 sampling , force start of conversion
ConvertTemperatureBME280:
Hi2Cin $88,(b2,b3,b4,b5,b6,b7) ' t1 t2 t3 compensation parameter values from BME280
Hi2Cin $FA,(b1,b0,XLsb) ' UT bit data
sign=" " : T2 = T2 *2
T3 = T3 *2 ; BME280
; T3 = -T3 *2 ; BMP280 ?
X1 = UT -T1 : IF UT <T1 THEN : sign = "-" : X1 = -X1 : ENDIF
xLsb = xLsb /64
x2 = x1 +xLsb *x1 **4
X2 = X1 +xLsb **X1 *4 +x2 **T3
x3 = x1 +x1 +2 **t2
X1 = X1 +X1 +xLsb **T2 +x3
IF sign = "-" THEN : X2 = -X2 :ENDIF
Tfine = X1 +X2 ; BME280
; Tfine = X1 -X2 ; BMP280 ?
ConvertPressureBME280:
T. = 16000 -Tfine : signF = "^"
IF sign = " " AND Tfine > 15999 THEN : T. = Tfine -16000 : signF = "+" : ENDIF
IF sign = "-" THEN : T. = Tfine +16000 : ENDIF
Hi2Cin $94,(b8,b9,b10,b11,b12,b13)'p4 p5 p6 compensation parameter values from BME280
P6 = -P6 *2048 **T. **T.
P5 = P5 *512 **T.
IF signf = "^" THEN : P5 = P5 +P6 +8 /16: P5 = -P5 : ELSE : P5 = P5 -P6 +8 /16 :ENDIF
P4 = P4 *16 +P5
p4Lsb = P4//16 : P4 = P4 /16
Hi2Cin $8E,(b2,b3,b4,b5,b6,b7)'p1 p2 p3 compensation parameter values from BME280
P3 = P3 *5 **T. **T. **P1
P2 = -P2 *5 **T. *2 +1 **P1
IF signf = "^" THEN : P2 = P2 +P3 +5/10 : ELSE : P2 = P2 -P3 +5 /10 : P2 = -P2 : ENDIF
P1 = P1 +P2
inX2 = $FFFF /P1 : Temp = $FFFF //P1 +1
rr = P1 //10 : P1 = P1 /10
FOR index = 1 TO 4
inX2 = inX2 *10 : inX2 = Temp /P1 +inX2
r = inX2 //10 *rr
Temp = Temp //P1 *10 -r
NEXT index
Hi2Cin $F7,(B1,b0,xLsb) 'Up data
P. = $FFFF -UP -P4 : xLsb = $10 -xLsb -p4Lsb
IF xLsb =16 THEN : P. = P.+2 : ENDIF
IF xLsb >15 THEN : xLsb = xLsb //16 : P. =P.-1 : ENDIF
P5 = p. *inX2 **1000'
P2 = xLsb *625 **inX2 **10486
P5 = P5 +P2 : P2 = P5 //1000 /100
P5 = P5 /1000
P.= P. **inX2 +P5
P4 = P2 *5 : P6 = P4 //10 /5
P4 = P4 /10
P5 = P. *5 +P4
Hi2Cin $9A,(b2,b3,b6,b7,b8,b9)'p7 p8 p9 compensation parameter values from BME280
P9 = P9 *8 **P5 +P6 **P5
P8 = -P8 *4 **P5
P7 = P8 -P7 -P9 /16
P5 = P7 //10
P7 = P7 /10
P2 = P2 +10 -P5
IF P2 <10 THEN: DEC P.:ENDIF
P2 = P2 //10
P. = P. -P7 +Calibrate_MSL_hPa
sertxd (#P.,#P2," hPa ")
C.= Tfine **10240
sertxd (" ",sign,#C.,"'C ")
F.= Tfine **18432 +3200 : signF= " "
IF sign = "-" THEN
If Tfine <11380 THEN : F. = 6400 -F. ELSE signF = "-" : F. =F. -6400 : ENDIF
ENDIF
sertxd (" ",signF,#F.,"'F ")
ConvertHumidityBME280:
Hi2Cin $E1,(b4,b5,w3) ' h2 h3 compensation parameter values from BME280
Hi2Cin $E4,(w4,b10,b11,w6) ' h4 h5 h6 compensation parameter values from BME280
b9=b10 and $0F : W4= b8*16+b9 ' adjust H4 12bit
w5=w5/16 ' adjust H5 12bit
Hi2Cin $FD,(B3,b2)
T. = 9600-Tfine : signF="^"
IF sign = " " AND Tfine > 9599 THEN : T. = Tfine-9600 : signF="+" : ENDIF
IF sign = "-" THEN : T. = Tfine+9600 : ENDIF
H4 = H4 *64
H. = UH -H4 *2
H5 = H5 *64 **T.
IF signF="^" THEN :H. = H. +H5 ELSE H. = H. -H5 :ENDIF
H6 = H6 +H3 *512 **H. **T.
IF signF="^" THEN : H. = H. -H6 ELSE H. = H. +H6 :ENDIF
Hi2Cin $A1,(w0) ' h1 compensation parameter values from BME280
H2 = H2 *100 **H. *2
H1 = H1 *512
H1 = H2 **H2 **H1 /100
H. = H2 /4 -H1
sertxd (" ",#H.," %RH ",cr,lf)
pause 4000
GOTO main

#rem    SAMPLE RESULTS:
390594 hPa   0'C   3200'F  4109 %RH 	; NUL DATA (BME280 not responding)
107569 hPa   1825'C   6486'F  3398 %RH 
107572 hPa   1827'C   6490'F  3399 %RH 
107569 hPa   1830'C   6494'F  3401 %RH 

BMx280 ID= 96
88-A1;E1-E7= 28184 , 26446 , 50 , 36836 , 54785 , 3024 , 7547 , 65426 , 65529 , 12300 , 53536 , 5000 , 19200 ,
 ,72,1,0,25,42,3,30
H1-H6= 75 : 328 : 0 : 6560 : 50 : 30
BMx280 ID= 96
BMx280 UT = 123:108:0 UP = 79:223:32 UH = 33308
BME280= 17.21 C : 35.20 % : Pressure= 1005.43 mb
SHT30 = 17.10 C : 42.43 %
BMx280 ID= 96
BMx280 UT = 123:144:128 UP = 79:235:16 UH = 33282
BME280= 17.40 C : 35.06 % : Pressure= 1005.42 mb
SHT30 = 17.24 C : 42.34 %
Cheers, Alan.
 

marks

Senior Member
Hi AllyCat,
I assumed the pdf in post#1 would keep all formatting (I didn't try it)
and as your've shown it wasn't a good choice I'll redo (done).

With that high pressure reading I wouldnt be confident there's a major problem there.
On my board the humidity reading appears correct when I bring my outdoor commercial sensor by (LA CROSSE)
next to the BME280 theres only a 1 % difference and expected the bosch sensor to be more accurate.

pressure on my spread sheet for some of your numbers was 1011 Hpa
Your H4 trimming value looks too large, to make it easier
I'll Post a program to run so I can easily paste results into excel to check!

I did notice many people on other platforms complain about humidity readings
Sugestion"s were to read the values in burst mode this seemed to fix their problem.
Reading the trim values continously requires good decouplin and regulated supply
trim values could be hard coded so they have less affect on supply and obtained sensor readings
but is then problematic if you change sensor.Luckily the Board I have has none of these issues.

T. = ((double)t_fine/2) - 64000; 25°C
P4 = T. * T. * ((double)dig_P6) / 32768;
P4 = P4 + T. * ((double)dig_P5) * 2;
P4 = (P4/4)+(((double)dig_P4) * 65536);
P1 = (((double)dig_P3) * T. * T. / 524288 + ((double)dig_P2) * T.) / 524288;
P1 = (1 + P1 / 32768)*((double)dig_P1);
p = 1048576 - (double)adc_P;

p = (p - (P4 / 4096)) * 6250 / P1;

P9 = ((double)dig_P9) * p * p / 2147483648;
P8 = p * ((double)dig_P8) / 32768;
p = p + (P9 + P8 + ((double)dig_P7)) / 16;

The formula is from 8.1 from the bosch datasheet it does look like I rewrote it slightly
I'm using the same formula in excel
the formula is then painstakinly converted to picaxe friendly code lol.
 
Last edited:

marks

Senior Member
Obtaining trimming values and sensor values for use with excel.
Quite often it will be recommended for checking it is also useful for negative numbers
to validate picaxe code we are using .Just copy and paste from the serial terminal
the values highlighted below from my sensor give the values 100903 2672 4051 are results from the spreadsheet.
Rich (BB code):
#picaxe 18m2 'marks
#no_data
pause 4000
#terminal 19200
SETFREQ M16

Initialize:
HI2CSETUP I2CMASTER, $EC, I2Cfast_16, I2CBYTE ' set to 400kbps BME280 @ 3.3v
Hi2Cout $F2,($01) ' UHx1 sampling BME280
Hi2Cout $F5,($10) ' Filter x16 changes sampling UT and UP to 20bit
main:
for b25 = 1 to 4
Hi2Cout $F4,($56) ' UTx2 UPx16 sampling , force start of conversion
pause 100
Hi2Cin $FA,(B1,b0,b26)
sertxd ("UT ",#W0," ",#b26," ")
Hi2Cin $F7,(B1,b0,b27)
sertxd ("UP ",#w0," ",#b27," ")
Hi2Cin $FD,(B1,b0) ' Up 16 bit data 32768
sertxd ("UH ",#w0,cr,lf)
next b25

   sertxd ("Trimming Values",cr,lf)
Hi2Cin $88,(b2,b3,b4,b5,b6,b7)
sertxd (#w1,cr,lf) 'T1 compensation parameter values from BME280
sertxd (#w2,cr,lf) 'T2 compensation parameter values from BME280
b8= " ":If b7 > 127 then: b8="-":W3=-W3 :b9=1 : endif
sertxd (b8,#w3,cr,lf,cr)'T3 compensation parameter values from BME280

Hi2Cin $8E,(b2,b3,b6,b7,b4,b5)
sertxd (#w1,cr,lf) 'P1 compensation parameter values from BME280
b8= " ":If b7 > 127 then: b8="-":W3=-W3 : endif
sertxd (b8,#w3,cr,lf) 'P2 compensation parameter values from BME280
sertxd (#w2,cr,lf) 'P3 compensation parameter values from BME280

Hi2Cin $94,(b2,b3,b4,b5,b6,b7)
sertxd (#w1,cr,lf) 'P4 compensation parameter values from BME280
sertxd (#w2,cr,lf) 'P5 compensation parameter values from BME280
b8= " ":If b7 > 127 then: b8="-":W3=-W3 : endif
sertxd (b8,#w3,cr,lf) 'P6 compensation parameter values from BME280

Hi2Cin $9A,(b2,b3,b6,b7,b4,b5)
sertxd (#w1,cr,lf) 'P7 compensation parameter values from BME280
b8= " ":If b7 > 127 then: b8="-":W3=-W3 : endif
sertxd (b8,#w3,cr,lf) 'P8 compensation parameter values from BME280
sertxd (#w2,cr,lf,cr) 'P9 compensation parameter values from BME280

If b9=0 then
Hi2Cin $A1,(w0)
Hi2Cin $E1,(b2,b3,w2)
sertxd (#b0,cr,lf) ' H1 compensation parameter values from BME280
sertxd (#w1,cr,lf) ' H2 compensation parameter values from BME280
sertxd (#w2,cr,lf) ' H3 compensation parameter values from BME280
Hi2Cin $E4,(w0,b2,b3,w2)
b1=b2 and $0F : W0= b0*16+b1 : sertxd (#w0,cr,lf)' H4 compensation parameter values from BME280
w1=w1/16 : sertxd (#w1,cr,lf)' H5 compensation parameter values from BME280
sertxd (#b4,cr,lf)' H6 compensation parameter values from BME280
endif

Hi2Cout $F4,($56) ' UTx2 UPx16 sampling , force start of conversion
pause 200
sertxd(cr,"Picaxe18m2 SerTxd Values",cr,lf)
sertxd("(MSB/LSB) 16bit",cr,lf)
Hi2Cin $FA,(b1,b0,b26) ' UT
sertxd (#w0,cr,lf)

Hi2Cin $F7,(B1,b0,b27) ' Up
sertxd (#w0,cr,lf)

If b9=0 then
Hi2Cin $FD,(B1,b0) ' UH
sertxd (#w0,cr,lf)
endif

b26=b26/16 : sertxd (cr,#b26,cr,lf) 'UTxlsb 4bit
b27=b27/16 : sertxd (#b27,cr,lf) 'Upxlsb 4bit
bme280trims.JPGbme280excel.JPG
 
Last edited:

AllyCat

Senior Member
Hi,
Your H4 trimming value looks too large,
Yes, (as described in post #30 and the program comments in my thread linked in #2 above) I pre-multiplied the H4 value by 16 (i.e. <<4 ) : It's then easier to "untangle" the nibbles of the 12-bit value from the I2C data bytes, and the overall required <<20 becomes a simple word-swap in the main calculation. But both our programs (and also an Arduino version) take the data directly from the I2C bus, and all agree within about 1% RH (on 3 or 4 samples of BME280). The problem I have is that both the BME280 and SHT31 claim around +/-3% absolute accuracy but mine (3 x BME, 2 x SHT) dispute the value by up to 10%. Also, an aspirated "wet bulb" calculation using an 18B20 in a waterproof probe generally falls much closer to the SHT31, and an outdoors BME280 indicated only just over 80% RH when the visibilty (fog) was less than 50 metres.

Apart from changing to a 14M2 and enabling the power rails to my BME breakout module(s), the program I ran (listed above) is exactly as documented in the .PDF. The Temperature and Humidity look quite consistent, so I was "surprised" when I noticed the pressure reported as 107x. .. Pa.

Cheers, Alan.
 
Top