BME680 Environment sensor
This module reads temperature, humidity, pressure and gas quality from Bosch Sensortec's BME680 sensor.
Wiring
To wire for I2C:
BME680 Pin | Espruino |
---|---|
1 (GND) | GND |
2 (CSB) | 3.3v (forces I2C mode) |
3 (SDI) | SDA pin (A6 in example) |
4 (SCK) | SCL pin (A7 in example) |
5 (SDO) | GND (default address) |
6 (VDDIO) | 3.3v |
7 (GND) | GND |
8 (VDD) | 3.3v |
The BME680 can run off 1.8v to 3.6v so can be connected directly to 3.3v (however some breakout boards contain a voltage regulator).
Software
BME680 Reset
Creating a new BME680 class - either by calling connectI2C
, connectSPI
, or directly calling new BME680()
- issues a reset to the BME680 device, and it won't be available for roughly 10ms.
The error is Cannot read property 'cal_t' of undefined...
Use the setInterval
method like in the examples, or a setTimeout
with more than 10ms, it will work.
I2C
We're using software I2C here so you can use any pins, but you could
easily use a hardware I2C device such as I2C1
.
var i2c = new I2C();
i2c.setup({sda:A6,scl:A7});
var bme = require("BME680").connectI2C(i2c);
setInterval(function() {
var data = bme.get_sensor_data();
console.log(JSON.stringify(data,null,2));
bme.perform_measurement();
}, 1000);
Prints data of the form:
{
"new": true, // is this a new measurement?
"temperature": 20.9, // degrees C
"pressure": 990.7, // hPa
"humidity": 52.425, // % rH
"gas_resistance": 95197 // Ohms
}
The first reading is done automatically, but subsequent readings
must be performed by calling bme.perform_measurement()
. The result
will then be available 1 second later.
Different I2C addresses
The BME680's default address is 0x76 (which you get when SDO is connected to GND). If SDO is connected to VDD the address can be forced to 0x77.
You can specify this new address with:
var bme = require("BME680").connectI2C(i2c, {addr:0x77});
SPI
For usage with SPI, the BME680 module can be intialised as follows:
var spi = new SPI();
spi.setup({miso : ..., mosi : ..., sck: ...});
var bme = require("BME680").connectSPI(spi, cs_pin);
setInterval(function() {
var data = bme.get_sensor_data();
console.log(JSON.stringify(data,null,2));
bme.perform_measurement();
}, 1000);
Low-level
The BME680
class is also exposed via require("BME680").BME680
so that
you can initialise it with your own read/write functions if needed.
Reference
BME680.prototype.soft_reset = function (callback) { ... }
BME680.prototype.get_calib_data = function () { ... }
BME680.prototype.set_sensor_mode = function (mode) { ... }
// filter, heatr_ctrl, os_temp, os_pres, os_hum, run_gas, nb_conv
BME680.prototype.set_sensor_settings = function (options) { ... }
BME680.prototype.set_heating_settings = function (tmp, dur, cnv) { ... }
// get duration in milliseconds needed before a reading
BME680.prototype.get_profile_dur = function (options) { ... }
/* Return data:
new // is this a new measurement?
temperature // degrees C
pressure // hPa
humidity // % rH
gas_resistance // Ohms
*/
BME680.prototype.get_sensor_data = function () { ... }
// Request the sensor takes another reading
BME680.prototype.perform_measurement = function () { ... }
BME680.prototype.calc_temperature = function (temp_adc) { ... }
BME680.prototype.calc_pressure = function (pres_adc) { ... }
BME680.prototype.calc_humidity = function (hum_adc) { ... }
BME680.prototype.calc_gas_resistance = function (gas_res_adc, gas_range) { ... }
BME680.prototype.calc_heater_resistance = function (temperature) { ... }
BME680.prototype.calc_heater_duration = function (duration) { ... }
function (options, read, write) { ... }
exports.connectI2C = function (i2c, options) { ... }
exports.connectSPI = function (spi, cs, options) { ... }
Using
(No tutorials are available yet)
Buying
BME680 ICs are too small to easily hand-solder, so we'd recommend buying them on a breakout board:
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.