obniz Parts Library

BMP280

GitHub
BMP280
Usable Devices :
obniz_board

Temperature Sensor - BMP280

Temperature / Humidity / Air pressure sensor.
Very low energy consumption and high accuracy.

wired(obniz, {[vio, vcore, gnd, csb, sdi, sck, sdo, address, i2c]} )

Connect a sensor to an obniz Board.
obniz Board has internal pull up. But for communication stability, please add pull-up resistor to both SCK and SDI.

name type required default description
vio number(obniz Board io) no   connected obniz Board io. power supply for interface
vcore number(obniz Board io) no   connected obniz Board io. power supply for core
gnd number(obniz Board io) no   connected obniz Board io. power supply
csb number(obniz Board io) no   connected obniz Board io. I2C/SPI selection.
sdi number(obniz Board io) no   connected obniz Board io. data port
sck number(obniz Board io) no   connected obniz Board io. clock
sdo number(obniz Board io) no   connected obniz Board io. data port or address selection
i2c i2c object no   configured i2c object
address number no 0x76 0x76 or 0x77

This library use I2C to communicate.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
const val = await bmp280.getAllWait();
console.log(val);

vio and vcore can be connected.
csb can be connected to high simply, and sdo can be connected to low.
So, minimum connection and configration is.

// Javascript Example

// vcore connected to vio
// csb connected to vio
// sdo connected to gnd

var bmp280 = obniz.wired("BMP280", {vio:0, gnd:1, sdi: 2, sck: 3 });
await bmp280.applyCalibrationWait();
const val = await bmp280.getAllWait();
console.log(val);

Or you can use i2c object

// Javascript Example

var i2c = obniz.getFreeI2C();
i2c.start({mode:"master", sda:2, scl:3, clock:100000}); 

var bmp280 = obniz.wired("BMP280", {vio:0, gnd:1, i2c: i2c });

If you configured a chip to use address 0x77 (by pull-up sdo)

// Javascript Example

var bmp280 = obniz.wired("BMP280", {vio:0, gnd:1, sdi: 2, sck: 3, address: 0x77});

[await] applyCalibrationWait()

Retrive factory stored calibration data from connected chip.
You can use BMP280 without calling this, But You should do for better accuracy.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();

[await] setIIRStrength()

configure of internal IIR filter. 0 to 4.

0 for disable IIR filter.(default)

IIR filter makes more stable and accurate result.
But you should wait for get more accurate result.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
await bmp280.setIIRStrengthWait(1); // start using minimum IIR 

[await] getAllWait()

get all values.

  • temperature: celcius
  • humidity: %
  • pressure: hPa
// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
const obj = await bmp280.getAllWait();
console.log('temp: ' + obj.temperature + ' degree');
console.log('pressure: ' + obj.pressure + ' hPa');

[await] getPressureWait()

get pressure values.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
console.log('pressure: ' + await bmp280.getPressureWait() + ' hPa');

[await] getTempWait()

get temperature values.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
console.log('temp: ' + await bmp280.getTempWait() + ' degree');

calcAltitude(pressure, seaPressure)

Utility function for calcurate accuracy using air pressure.
Unit is m.

// Javascript Example
// Please pullup sdi and sck.
var bmp280 = obniz.wired("BMP280", {vio:0, vcore:1, gnd:2, csb:3, sdi: 4, sck: 5, sdo:6 });
await bmp280.applyCalibrationWait();
const obj = await bmp280.getAllWait();
const airPressure = obj.pressure;
const hight_in_m = bmp280.calcAltitude(airPressure);
console.log('altitude: ' + hight_in_m + ' m');

Supported from: obniz.js 3.5.0