pimoroni / bme680-python Goto Github PK
View Code? Open in Web Editor NEWPython library for the BME680 gas, temperature, humidity and pressure sensor.
Home Page: https://shop.pimoroni.com/products/bme680
License: MIT License
Python library for the BME680 gas, temperature, humidity and pressure sensor.
Home Page: https://shop.pimoroni.com/products/bme680
License: MIT License
First, thank you for this awesome library!
This is just to save some time for future people who might meet same error.
I am using BME680 on Jetson TX2. I got the error
RuntimeError: BME680 Not Found. Invalid CHIP ID: 0x-79
In my case, my I2C address is using 0x77.
Based on the example code, it should automatically switch to 0x77 if 0x76 failed, but it does not.
try:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY) # 0x76
except IOError:
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY) # 0x77
So basically you just need replace
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
to
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
It will work.
Or you can connect BME680's SDO PIN to the ground, which will change I2C address from 0x77 to 0x76.
I need 3 sensors, but there are unfortunately only 2 I2C addresses. So i have to use SPI instead of I2C. Is there a way to use the same library in SPI?
I've been getting some pretty whacky gas resistance readings from one of the BME680 sensors using this library. The values I've logged have spiked as high as 285204105.924075 and as low as -24795831.931635 which is pretty far outside the expected range as I understand it.
Here are a bunch of graphs at increasing levels of detail to illustrate the trends:
Another sensor elsewhere in the house running the exact same code is returning more sensible values:
For reference this is the code I'm running: https://github.com/davea/rpi-mqtt-sensors/blob/master/main.py
How do I use DISABLE_HEATER
defined in constants.py? I'm not using the gas sensor and would like to turn the heater off.
https://learn.pimoroni.com/bme680
Shows a blank page.
Hi,
I am experiencing the issue that the temperatures from the bme680 are too high. Compared to another temperature sensor they are about 3-4 °C higher.
Changing the oversampling methods won't fix the issue. The sensors are not influenced by the heat from the raspberrypi zero w. I could just substract 4°C from the temperature, but the relative humidity is also influenced by the wrong temperature.
Does anyone know how to fix the issue?
I looked briefly into the _calc_temperature
funtion in init.py but I could figure out where I should start on a fix.
I attached the output of the read-all.py.
Calibration data:
par_gh1: -30
par_gh2: -24754
par_gh3: 18
par_h1: 676
par_h2: 1029
par_h3: 0
par_h4: 45
par_h5: 20
par_h6: 120
par_h7: -100
par_p1: 36673
par_p10: 30
par_p2: -10515
par_p3: 88
par_p4: 7310
par_p5: -129
par_p6: 30
par_p7: 46
par_p8: -3177
par_p9: -2379
par_t1: 26041
par_t2: 26469
par_t3: 3
range_sw_err: 0
res_heat_range: 1
res_heat_val: 48
t_fine: 136667
Initial reading:
gas_index: 0
gas_resistance: 12946860
heat_stable: False
humidity: 42.402
meas_index: 0
pressure: 987.12
status: 32
temperature: 26.69
Polling:
Polling:
26.70 C,987.11 hPa,42.40 %RH
26.71 C,987.11 hPa,42.38 %RH,24370 Ohms
26.74 C,987.12 hPa,42.34 %RH,33347 Ohms
26.77 C,987.12 hPa,42.26 %RH,43482 Ohms
26.80 C,987.16 hPa,42.21 %RH,53233 Ohms
26.82 C,987.16 hPa,42.14 %RH,62627 Ohms
26.84 C,987.15 hPa,42.09 %RH,71260 Ohms
26.86 C,987.15 hPa,42.02 %RH,79288 Ohms
26.87 C,987.16 hPa,41.97 %RH,86583 Ohms
26.89 C,987.13 hPa,41.92 %RH,93756 Ohms
...
27.16 C,987.12 hPa,40.87 %RH,209827 Ohms
27.15 C,987.12 hPa,40.88 %RH,212672 Ohms
27.15 C,987.11 hPa,40.90 %RH,211037 Ohms
27.16 C,987.10 hPa,40.91 %RH,211988 Ohms
...
27.30 C,987.12 hPa,41.45 %RH,214333 Ohms
27.29 C,987.13 hPa,41.69 %RH,215737 Ohms
27.29 C,987.13 hPa,41.86 %RH,215879 Ohms
27.29 C,987.14 hPa,41.95 %RH,217447 Ohms
27.29 C,987.14 hPa,41.98 %RH,217878 Ohms
27.29 C,987.14 hPa,41.97 %RH,218456 Ohms
27.30 C,987.14 hPa,41.92 %RH,220062 Ohms
27.30 C,987.13 hPa,41.86 %RH,218892 Ohms
I turned the gas sensor of the green raspizero1 of at 14:37 with sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
. But it didn't affect the temperature readings.
Can someone point me in a useful direction to fix the temperature issue?
I want to use sleep mode to reduce consumption and force mode just when I need readings
I've been looking through the code in detail, and there seems to be something odd with get_sensor_data(self)
. The power mode is set to FORCED_MODE
at the start, but is never returned to the mode it was in when starting the method. Is this intentional? Or should the mode be saved when entering this method, and reset just before returning?
Don't panic, I'm not looking for detailed instructions, more a yes or no with a pointer to where to get started.
Thanks!
Hello everyone,
We have bought the breakout circuit and are using it in combination with a rsp pi 4. Altough the measurements seem fine we would like to calculate CO2 estimation (ppm) out of it. As described in the datasheet of the BME680 the sensor itself should already do this. But as this point we can not seem to find out how we can acces this value from the python script.
You can see here that through the C library there are available sensor readings from the device.
https://github.com/alexh-name/bsec_bme680_linux
Upon reviewing the patch there seems to be sensor data through the use of the API (most likely proprietary calculations) as provided in https://www.bosch-sensortec.com/media/boschsensortec/downloads/bsec/bsec_1-4-8-0_generic_release.zip in the examples/bsec_iot_example.c
I'm not sure if it is able to be supported in this library by extending the function
bme680-python/library/bme680/__init__.py
Line 258 in da98fca
Thanks!
Hi,
Pull request #13 adds the possibility to set a temperature offset.
In the first comment of the PR you can see that setting a positive offset results in an increased %RH, while a negative offset decreases the %RH.
As far as I know, it should be the other way around, plus the difference should be much greater...
Am I missing something?
Thanks!
When running example read_all.py
, after about 5-10 samples the readout shows:
32.57 C,686.35 hPa,100.00 %RH
then continues with these values until Errno 121. Sometimes it takes longer, sometimes error occurs immediately without any readings.
I am using a bunch of jumpers, and I have DHT22 connected on a different pin, and no other devices. Could it be a bad connection? Can't find much about this strangest thing, did I damage the sensor?
Oh, I also saw this earlier, which lead me down this rabbit hole:
I should probably mention that both of these sensors are hanging in a sealed jar above some wet salt to calibrate humidity readings.
I have tried a simpler version of the bme680 and it worked. With this version the gas is always the same: 118898.4. The rest is correct. What could be wrong?
Hello,
I am getting the below error when I run the examples.
Installed the libraries based on the README.
Seems my slave address is 0x77, but python code is using 0x76, thats why I am getting this issue ?
BTW, this one works, its C code.
https://github.com/twartzek/bme680-raspberry
But I would like to use python.
pi@picontainer1:~/bme680/examples $
pi@picontainer1:~/bme680/examples $ python --version
Python 2.7.13
pi@picontainer1:~/bme680/examples $
pi@picontainer1:~/bme680/examples $
pi@picontainer1:~/bme680/examples $ ls
indoor-air-quality.py read-all.py temp-press-hum.py
pi@picontainer1:~/bme680/examples $ python read-all.py
Traceback (most recent call last):
File "read-all.py", line 6, in <module>
sensor = bme680.BME680()
File "/usr/local/lib/python2.7/dist-packages/bme680/__init__.py", line 25, in __init__
self.chip_id = self._get_regs(CHIP_ID_ADDR, 1)
File "/usr/local/lib/python2.7/dist-packages/bme680/__init__.py", line 285, in _get_regs
return self._i2c.read_byte_data(self.i2c_addr, register)
IOError: [Errno 121] Remote I/O error
pi@picontainer1:~/bme680/examples $
pi@picontainer1:~/bme680/examples $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77
pi@picontainer1:~/bme680/examples $
pi@picontainer1:~/bme680/examples $
Thanks for the help.
Hi,
I'm using this code on a LoPy and it seems to work well, other than that the pressure reading is too high. I'm consistently seeing readings around 21mb higher than they should be (eg currently 1038 when the real pressure is ~1017). The pressure reading also consistently rises as the temperature drops. It doesn't seem to make a difference whether I have the gas heater on or off.
I've had good success with the BMP180 measuring temp/pressure in the same environment (just a house, nothing special!)
Can you think of anything I should try?
Hi,
I'm having a similar problem to #10 but the issue isn't my i2c address I think (it's 0x76 as defined for the primary in the constants file).
Any suggestions? I'm not really sure where to look.
Thanks,
pi@mypi:~ $ python2.7 Pimoroni/bme680/examples/read-all.py
Traceback (most recent call last):
File "Pimoroni/bme680/examples/read-all.py", line 6, in <module>
sensor = bme680.BME680()
File "/usr/local/lib/python2.7/dist-packages/bme680/__init__.py", line 25, in __init__
self.chip_id = self._get_regs(CHIP_ID_ADDR, 1)
File "/usr/local/lib/python2.7/dist-packages/bme680/__init__.py", line 296, in _get_regs
return self._i2c.read_byte_data(self.i2c_addr, register)
IOError: [Errno 121] Remote I/O error
pi@mypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
I forked this repo quite some time ago and started porting it to the BME688. I mainly came up with the same set of changes as you now. But when I started to compare all the constants, I noted a number of differences.
E.g. you have
COEFF_SIZE = 41
COEFF_ADDR1_LEN = 25
COEFF_ADDR2_LEN = 16
# Coefficient's address
COEFF_ADDR1 = 0x89
COEFF_ADDR2 = 0xe1
and Bosch has
#define BME68X_LEN_COEFF1 UINT8_C(23)
#define BME68X_LEN_COEFF2 UINT8_C(14)
#define BME68X_REG_COEFF1 UINT8_C(0x8a)
#define BME68X_REG_COEFF2 UINT8_C(0xe1)
(Bosch also reads and processes a third set of coefficients).
So this stopped me from going on (there are more differences, e.g. in the array-indices, and it would need way more time to figure out where and how all those constants are used). I also ran a program with the Bosch-Code and with my code (which is almost identical to your code) and the results did not match.
All of this is not really related to the BME688, at least Bosch claims their BME68x code works with both sensors. So I wonder if the python-bme680-package has ever produced correct results or if Bosch is wrong.
After running ok for some time, I get the following exception
sensor.get_sensor_data()
File "build/bdist.linux-armv7l/egg/bme680/__init__.py", line 264, in get_sensor_data
self.set_power_mode(constants.FORCED_MODE)
File "build/bdist.linux-armv7l/egg/bme680/__init__.py", line 248, in set_power_mode
self._set_bits(constants.CONF_T_P_MODE_ADDR, constants.MODE_MSK, constants.MODE_POS, value)
File "build/bdist.linux-armv7l/egg/bme680/__init__.py", line 307, in _set_bits
self._set_regs(register, temp)
File "build/bdist.linux-armv7l/egg/bme680/__init__.py", line 314, in _set_regs
self._i2c.write_i2c_block_data(self.i2c_addr, register, value)
TypeError: Third argument must be a list of at least one, but not more than 32 integers
and the sensor fails all the time after this.
Im needing altitude and sea level pressure parameters. Is there something Im missing?
I've made a small adapter class so that this can be used with micropython:
https://github.com/gkluoe/bme680/blob/master/library/bme680/i2c.py
@Gadgetoid would you consider a pull request to add this functionality?
Probably a stupid question, but would we be able to use this on a Raspberry Pi Pico W running micropython? I've seen a couple of issues on this but I just need a definite answer from someone, thanks.
Hello
I'll try to get a BME680 running on breakout garden with raspberry pi 3b+ and constantly receive
Traceback (most recent call last):
File "temp-offset.py", line 7, in
sensor = bme680.BME680()
File "build/bdist.linux-armv7l/egg/bme680/init.py", line 47, in init
RuntimeError: BME680 Not Found. Invalid CHIP ID: 0x00
I assume BME680 CHIPP ID should be 0x61? Is there a way to fix this?
Many thanks!
When running example programs is get
Traceback (most recent call last): File "read-all.py", line 6, in <module> sensor = bme680.BME680() File "build/bdist.linux-armv7l/egg/bme680/__init__.py", line 27, in __init__ RuntimeError: BME680 Not Found. Invalid CHIP ID: 0x60
I can't find build/bdist.linux-armv7l/egg/bme680
. I'm using the adafruit bme680 board and the chip id is 0xD0. I just dont know where to change this.
Everything is working as it should, except from the gas readings, I always get the exact same number. I am using a generic ESP32 DEVKITV1 (VROOM 32). The sensor is not broken because it works fine when used in a raspberry pi. So it is got to do with Micropython? I followed instructions from here.
This is the code I have used:
import bme680
from i2c import I2CAdapter
import machine
i2c_dev = I2CAdapter(scl=machine.Pin(22),sda=machine.Pin(21))
sensor = bme680.BME680(i2c_device=i2c_dev)
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)
while True:
if sensor.get_sensor_data():
output = "{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
if sensor.data.heat_stable:
print("{0},{1} Ohms".format(output, sensor.data.gas_resistance))
else:
print(output)
time.sleep(1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.