Home

Awesome

BMP280/BME280 sensor library for Arduino

Build Status

This is a BMP280/BME280 temperature/pressure/humidity sensor library for Arduino.

BMX280

Arduino library features

BMP280/BME280 sensor specifications

Hardware

Connection Arduino board - BMX280 sensor

Pins board - BMX280VCCGNDSDASCL
Arduino UNO (ATMega328 boards)5VGNDA4A5
Arduino Mega25605VGNDD20D21
Arduino Leonardo5VGNDD2D3
Arduino DUE (ATSAM3X8E)3V3GND2021
ESP82663V3GNDGPIO4 (D2)GPIO5 (D1)
ESP323V3GNDGPIO21GPIO22

Other unlisted MCU's may work, but are not tested.

Examples

Examples | Erriez BMP280/BME280 sensor:

Documentation

Example

#include <Wire.h>
#include <ErriezBMX280.h>

// Adjust sea level for altitude calculation
#define SEA_LEVEL_PRESSURE_HPA      1026.25

// Create BMX280 object I2C address 0x76 or 0x77
ErriezBMX280 bmx280 = ErriezBMX280(0x76);


void setup()
{
    // Initialize serial
    delay(500);
    Serial.begin(115200);
    while (!Serial) {
        ;
    }
    Serial.println(F("\nErriez BMP280/BMX280 example"));

    // Initialize I2C bus
    Wire.begin();
    Wire.setClock(400000);

    // Initialize sensor
    while (!bmx280.begin()) {
        Serial.println(F("Error: Could not detect sensor"));
        delay(3000);
    }

    // Print sensor type
    Serial.print(F("\nSensor type: "));
    switch (bmx280.getChipID()) {
        case CHIP_ID_BMP280:
            Serial.println(F("BMP280\n"));
            break;
        case CHIP_ID_BME280:
            Serial.println(F("BME280\n"));
            break;
        default:
            Serial.println(F("Unknown\n"));
            break;
    }
}

void loop()
{
    Serial.print(F("Temperature: "));
    Serial.print(bmx280.readTemperature());
    Serial.println(" C");

    if (bmx280.getChipID() == CHIP_ID_BME280) {
        Serial.print(F("Humidity:    "));
        Serial.print(bmx280.readHumidity());
        Serial.println(" %");
    }

    Serial.print(F("Pressure:    "));
    Serial.print(bmx280.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print(F("Altitude:    "));
    Serial.print(bmx280.readAltitude(SEA_LEVEL_PRESSURE_HPA));
    Serial.println(" m");

    Serial.println();

    delay(1000);
}

Output

Erriez BMP280/BMX280 example

Sensor type: BME280

Temperature: 28.50 C
Humidity:    45.13 %
Pressure:    1024.88 hPa
Altitude:    11.27 m

Temperature: 28.55 C
Humidity:    45.21 %
Pressure:    1024.89 hPa
Altitude:    11.21 m

...

Set sampling

The sensor sampling and mode can be configured with function setSampling(). Recommended modes of operation according to the datasheet chapter "Recommended modes of operation":

// Set sampling
//
// Weather
//  - forced mode, 1 sample / minute
//  - pressure ×1, temperature ×1, humidity ×1
//  - filter off
//
// Humidity sensing
//  - forced mode, 1 sample / second
//  - pressure ×0, temperature ×1, humidity ×1
//  - filter off
//
// Indoor navigation
//  - normal mode, t standby = 0.5 ms
//  - pressure ×16, temperature ×2, humidity ×1
//  - filter coefficient 16
//
// Gaming
//  - forced mode, t standby = 0.5 ms
//  - pressure ×1, temperature ×1, humidity ×1
//  - filter off
bmx280.setSampling(BMX280_MODE_NORMAL,    // SLEEP, FORCED, NORMAL
                   BMX280_SAMPLING_X16,   // Temp:  NONE, X1, X2, X4, X8, X16
                   BMX280_SAMPLING_X16,   // Press: NONE, X1, X2, X4, X8, X16
                   BMX280_SAMPLING_X16,   // Hum:   NONE, X1, X2, X4, X8, X16 (BME280)
                   BMX280_FILTER_X16,     // OFF, X2, X4, X8, X16
                   BMX280_STANDBY_MS_500);// 0_5, 10, 20, 62_5, 125, 250, 500, 1000

Library dependencies

Library installation

Please refer to the Wiki page.

Other Arduino Libraries and Sketches from Erriez