This is a current in-progress project. Actually it’s half of a project, but I’ve separated it into two parts because some people may wish to do just one part using individual components. This project is based round a Mikroe mikroBUS module called ‘13DOF2 Click’. This small board has two sensor chips:
- BME680 - This has temperature, humidity, atmospheric pressure and air quality sensors onboard. I’m primarily interested in this for air quality data, but the T/H/P readings may be of use, e.g. to get a better indoor temperature reading then the Davis VP2 console gives because that tends to read high due to internal heating.
- BMX160 - This is a 9-axis sensor consisting of a 3-axis, low-g accelerometer, a low power 3-axis gyroscope and a 3-axis geomagnetic sensor. It’s intended use is as an orientation sensor, e.g. think they can be used in phones to work out which way up they are and how they’re moving. My initial thoughts for this are to use the accelerometer to make a (probbaly inaccurate) seismometer.
This particular project will cover the BME680 sensors with the BMX160 in another project. The BME680 on the 13DOF2 Click board is described by the manufacturer (Bosch Sensortec) as…
Gas sensor measuring relative humidity, barometric pressure, ambient temperature and gas (VOC).The BME680 is the first gas sensor that integrates high-linearity and high-accuracy gas, pressure, humidity and temperature sensors. It is especially developed for mobile applications and wearables where size and low power consumption are critical requirements. The BME680 guarantees - depending on the specific operating mode - optimized consumption, long-term stability and high EMC robustness. In order to measure air quality for personal wellbeing the gas sensor within the BME680 can detect a broad range of gases such as volatile organic compounds (VOC).
Possible use cases are:
[ul] [li]Personal air quality tracker[/li] [li]Air quality mapping[/li] [li]Air quality inside cars & public transport[/li] [li]Indicator of too high / low humidity[/li] [li]Air quality & well-being indicator[/li] [li]Weather trends[/li] [/ul]
The project is currently using module parts, which means that in it’s simplest form it’s more or less plug-and-play. That does mean it’s probably more expensive too. However, if you have the skills you can build it from individual parts which is probably going to be cheaper.
Hardware
- 1*Raspberry Pi - I’m using a 4GB Model 4B but I think this will also work on Model 3 devices with less RAM and possibly Model 2’s too. The GPIO interface on Model 1’s isn’t compatible though. Raspberry Pi’s are available from many sources and I’m treating it as a commodity device so I won’t discuss it too much within the project.
- 1*Mikroe Pi 3 Click Shield - This is a Pi addon board designed to plug into the 40-pin GPIO connector on a Raspberry Pi. It provides two mikroBUS sockets which allow you to plug a wide variety of ‘click boards’ into the Pi. This is a simple way to add sensors onto a Pi, but be aware that Pi software isn’t available for all of the sensor boards so you may have to write your own/adapt other code. You can buy the Pi 3 Click Shield direct from Mikroe Pi 3 Click Shield in the US, and also some electronics suppliers in other countries, e.g. RS Components or Farnell in the UK. Note that whilst this is called a ‘Pi 3’ shield it is also compatible with the Pi 4 (and I think the Pi 2).
- 1*Mikroe 13DOF2 Click board - This is a mikroBUS module that plugs into the Pi 3 Click Shield. It has a Bosch Sensortec BME680 and a Bosch Sensortec BMX160 built onto the module with supporting components. You can buy the 13DOF2 Click direct from Mikroe 13DOF2 Click in the US, and also some electronics suppliers in other countries, e.g. Mouser Electronics or Digi-Key Electronics in the UK.
Assembly
- Plug the Pi 3 Click Shield onto the 40-pin GPIO connector on the Pi. Follow the instructions for the Click Shield for how to do this. Note: Make sure your Pi is turned off when you do this!
- Plug the 13DOF2 Click board into one of the sockets on the Click Shield. It will work in either socket. Mine is plugged into socket 1 because I have another module plugged into socket 2 (see my Lightning Detector project). Ensure the the small GPIO/ADC switch on the Click Shield for the socket you choose is set to GPIO. This should be the default out of the box setting. Note: Make sure your Pi is turned off when you do this!
- Turn on your Pi. After the Pi has started to boot up you should see the green LED on the 13DOF3 Click board light up.
- That’s it for assembly. The rest is down to software.
Software
As mentioned above, not all Click Boards have software available for them on the Raspberry Pi. This is true in the case of the 13DOF2 Click board. There is some software available to use the BME680 which I’ve checked works on the Raspberry Pi.
There are a number of steps included in the software setup…
- Enable I2C on the Raspberry Pi. See https://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/
- I’m using Python 3 to access the BME680. If you’re running Raspberry Pi OS (previously called Raspbian OS) then you should have both Python2, Python 3 and pip installed by default. If you’re using another OS or installed a version of the Raspberry Pi OS without Python 3 and pip included please install them using the appropriate method for your OS.
- Create a directory “/home/pi/Sensors” for the other software. You can name the directory as you wish, but I’m using Sensors here so that I can refer to it consistently.
The next steps start to cover the Python software. This is still a work in progress for me. For now, I’ve included basic Python code to read data from the BME680 and output it to the terminal window.
- [li]Install the BME680 Python support libraries. Enter ‘pip3 install bme680’.
- Download the three attached files and place in the Sensors directory. Rename each file from .txt to .py
In the Sensors directory run the ‘temp-press-hum.py’ script using:
python3 temp-press-hum.py
This will display something like the info below. The temperature, pressure and humidity will be read rapidly and output.
pi@IOT-DevPi:~/Sensors $ python3 temp-press-hum.py Display Temperature, Pressure and HumidityIf you don’t need gas readings, then you can read temperature,
pressure and humidity quickly.Press Ctrl+C to exit
Polling:
30.95 C,1017.71 hPa,30.877 %RH
30.95 C,1017.70 hPa,30.883 %RH
30.96 C,1017.68 hPa,30.891 %RH
30.97 C,1017.70 hPa,30.897 %RH
30.98 C,1017.68 hPa,30.893 %RH
30.99 C,1017.70 hPa,30.898 %RH
31.00 C,1017.68 hPa,30.891 %RH
The temperature (indoor) in my case is high because the module is mounted just above the Pi board so the CPU is heating it. I need to change the construction to keep the sensor at ambient temperature and maybe use a small fan to keep a good airflow past the sensor.
Next run the ‘read-all.py’ script using:
python3 read-all.py
This will display something like the info below. The temperature, pressure, humidity and gas sensor resistance will be read and output along with with various other calibration data from the sensor chip.
pi@IOT-DevPi:~/Sensors $ python3 read-all.py Calibration data: par_gh1: -19 par_gh2: -10936 par_gh3: 18 par_h1: 752 par_h2: 1015 par_h3: 0 par_h4: 45 par_h5: 20 par_h6: 120 par_h7: -100 par_p1: 37097 par_p10: 30 par_p2: -10661 par_p3: 88 par_p4: 7496 par_p5: -93 par_p6: 30 par_p7: 59 par_p8: -4684 par_p9: -1762 par_t1: 26128 par_t2: 26190 par_t3: 3 range_sw_err: 15 res_heat_range: 1 res_heat_val: 45 t_fine: 157742Initial reading:
gas_index: 0
gas_resistance: 6877278.729487992
heat_stable: False
humidity: 32.409
meas_index: 0
pressure: 1017.73
status: 32
temperature: 30.81Polling:
30.81 C,1017.71 hPa,32.40 %RH
30.84 C,1017.68 hPa,32.32 %RH,10496.02229501644 Ohms
30.89 C,1017.70 hPa,32.18 %RH,19326.876846977095 Ohms
Next run the ‘indoor-air-quality.py’ script using:
python3 indoor-air-quality.py
This will display something like the info below. Initially, the gas sensor resistance will be output during a 5 minute burn-in period.
pi@IOT-DevPi:~/Sensors $ python3 indoor-air-quality.py Estimate indoor air qualityRuns the sensor for a burn-in period, then uses a
combination of relative humidity and gas resistance
to estimate indoor air quality as a percentage.Press Ctrl+C to exit
Collecting gas resistance burn-in data for 5 mins
Gas: 15248.344819637847 Ohms
Gas: 28410.649474385635 Ohms
Gas: 37735.37908410996 Ohms
Gas: 49805.362637590595 Ohms
Gas: 59768.48940398531 Ohms
After 5 minutes the display changes to show…
Gas: 297539.15229069436 Ohms Gas: 296524.39794535004 Ohms Gas: 297030.9084362385 Ohms Gas baseline: 297012.87933643296 Ohms, humidity baseline: 40.00 %RHGas: 297284.81 Ohms,humidity: 30.22 %RH,air quality: 93.89
Gas: 299847.94 Ohms,humidity: 30.20 %RH,air quality: 93.87
Gas: 298817.40 Ohms,humidity: 30.18 %RH,air quality: 93.86
Gas: 298817.40 Ohms,humidity: 30.17 %RH,air quality: 93.86
Gas: 301407.14 Ohms,humidity: 30.15 %RH,air quality: 93.84
Gas: 298817.40 Ohms,humidity: 30.15 %RH,air quality: 93.84
Gas: 296777.44 Ohms,humidity: 30.17 %RH,air quality: 93.80
The air quality value is calculated by the chip and humdity is part of the calculation. If you prefer it dryer or damper than 40% RH then I believe you can adjust the 40% to your preferred value but I haven’t tried that yet.
The 5 minute burn-in period happens each time you start the script, so the air quality data is best read by a script that runs 24*7 to avoid gaps in the data, or perhaps you could only read air quality data every 5 minutes (or longer)?
The next steps are to write more Python code to use the data, e.g. to output it to screen, send it to another program or create a web page containing the data (or anything else you can think of that would be a useful way to use the data). It may also be necessary to adjust/fine tune some sensor parameters but I haven’t investigate that yet.
I’ve not done any more coding yet, but I’ll post what I do write when I’ve written it. If you understand Python then you probably have enough info to move forward on your own from this point.
temp-press-hum.py.txt (842 Bytes)
indoor-air-quality.py.txt (2.93 KB)
read-all.py.txt (1.63 KB)