Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:40 25 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : BME280 accuracy using Micromite

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 05:32pm 13 Sep 2019
Copy link to clipboard 
Print this post

I;ve tried 3 different BME280 modules now in case I have a faulty one and all of them give the same results
The readings are higher than the actual temperature, by around 2-3°C
I have tested it with my Weatherflow Sensor beside the BME280, a glass thermometer sat in the same place and a BME280 on a Pi Zero using Python and they all give around the same temperatures around 2-3°C lower than the MM

The MM is on  Pi Zero W using Matherps latest Picromite and the BME280 code thats on the forum

Anyone else found this or have any idea why?

I've mounted the BME280 sensor physically away from the Pi so it can't be heat from the PI affecting it.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5898
Posted: 10:25pm 13 Sep 2019
Copy link to clipboard 
Print this post

I have a BMP280 co-located with a SHT31.
The BMP280 is consistently 1 degree higher than the SHT31

I put it down to the BMP280 mainly interested in it's internal temperature which it uses for pressure and humidity readings.

The SHT31 uses Arduino code and the BME280 is on a MX170

Jim
VK7JH
MMedit   MMBasic Help
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 639
Posted: 01:38am 14 Sep 2019
Copy link to clipboard 
Print this post

Back in Feb. I took readings from 2, BME with 170 and decided the error was less than 0.5C.

Peter
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 425
Posted: 04:19pm 14 Sep 2019
Copy link to clipboard 
Print this post

I also found this problem (+2/3 DegC), including with a rpi3, and even an arduino
I think it come from chinese product quality with low cost components
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 639
Posted: 12:32am 15 Sep 2019
Copy link to clipboard 
Print this post

Good morning Lew.

I just read your post correctly this time.
The actual problem is with the MM not the BME280, correct?
It is reading 2-3 degrees higher than true.
If that is the case then:

1. check code
2. check soldered joins & mechanical connections
3. prayer

Peter
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2285
Posted: 12:54am 15 Sep 2019
Copy link to clipboard 
Print this post

might i suggest the following test:

place a BMP280, a DS18B20, and a SHT31 - all wired up to a remove micromite - into a small polystyrene box, along with something to act as a thermal mass. sand would to. leave for half a day and check the temperature reading produced by each.

you'll find that different constructions of sensor may behave differently in free air. things like exposed metal surfaces (BMP280), a plastic shell (SHT31), and a thermall small mass (DS18B20) will effect how small movements of air impact the reading.


cheers,
rob   :-)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5898
Posted: 02:40am 15 Sep 2019
Copy link to clipboard 
Print this post

I had a spare BME280 so I added it to my test micromite. (The one accessible from MMEDit)

  Quote  12:39:14 T(BMP180): 22.1 P(sl): 1011.5,T(DHT22): 21.4 H: 48.9,T(DS18B20): 23.5 BME280: T: 23.1 P: 1011.0 H: 43.7
12:39:24 T(BMP180): 22.1 P(sl): 1011.4,T(DHT22): 21.4 H: 49.0,T(DS18B20): 23.2 BME280: T: 23.1 P: 1011.0 H: 43.8
12:39:34 T(BMP180): 22.1 P(sl): 1011.4,T(DHT22): 21.4 H: 49.1,T(DS18B20): 23.2 BME280: T: 23.1 P: 1011.0 H: 43.9



The test micromite is not in a case and the sensors are in free air reasonably close to each other.

Jim
VK7JH
MMedit   MMBasic Help
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 639
Posted: 06:31am 15 Sep 2019
Copy link to clipboard 
Print this post

I think it was 23.1 +/- 0.5 at your place.

Peter
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 01:32pm 16 Sep 2019
Copy link to clipboard 
Print this post

Sorry the title of this post is wrong - it should be PI-Cromite not Micromite

I have just got a genuine expensive BME280 just in case any of the others I tried are faulty and I still get the same results

It varies from aroun 3°C high to 4°C higher than the actual temperature

I have tried this so it's eliminated any heat produced by anything

I have it set on a table with a fan blowing air slowly past it, the BME280 is not in any case or packaging it's open to the air on the table

Then I put the glass thermometer in the same spot and took readings

Then I put my Weatherflow Temperature sensor in the same spot and took readings
and finally I used a Fluke multimeter with temperature sensor and took readings

All devices were within 1°C of each other apart from the BME280 mounted on the Pi board

I've used the same BME280 on the same board but using Python instead of MM Basic and it gives a temperature very close to the other devices

I've tried altering the speed of the I2C bus in case that might be causing it but it doesn't help

Anyone got any ideas?

The only thing I can think of is the self calibration in MM is slightly out when using a Pi Zero?
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3510
Posted: 01:58pm 16 Sep 2019
Copy link to clipboard 
Print this post

Dear lew247,

I recall reading a note about the PI running MMbasic. When MMBasic is idle, it still consumes some power.
Maybe that could explain the 3 degrees difference between python and MMBasic.
Local heating by the PI core. You could simply check this by measuring the power from the USB. That heat goes somewhere..

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 02:13pm 16 Sep 2019
Copy link to clipboard 
Print this post

  Volhout said  Dear lew247,

I recall reading a note about the PI running MMbasic. When MMBasic is idle, it still consumes some power.
Maybe that could explain the 3 degrees difference between python and MMBasic.
Local heating by the PI core. You could simply check this by measuring the power from the USB. That heat goes somewhere..

Regards,

Volhout


I've eliminated any heat produced by anything

I have it set on a table with a fan blowing air slowly past it, the BME280 is not in any case or packaging it's open to the air on the table
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5898
Posted: 09:58pm 16 Sep 2019
Copy link to clipboard 
Print this post

Can you run the same code on a micromite to see if there is a similar difference in readings.
If there is a difference, you can then print the calibration values etc to see where things deviate between the platforms.

I don't have a PiZero so can't do it here.

I find my BME280 reads higher than the others when there is more air movement.
When there is little air flow, the difference between the various modules is much less.

This is this mornings test:
  Quote  07:46:51 T(BMP180): 14.0 P(sl): 1028.5,T(DHT22): 13.7 H: 45.5,T(DS18B20): 14.0 BME280: T: 15.1 P: 1028.4 H: 42.7
07:47:01 T(BMP180): 14.0 P(sl): 1028.6,T(DHT22): 13.7 H: 45.4,T(DS18B20): 14.0 BME280: T: 15.2 P: 1028.3 H: 42.8
07:47:11 T(BMP180): 14.0 P(sl): 1028.7,T(DHT22): 13.7 H: 45.4,T(DS18B20): 14.0 BME280: T: 15.2 P: 1028.3 H: 42.7
07:47:21 T(BMP180): 14.0 P(sl): 1028.5,T(DHT22): 13.7 H: 45.5,T(DS18B20): 14.0 BME280: T: 15.2 P: 1028.3 H: 42.6



A copy of the code you are using will help.

Jim
Edited 2019-09-17 08:01 by TassyJim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5898
Posted: 04:44am 17 Sep 2019
Copy link to clipboard 
Print this post

OK Lew,
I have had a play.
The following program needs to be run on your PI as well as a micromite using the same BME280 module.
You can then compare the registers and see where there are differences.
The cal%(x), Tx Px and Hx values should be the same for the same module but differ between modules.

The adc%(x) values depend on the temperature etc so will be different for each run.

If you need further investigation, we can take dig into the maths further and see where the figures diverge.

  Quote    ' BME280 test program to compare Pi-cromite to micromite basic
 OPTION BASE 0
 
OPTION EXPLICIT
 
 
'  BME280 constants
 '
 CONST BME280_ADDRESS                    = &H76
 
CONST BME280_REGISTER_T1                = &H88
 
CONST BME280_REGISTER_P1                = &H8E
 
CONST BME280_REGISTER_H1                = &HA1
 
CONST BME280_REGISTER_H2                = &HE1
 
CONST BME280_REGISTER_CHIPID            = &HD0
 
CONST BME280_REGISTER_CONTROLHUMID      = &HF2
 
CONST BME280_REGISTER_CONTROL           = &HF4
 
CONST BME280_REGISTER_PRESSUREDATA      = &HF7
 
CONST BME280_REGISTER_TEMPDATA          = &HFA
 
CONST BME280_REGISTER_HUMIDDATA         = &HFD
 
'
 DIM INTEGER s16=&HFFFFFFFFFFFF0000 , s16b=&H8000
 
DIM INTEGER s12=&HFFFFFFFFFFFFF000 , s12b=&H800
 
DIM INTEGER s8= &HFFFFFFFFFFFFFF00 , s8b=&H80
 
'
 DIM INTEGER T1,T2,T3     'uint16_t, int16_t, int16_t
 DIM INTEGER P1,P2,P3,P4,P5,P6,P7,P8,P9    'uint16_t, 8 x int16_t
 DIM INTEGER H1,H2,H3,H4,H5,H6     'uint8_t, int16_t , uint8_t, int16_t, int16_t, int8_t
 DIM INTEGER t_fine
 
DIM FLOAT t_bme, p_bme, h_bme, alt = 235    ' your altitude in metres
 
 
I2C OPEN 400, 200       ' Enable I2C. use slow speeds for long leads
 PAUSE 20
 
PRINT "Device = ";MM.DEVICE$
 bme280_init
 t_bme = bme280_read_temp()
 p_bme = bme280_read_pressure()
 p_bme = Psl(p_bme,alt)
 h_bme = bme280_read_humidity()
 
PRINT "T= ";t_bme;" P= ";p_bme;" H= ";h_bme
 
I2C CLOSE
 
END
 
 
FUNCTION Psl(p AS FLOAT, alt AS FLOAT) AS FLOAT
 
'given local pressure and altitude, returns pressure at sea level
 Psl= p/(1- alt/44330.77)^5.25588
END FUNCTION
 
 
'
FUNCTION bme280_read_temp() AS FLOAT
 
LOCAL INTEGER var1,var2,adc_T
 
LOCAL adc%(2),n!
 
I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_TEMPDATA
 
I2C READ BME280_ADDRESS,0,3,adc%()
 adc_T=((adc%(
0)<<16) OR (adc%(1)<<8) OR adc%(2))>>4
 var1  = ((((adc_T>>
3) - (T1 <<1))) * T2) \ q(11)
 var2  = (((((adc_T>>
4) - (T1)) * ((adc_T\ q(4)) - (T1))) \ q(12)) * (T3)) \ q(14)
 t_fine = var1 + var2
 bme280_read_temp = ((t_fine *
5 + 128) \ q(8))/100.0
 
PRINT "bme280_read_temp()"
 
FOR n! = 0 TO 2
   
PRINT "adc%(";n!;"), ";adc%(n!)
 
NEXT n!
END FUNCTION
 
FUNCTION bme280_read_pressure() AS FLOAT
 
LOCAL INTEGER var1, var2, adc_P, p
 
LOCAL adc%(2),n!
 
I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_PRESSUREDATA
 
I2C READ BME280_ADDRESS,0,3,adc%()
 adc_P=((adc%(
0)<<16) OR (adc%(1)<<8) OR adc%(2))>>4
 var1 = t_fine -
128000
 var2 = var1 * var1 * P6
 var2 = var2 + ((var1 * P5)<<
17)
 var2 = var2 + (P4 <<
35)
 var1 = ((var1 * var1 * P3)\ q(
8)) +    ((var1 * P2)<<12)
 var1 = ((
1<<47)+var1)*P1\ q(33)
 
IF var1 = 0 THEN
   bme280_read_pressure =  
0' avoid exception caused by division by zero
   EXIT FUNCTION
 
ENDIF
 p =
1048576 - adc_P
 p = (((p<<
31) - var2)*3125) \ var1
 var1 = (P9 * (p\ q(
13)) * (p\ q(13))) \ q(25)
 var2 = (P8 * p) \ q(
19)
 p = ((p + var1 + var2) \ q(
8)) + (P7<<4)
 bme280_read_pressure = p/
25600.0
 
PRINT "bme280_read_pressure()"
 
FOR n! = 0 TO 2
   
PRINT "adc%(";n!;"), ";adc%(n!)
 
NEXT n!
END FUNCTION
 
'
FUNCTION bme280_read_humidity() AS FLOAT
 
LOCAL INTEGER v_x1,adc_H
 
LOCAL adc%(1),n!
 
I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_HUMIDDATA
 
I2C READ BME280_ADDRESS,0,2,adc%()
 adc_H=(adc%(
0)<<8) OR adc%(1)
 v_x1 = t_fine -
76800
 v_x1=(((((adc_H<<
14)-((H4)<<20)-(H5*v_x1))+16384)\ q(15))*(((((((v_x1*H6)\ q(10))*(((v_x1*H3)\ q(11))+32768))\ q(10))+2097152)*H2+8192)\ q(14)))
 v_x1 = (v_x1 - (((((v_x1 \ q(
15)) * (v_x1 \ q(15))) \ q(7)) * (H1)) \ q(4)))
 
IF v_x1< 0 THEN v_x1 = 0
 
IF v_x1 > 419430400 THEN v_x1= 419430400
 bme280_read_humidity = (v_x1\ q(
12)) / 1024.0
 
PRINT "bme280_read_pressure()"
 
FOR n! = 0 TO 1
   
PRINT "adc%(";n!;"), ";adc%(n!)
 
NEXT n!
END FUNCTION
 
SUB bme280_init
 
LOCAL i%,cal%(17),n!
 
' i2c open 400,1000 '400KHz bus speed
 I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_CHIPID
 
I2C READ BME280_ADDRESS,0,1,i%
 
IF i%<>&H60 THEN PRINT "Error BME280 not found"
 
'
 I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_T1
 
I2C READ BME280_ADDRESS,0,6,cal%()
 T1=cal%(
0) OR (cal%(1)<< 8)
 T2=cal%(
2) OR (cal%(3)<< 8):   IF T2 AND s16b THEN T2=T2 OR s16 'sign extend if required
 T3=cal%(4) OR (cal%(5)<< 8):   IF T3 AND s16b THEN T3=T3 OR s16
 
'
 I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_P1
 
I2C READ BME280_ADDRESS,0,18,cal%()
 P1=cal%(
0) OR (cal%(1)<<8)
 P2=cal%(
2) OR (cal%(3)<<8):   IF P2 AND s16b THEN P2=P2 OR s16 'sign extend if required
 P3=cal%(4) OR (cal%(5)<<8):   IF P3 AND s16b THEN P3=P3 OR s16
 P4=cal%(
6) OR (cal%(7)<<8):   IF P4 AND s16b THEN P4=P4 OR s16
 P5=cal%(
8) OR (cal%(9)<<8):   IF P5 AND s16b THEN P5=P5 OR s16
 P6=cal%(
10) OR (cal%(11)<<8):   IF P6 AND s16b THEN P6=P6 OR s16
 P7=cal%(
12) OR (cal%(13)<<8):   IF P7 AND s16b THEN P7=P7 OR s16
 P8=cal%(
14) OR (cal%(15)<<8):   IF P8 AND s16b THEN P8=P8 OR s16
 P9=cal%(
16) OR (cal%(17)<<8):   IF P9 AND s16b THEN P9=P9 OR s16
 
'
 I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_H1
 
I2C READ BME280_ADDRESS,0,1,H1
 
I2C WRITE BME280_ADDRESS,1,1,BME280_REGISTER_H2
 
I2C READ BME280_ADDRESS,0,7,cal%()
 H2=cal%(
0) OR (cal%(1)<< 8):   IF H2 AND s16b THEN H2=H2 OR s16 'sign extend if required
 H3=cal%(2)
 H6=cal%(
6):   IF H6 AND s8b THEN H6=H6 OR s8 'sign extend if required
 H4=(cal%(3)<<4) OR (cal%(4) AND &H0F): IF H4 AND s12b THEN H4=H4 OR s12 'sign extend if required
 H5=(cal%(5)<<4) OR (cal%(4)>>4):  IF H5 AND s12b THEN H5=H5 OR s12
 
'
 I2C WRITE BME280_ADDRESS,0,2,BME280_REGISTER_CONTROLHUMID,&H05 '16x oversampling humidity
 I2C WRITE BME280_ADDRESS,0,2,BME280_REGISTER_CONTROL,&HB7      '16x oversampling pressure/temp, normal mode
 '
 FOR n! = 0 TO 17
   
PRINT "cal%(";n!;"), &h";HEX$(cal%(n!),2)
 
NEXT n!
 
PRINT
 
PRINT "T1 , &h";HEX$(T1,4)
 
PRINT "T2 , &h";HEX$(T2,4)
 
PRINT "T3 , &h";HEX$(T3,4)
 
PRINT
 
PRINT "P1 , &h";HEX$(P1,4)
 
PRINT "P2 , &h";HEX$(P2,4)
 
PRINT "P3 , &h";HEX$(P3,4)
 
PRINT "P4 , &h";HEX$(P4,4)
 
PRINT "P5 , &h";HEX$(P5,4)
 
PRINT "P6 , &h";HEX$(P6,4)
 
PRINT "P7 , &h";HEX$(P7,4)
 
PRINT "P8 , &h";HEX$(P8,4)
 
PRINT "P9 , &h";HEX$(P9,4)
 
PRINT
 
PRINT "H1 , &h";HEX$(H1,4)
 
PRINT "H2 , &h";HEX$(H2,4)
 
PRINT "H3 , &h";HEX$(H3,4)
 
PRINT "H4 , &h";HEX$(H4,4)
 
PRINT "H5 , &h";HEX$(H5,4)
 
PRINT "H6 , &h";HEX$(H6,4)
 
PRINT
END SUB
 
'
FUNCTION q(x AS INTEGER) AS INTEGER  'returns 2 raised to the power
 q=(1<<x)
END FUNCTION


Results form a RPi and micromite:

  Quote  > RUN
Device = Micromite MkII
cal%( 0), &h6D
cal%( 1), &h01
cal%( 2), &h00
cal%( 3), &h13
cal%( 4), &h27
cal%( 5), &h03
cal%( 6), &h1E
cal%( 7), &h26
cal%( 8), &h37
cal%( 9), &hFF
cal%( 10), &hF9
cal%( 11), &hFF
cal%( 12), &hAC
cal%( 13), &h26
cal%( 14), &h0A
cal%( 15), &hD8
cal%( 16), &hBD
cal%( 17), &h10

T1 , &h6D04
T2 , &h663A
T3 , &h0032

P1 , &h9613
P2 , &hFFFFFFFFFFFFD5D0
P3 , &h0BD0
P4 , &h26AE
P5 , &hFFFFFFFFFFFFFF37
P6 , &hFFFFFFFFFFFFFFF9
P7 , &h26AC
P8 , &hFFFFFFFFFFFFD80A
P9 , &h10BD

H1 , &h004B
H2 , &h016D
H3 , &h0000
H4 , &h0137
H5 , &h0032
H6 , &h001E

bme280_read_temp()
adc%( 0),  125
adc%( 1),  97
adc%( 2),  160
bme280_read_pressure()
adc%( 0),  66
adc%( 1),  52
adc%( 2),  240
bme280_read_pressure()
adc%( 0),  108
adc%( 1),  72
T=  20.91 P=  1027.35 H=  43.3281
>

> RUN
Device = Pi-cromite running on H/W version: A02082
cal%( 0), &h6D
cal%( 1), &h01
cal%( 2), &h00
cal%( 3), &h13
cal%( 4), &h27
cal%( 5), &h03
cal%( 6), &h1E
cal%( 7), &h26
cal%( 8), &h37
cal%( 9), &hFF
cal%( 10), &hF9
cal%( 11), &hFF
cal%( 12), &hAC
cal%( 13), &h26
cal%( 14), &h0A
cal%( 15), &hD8
cal%( 16), &hBD
cal%( 17), &h10

T1 , &h6D04
T2 , &h663A
T3 , &h0032

P1 , &h9613
P2 , &hFFFFFFFFFFFFD5D0
P3 , &h0BD0
P4 , &h26AE
P5 , &hFFFFFFFFFFFFFF37
P6 , &hFFFFFFFFFFFFFFF9
P7 , &h26AC
P8 , &hFFFFFFFFFFFFD80A
P9 , &h10BD

H1 , &h004B
H2 , &h016D
H3 , &h0000
H4 , &h0137
H5 , &h0032
H6 , &h001E

bme280_read_temp()
adc%( 0),  126
adc%( 1),  87
adc%( 2),  112
bme280_read_pressure()
adc%( 0),  66
adc%( 1),  134
adc%( 2),  128
bme280_read_pressure()
adc%( 0),  107
adc%( 1),  206
T=  22.14 P=  1027.339211 H=  42.65429687
>


Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024