I2C Sensors Part Deux

BME-680 Sensor
 I found my BME680 sensor module in the clutter on my workbench this week, so let's extend the previous project to include the additional features of the BME680.  First we will need to wire it to the Pi.  Since it has the same electrical interface, we can just pull the patch wires off the BMP280 and move them to the BME680.   Once again, we have from the BME to the Pi: Vcc to 3V3 (1), SDA to SDA (3), SCL to SCL(5), and GND to GND (6).

If you recall from the previous tutorial, there was some question of what the I2C bus address for the module would be, so once we get the hardware installed, we will probe the bus for addresses to make sure we know which one we got.  In the case of my sensor pictured above:

$ sudo 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

So this module is at the default 0x77 address.  We'll note that in the test program.

We will need the Adafruit library specific to the BME-680 to get the added functionality.  Update your system if it's been more than a few days, then:

$ sudo pip3 install adafruit-circuitpython-bme680

Next, I will copy the BMP280 test program, so we can leave the original untouched for comparison:

$ cp bmp280test.py bme680test.py

Now we can edit the BME680 program.  If you just change all instances of bmp280 to bme680 and BMP280 to BMP680, and fix the address, the program will run!  It will, of course, only give you the readings that were available in the BMP280, because that is all the program knows about.  This is due partly to the regularity of the I2C protocol implemented by the Bosch devices, but also in large part to good programming by the Adafruit library developers.

We can get the two additional readings available from the BMP680 with:

    print("Gas: %d ohm" % bme680.gas)
    print("Humidity: %0.1f %%" % bme680.relative_humidity)

With that, the full program (running) now looks like:


The source code is available in this gist.

The Adafruit page on their BME680 sensor has quite a bit of additional information on this versatile sensor, including some hints on how to calibrate the sensor.  I also recommend their sensor modules, especially if you are a beginner, as their quality and support is outstanding.


Comments

Popular posts from this blog

I2C Sensors are fun and easy