BME280 Environment sensor
This module reads values from Bosch Sensortec's BME280 sensor. Use the BME280 module for it.
Note: There is also a BMP280 module, which doesn't include the humidity calculations (which can save a little code space).
Wiring
You can wire this up as follows:
Device Pin | Espruino |
---|---|
1 (GND) | GND |
8 (VCore) | 3.3 |
3 (SDI) | B9(I2C1 SDA) |
4 (SCK) | B8(I2C1 SCL) |
2(CSB) | 3.3 |
5(SDO) | GND |
6(Vio) | 3.3 |
Don't forget to pull-up both of the I2C pins with 10k resistors.
Software
Simple SPI
var spi = new SPI();
spi.setup({miso : ..., mosi : ..., sck: ...});
var bme = require("BME280").connectSPI(spi, cs_pin);
console.log(bme.getData());
// prints { "temp": 23.70573815741, "pressure": 1017.27733597036, "humidity": 42.0771484375 }
Simple I2C
I2C1.setup({scl:B8,sda:B9});
var bme = require("BME280").connect(I2C1);
console.log(bme.getData());
// prints { "temp": 23.70573815741, "pressure": 1017.27733597036, "humidity": 42.0771484375 }
Simple I2C (with Alternative I2C address)
I2C1.setup({scl:B8,sda:B9});
var bme = require("BME280").connect(I2C1,{addr: 0x77}); // use alternate I2C address
console.log(bme.getData());
// prints { "temp": 23.70573815741, "pressure": 1017.27733597036, "humidity": 42.0771484375 }
Manual usage
Sometimes you might want to read the raw data in separately, in which case you can do:
I2C1.setup({scl:B8,sda:B9});
var bme = require("BME280").connect(I2C1);
bme.readRawData();
var temp_cal = bme.calibration_T(bme.temp_raw);
var press_cal = bme.calibration_P(bme.pres_raw);
var hum_cal = bme.calibration_H(bme.hum_raw);
var temp_act = temp_cal / 100.0;
var press_act = press_cal / 100.0;
var hum_act = hum_cal / 1024.0;
console.log("Pressure: " + press_act + " hPa");
console.log("Temperature: " + temp_act + " C");
console.log("Humidity: "+ hum_act+" %");
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.