Newbie with bme280 issues

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Cmonte2
Posts: 6
Joined: Tue Sep 22, 2020 5:32 pm

Newbie with bme280 issues

Post by Cmonte2 » Tue Sep 22, 2020 5:57 pm

Hi all

First at all sorry for my english, I hope you can understand me ;)

Recently I bought a little kit in order to start an IOT projects. My intention is to monitoring the temperature and humidity outside of my home. For this task I have two bme280 sensors, this board https://www.aliexpress.com/item/3285805 ... 63c0E8piTS , the wires, breadboard, etc...

I have made it work and I see the values in the IDE ( I use Thonny IDE). The main problem is after a period of time, not always the same, the code returned an error.

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 15, in <module>
  File "bme280_float.py", line 236, in values
  File "bme280_float.py", line 158, in read_compensated_data
  File "bme280_float.py", line 123, in read_raw_data
OSError: [Errno 19] ENODEV
Only one I get this other error

Code: Select all

I (540) cpu_start: Pro cpu up.
I (540) cpu_start: Application information:
I (540) cpu_start: Compile time:     Sep  2 2020 03:00:08
I (543) cpu_start: ELF file SHA256:  0000000000000000...
I (549) cpu_start: ESP-IDF:          v3.3.2
I (554) cpu_start: Starting app cpu, entry point is 0x40082f30
I (0) cpu_start: App cpu up.
I (564) heap_init: Initializing. RAM available for dynamic allocation:
I (571) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (577) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (583) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (589) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (596) heap_init: At 3FFCA9E8 len 00015618 (85 KiB): DRAM
I (602) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (608) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (614) heap_init: At 4009DE28 len 000021D8 (8 KiB): IRAM
I (621) cpu_start: Pro cpu start user code
I (304) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I have tested several times and a with many different libraries but the result is always the error I posted above. Both sensor works fine because I have tested in my raspberry and it works normally, no errors for days.

I have read other guys with issues similar to mine and try to fix it the same way without sucess.

Surely I am doing something very wrong but I am unable to find the issue.

Any help would be much appreciate.

Thanks in advance.

User avatar
T-Wilko
Posts: 30
Joined: Thu Sep 19, 2019 8:08 am

Re: Newbie with bme280 issues

Post by T-Wilko » Wed Sep 23, 2020 12:24 pm

Your first error shows that your board couldn't detect the bme280 (ENODEV = error - no device detected). I've found from experience that the cheap bme/bmp280's often throw this error intermittently, for some unknown reason. Easiest way around this is to catch this exception every time you poll the sensor with a simple Try Catch loop.

As for the second error message, that simply shows that your ESP32 reset, reason for which can be explored with https://docs.micropython.org/en/latest/ ... eset_cause

ESP32's are unfortunately not the most reliable/consistent platform for micropython. Many of my ESP32 projects had phantom reboots that I couldn't end up attributing to anything.

Cmonte2
Posts: 6
Joined: Tue Sep 22, 2020 5:32 pm

Re: Newbie with bme280 issues

Post by Cmonte2 » Wed Sep 23, 2020 2:58 pm

Hi and thanks for your answer T-Wilko.

Once the sensor gives the first error the code doesn´t work anymore, it returns

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 11, in <module>
  File "bme280_float.py", line 88, in __init__
OSError: [Errno 19] ENODEV
by the way de code I run in order to get the values is like this:

Code: Select all

from machine import I2C, Pin
from bme280_float import *
from utime import sleep
import micropython, os
i2c = I2C(scl=Pin(26), sda=Pin(25), freq=40000)
bme280 = BME280(i2c=i2c)
while True:
    print(bme280.values)
    micropython.mem_info()
    sleep(30)
I have tested the two bme280 sensors in a raspberry and it works perfectly so I deduce that is the soc that is giving me headaches.

So the question is if there is any solution for this issue or there is nothing to do but change to another platform

Regards

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Newbie with bme280 issues

Post by Roberthh » Wed Sep 23, 2020 3:06 pm

The freq value of 40000 seems low. I guess the intention is 400000. But that should not matter, since the is no lower limit for the frequency.

Cmonte2
Posts: 6
Joined: Tue Sep 22, 2020 5:32 pm

Re: Newbie with bme280 issues

Post by Cmonte2 » Wed Sep 23, 2020 5:49 pm

Roberthh wrote:
Wed Sep 23, 2020 3:06 pm
The freq value of 40000 seems low. I guess the intention is 400000. But that should not matter, since the is no lower limit for the frequency.
Hi Robert, thanks for you reply. I have tested with 100.000 and 40.000 with same results.

I have tested this peace of code

Code: Select all

from machine import I2C, Pin
from bme280_float import *
from utime import sleep
import micropython, os
i2c = I2C(scl=Pin(26), sda=Pin(25), freq=100000)
bme280 = BME280(i2c=i2c)
while True:
    print(bme280.values)
    micropython.mem_info()
    sleep(30)
and this is the output, error including

Code: Select all

exec(open('./bme280test3.py').read(),globals())
(19.1135, 77.22618)
stack: 1376 out of 15360
GC: total: 111168, used: 17216, free: 93952
 No. of 1-blocks: 341, 2-blocks: 79, max blk sz: 30, max free sz: 5327
(19.12562, 77.22718)
stack: 1376 out of 15360
GC: total: 111168, used: 18736, free: 92432
 No. of 1-blocks: 434, 2-blocks: 80, max blk sz: 30, max free sz: 5327
(19.09755, 77.51016)
stack: 1376 out of 15360
GC: total: 111168, used: 20256, free: 90912
 No. of 1-blocks: 527, 2-blocks: 81, max blk sz: 30, max free sz: 5327
(19.08032, 77.76548)
stack: 1376 out of 15360
GC: total: 111168, used: 21776, free: 89392
 No. of 1-blocks: 620, 2-blocks: 82, max blk sz: 30, max free sz: 5327
(19.18178, 77.49446)
stack: 1376 out of 15360
GC: total: 111168, used: 23296, free: 87872
 No. of 1-blocks: 713, 2-blocks: 83, max blk sz: 30, max free sz: 5327
(19.06755, 77.ee sz: 5327
(19.28643, 77.58893)
stack: 1376 out of 15360
GC: total: 111168, used: 26336, free: 84832
 No. of 1-blocks: 899, 2-blocks: 85, max blk sz: 30, max free sz: 5300
( sz: 30, masz: 5205
(19.43128, 77.45843)
stack: 1376 out of 15360
GC: total: 111168, used: 29376, free: 81792
 No. of 1-blocks: 1085, 2-blocks: 87, max blk sz: 30, max free sz: 5110
(19.44724, 78.51614)
stack: 1376 out of 15360
GC: total: 111168, used: 30896, free: 80272
 No. of 1-blocks: 1178, 2-blocks: 88, max blk sz: 30, max free sz: 5015
(19.43639, 77.5331)
stack: 1376 out of 15360
GC: total: 111168, used: 32416, free: 78752
 No. of 1-blocks: 1271, 2-blocks: 89, max blk sz: 30, max free sz: 4920
(19.3898, 77.06089)
stack: 1376 out of 15360
GC: total: 111168, used: 33936, free: 77232
 No. of 1-blocks: 1364, 2-blocks: 90, max blk sz: 30, max free sz: 4825
(19.36875, 77.35037)
stack: 1376 out of 15360
GC: total: 111168, used: 35456, free: 75712
 No. of 1-blocks: 1457, 2-blocks: 91, max blk sz: 30, max free sz: 4730
(19.33684, 77.42762)
stack: 1376 out of 15360
GC: total: 111168, used: 36976, free: 74192
 No. of 1-blocks: 1550, 2-blocks: 92, max blk sz: 30, max free sz: 4635
(19.28515, 77.80573)
stack: 1376 out of 15360
GC: total: 111168, used: 38496, free: 72672
 No. of 1-blocks: 1643, 2-blocks: 93, max blk sz: 30, max free sz: 4540
(19.35726, 77.6292)
stack: 1376 out of 15360
GC: total: 111168, used: 40016, free: 71152
 No. of 1-blocks: 1736, 2-blocks: 94, max blk sz: 30, max free sz: 4445
(19.27494, 78.3414)
stack: 1376 out of 15360
GC: total: 111168, used: 41536, free: 69632
 No. of 1-blocks: 1829, 2-blocks: 95, max blk sz: 30, max free sz: 4350
(19.27686, 77.81646)
stack: 1376 out of 15360
GC: total: 111168, used: 43056, free: 68112
 No. of 1-blocks: 1922, 2-blocks: 96, max blk sz: 30, max free sz: 4255
(19.25899, 77.87202)
stack: 1376 out of 15360
GC: total: 111168, used: 44576, free: 66592
 No. of 1-blocks: 2015, 2-blocks: 97, max blk sz: 30, max free sz: 4160
(19.32216, 77.33503)
stack: 1376 out of 15360
GC: total: 111168, used: 46096, free: 65072
 No. of 1-blocks: 2108, 2-blocks: 98, max blk sz: 30, max free sz: 4065
(19.363, 78.26339)
stack: 1376 out of 15360
GC: total: 111168, used: 47616, free: 63552
 No. of 1-blocks: 2201, 2-blocks: 99, max blk sz: 30, max free sz: 3970
(19.3362, 77.67879)
stack: 1376 out of 15360
GC: total: 111168, used: 49136, free: 62032
 No. of 1-blocks: 2294, 2-blocks: 100, max blk sz: 30, max free sz: 3875
(19.28962, 78.54813)
stack: 1376 out of 15360
GC: total: 111168, used: 50656, free: 60512
 No. of 1-blocks: 2387, 2-blocks: 101, max blk sz: 30, max free sz: 3780
(19.25963, 77.79216)
stack: 1376 out of 15360
GC: total: 111168, used: 52176, free: 58992
 No. of 1-blocks: 2480, 2-blocks: 102, max blk sz: 30, max free sz: 3685
(19.35024, 76.97765)
stack: 1376 out of 15360
GC: total: 111168, used: 53696, free: 57472
 No. of 1-blocks: 2573, 2-blocks: 103, max blk sz: 30, max free sz: 3590
(19.3228, 76.00449)
stack: 1376 out of 15360
GC: total: 111168, used: 55216, free: 55952
 No. of 1-blocks: 2666, 2-blocks: 104, max blk sz: 30, max free sz: 3495
(19.26345, 75.43993)
stack: 1376 out of 15360
GC: total: 111168, used: 56736, free: 54432
 No. of 1-blocks: 2759, 2-blocks: 105, max blk sz: 30, max free sz: 3400
(19.1186, 76.0964)
stack: 1376 out of 15360
GC: total: 111168, used: 58256, free: 52912
 No. of 1-blocks: 2852, 2-blocks: 106, max blk sz: 30, max free sz: 3305
(18.9846, 76.46785)
stack: 1376 out of 15360
GC: total: 111168, used: 59776, free: 51392
 No. of 1-blocks: 2945, 2-blocks: 107, max blk sz: 30, max free sz: 3210
(18.92717, 76.54301)
stack: 1376 out of 15360
GC: total: 111168, used: 61296, free: 49872
 No. of 1-blocks: 3038, 2-blocks: 108, max blk sz: 30, max free sz: 3115
(18.90802, 75.9537)
stack: 1376 out of 15360
GC: total: 111168, used: 62816, free: 48352
 No. of 1-blocks: 3131, 2-blocks: 109, max blk sz: 30, max free sz: 3020
(18.83272, 76.49527)
stack: 1376 out of 15360
GC: total: 111168, used: 64336, free: 46832
 No. of 1-blocks: 3224, 2-blocks: 110, max blk sz: 30, max free sz: 2925
(18.95907, 76.97357)
stack: 1376 out of 15360
GC: total: 111168, used: 65856, free: 45312
 No. of 1-blocks: 3317, 2-blocks: 111, max blk sz: 30, max free sz: 2830
(18.9278, 76.90821)
stack: 1376 out of 15360
GC: total: 111168, used: 67376, free: 43792
 No. of 1-blocks: 3410, 2-blocks: 112, max blk sz: 30, max free sz: 2735
(18.94057, 76.22456)
stack: 1376 out of 15360
GC: total: 111168, used: 68896, free: 42272
 No. of 1-blocks: 3503, 2-blocks: 113, max blk sz: 30, max free sz: 2640
(19.0114, 76.88665)
stack: 1376 out of 15360
GC: total: 111168, used: 70416, free: 40752
 No. of 1-blocks: 3596, 2-blocks: 114, max blk sz: 30, max free sz: 2545
(19.08797, 77.67484)
stack: 1376 out of 15360
GC: total: 111168, used: 71936, free: 39232
 No. of 1-blocks: 3689, 2-blocks: 115, max blk sz: 30, max free sz: 2450
(19.12881, 78.21466)
stack: 1376 out of 15360
GC: total: 111168, used: 73456, free: 37712
 No. of 1-blocks: 3782, 2-blocks: 116, max blk sz: 30, max free sz: 2355
(19.12243, 78.57925)
stack: 1376 out of 15360
GC: total: 111168, used: 74976, free: 36192
 No. of 1-blocks: 3875, 2-blocks: 117, max blk sz: 30, max free sz: 2260
(19.09244, 78.81623)
stack: 1376 out of 15360
GC: total: 111168, used: 76496, free: 34672
 No. of 1-blocks: 3968, 2-blocks: 118, max blk sz: 30, max free sz: 2165
(19.08414, 78.76416)
stack: 1376 out of 15360
GC: total: 111168, used: 78016, free: 33152
 No. of 1-blocks: 4061, 2-blocks: 119, max blk sz: 30, max free sz: 2070
(19.06117, 77.39297)
stack: 1376 out of 15360
GC: total: 111168, used: 79536, free: 31632
 No. of 1-blocks: 4154, 2-blocks: 120, max blk sz: 30, max free sz: 1975
(19.08032, 76.9894)
stack: 1376 ou(19.15434, 78.02857)
stack: 1376 out of 15360
GC: total: 111168, used: 82576, free: 28592
 No. of 1-blocks: 4340, 2-blocks: 122, max blk sz: 30, max free sz: 1785
(19.13711, 79.21373)
stack: 1376 out of 15360
GC: total: 111168, used: 84096, free: 27072
 No. of 1-blocks: 4433, 2-blocks: 123, max blk sz: 30, max free sz: 1690
(19.03884, 79.40464)
stack: 1376 out of 15360
GC: total: 111168, used: 85616, free: 25552
 No. of 1-blocks: 4526, 2-blocks: 124, max blk sz: 30, max free sz: 1595
(19.0165, 79.70485)
stack: 1376 out of 15360
GC: total: 111168, used: 87136, free: 24032
 No. of 1-blocks: 4619, 2-blocks: 125, max blk sz: 30, max free sz: 1500
(19.01331, 79.96114)
stack: 1376 out of 15360
GC: total: 111168, used: 88656, free: 22512
 No. of 1-blocks: 4712, 2-blocks: 126, max blk sz: 30, max free sz: 1405
(18.95142, 80.36594)
stack: 1376 out of 15360
GC: total: 111168, used: 90176, free: 20992
 No. of 1-blocks: 4805, 2-blocks: 127, max blk sz: 30, max free sz: 1310
(18.94248, 80.60451)
stack: 1376 out of 15360
GC: total: 111168, used: 91696, free: 19472
 No. of 1-blocks: 4898, 2-blocks: 128, max blk sz: 30, max free sz: 1215
(18.91759, 80.81308)
stack: 1376 out of 15360
GC: total: 111168, used: 93216, free: 17952
 No. of 1-blocks: 4991, 2-blocks: 129, max blk sz: 30, max free sz: 1120
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  FiYk}5  File "bme280_float.py", line 124, in read_raw_data
OSError: [Errno 19] ENODEV
Regards

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Newbie with bme280 issues

Post by Roberthh » Wed Sep 23, 2020 6:07 pm

You could try to add a call to gc.collect() in the loop.

Cmonte2
Posts: 6
Joined: Tue Sep 22, 2020 5:32 pm

Re: Newbie with bme280 issues

Post by Cmonte2 » Thu Sep 24, 2020 7:16 am

Roberthh wrote:
Wed Sep 23, 2020 6:07 pm
You could try to add a call to gc.collect() in the loop.
I have tried this

Code: Select all

from machine import I2C, Pin
from bme280_float import *
from utime import sleep
import micropython, os
i2c = I2C(scl=Pin(26), sda=Pin(25), freq=100000)
bme280 = BME280(i2c=i2c)
while True:
    print(bme280.values)
    print(gc.collect())
    sleep(30)
and after a while

Code: Select all

exec(open('./bme280test3.py').read(),globals())
(20.14024, 68.26769)
None
(20.11854, 69.16092)
None
(20.12556, 69.52835)
None
(20.11854, 69.47628)
None
(20.13514, 69.20788)
None
(19.98581, 68.69939)
None
(19.47787, 68.83845)
None
(19.11031, 69.79849)
None
(18.63172, 71.71973)
None
(18.33627, 72.71977)
None
(18.09251, 74.20653)
None
(17.79834, 74.93533)
None
(17.55777, 75.44537)
None
(17.38038, 75.90307)
None
(17.23936, 77.09085)
None
(17.11748, 77.48387)
None
(17.02112, 77.89588)
None
(16.90946, 78.26656)
None
(16.68995, 79.31385)
None
(16.51383, 79.73453)
None
(16.4781, 79.20971)
None
(16.43024, 79.55686)
None
(16.38685, 79.83629)
None
(16.34091, 80.44972)
None
(16.2688, 80.77724)
None
(16.18074, 80.70104)
None
(16.16033, 81.13513)
None
(16.1297, 82.08896)
None
(16.06206, 82.62)
None
(16.06078, 83.04424)
None
(15.99761, 83.69411)
None
(15.97974, 84.09951)
None
(15.90572, 84.25598)
None
(15.91593, 84.39835)
None
(15.89424, 84.58269)
None
(15.87829, 84.92585)
None
(15.83489, 84.80268)
None
(15.85914, 83.45969)
None
(15.87191, 83.33093)
None
(15.88658, 83.71125)
None
(15.87892, 84.1628)
None
(15.8534, 84.17716)
None
(15.84, 84.00054)
None
(15.83107, 83.69436)
None
(15.86233, 83.31302)
None
(15.86297, 83.83892)
None
(15.86744, 84.34818)
None
(15.91147, 84.60706)
None
(15.88977, 83.72852)
None
Traceback (most recent call last):
 +py", line 159, in read_compensated_data
  File "bme280_float.py", line 124, in read_raw_data
OSError: [Errno 19] ENODEV
>>> 
Regards

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

ESPx reliability

Post by pythoncoder » Thu Sep 24, 2020 7:24 am

T-Wilko wrote:
Wed Sep 23, 2020 12:24 pm
...
ESP32's are unfortunately not the most reliable/consistent platform for micropython. Many of my ESP32 projects had phantom reboots that I couldn't end up attributing to anything.
This is undoubtedly true. Myself and @kevinkk525 have done extensive long term testing and found this does occur. The ESP8266 is worse and actually crashes: my record for keeping an ESP8266 running and using WiFi is 198 hours. The reliable WiFi platform is the Pyboard D which seems rock-solid.

Another factor in keeping these things going is coping with WiFi outages. Not a problem if you're just sending data, you can connect, send, and shut down. But if you're receiving you need to detect outages and reconnect.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Newbie with bme280 issues

Post by Roberthh » Thu Sep 24, 2020 8:13 am

So it does not seem to be a memory problem. But I remember having made a long test run comparing various sensors including the BME280 with up to 6000 tests in a row, 20000 samples in total. Board ESP32. I have not seen any of the sensors failing. So it might be a combination of the board/sensor you are using. The only difference I noted was, that I used the BME280_int.py variant of the driver. But that should not make a difference.

P.S.: There are frequent contact problems reported with lowcost = cheap breadboards and wires. Maybe you could check that.

User avatar
T-Wilko
Posts: 30
Joined: Thu Sep 19, 2019 8:08 am

Re: Newbie with bme280 issues

Post by T-Wilko » Thu Sep 24, 2020 2:54 pm

I had a bmp280 on a high altitude balloon project a little while ago that did this sort of random ENODEV occurences, so I just added Try Except statements like this (suited for your example) to make it so that it at least attempted to handle the error:

Code: Select all

while True:
    try:
        print(bme280.values)
        
    except OSError: #or alternatively just 'except:'
        print("Error occured")
        # Do some other error logging to keep track of how often this happens
        
    sleep(30)
Might be a knockoff BME sensor that isn't actually made by Bosch, I've heard there's a fair bunch in circulation.

Post Reply