Arduino library · Sensors

BlueDot BME280 Library: an example that runs

Yes. You can use the BlueDot BME280 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Pressure, humidity and temperature, BME280). The example below, "The BlueDot weather station: temperature, humidity, pressure, altitude", runs on the Arduino Uno R3.

Built in on Mokxi: #include <BlueDot_BME280.h> and it builds, with nothing to install. Free, and no account needed.

What BlueDot BME280 Library does

BlueDot_BME280 with its parameter struct: init(), readTempC(), readTempF(), readHumidity(), readPressure() in hPa and readAltitudeMeter() and readAltitudeFeet(). That is what BlueDot BME280 Library covers. The sketch below uses it on the Arduino Uno: “The BlueDot weather station: temperature, humidity, pressure, altitude”.

BlueDot's BME280 library, for the Bosch BME280 on I2C, hardware SPI or bit-banged SPI.

init() reads the coefficients, writes the filter, the oversampling and the mode, and returns the chip id: 0x60 for a BME280. Each register is read on its own, as upstream does. readPressure() and readHumidity() use the temperature of the last readTempC() or readTempF(), so read that first; readPressure() reads it itself.

The calls follow release 1.0.9 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameBlueDot BME280 Library
AuthorBlueDot
Include#include <BlueDot_BME280.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesPressure, humidity and temperature, BME280

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <BlueDot_BME280.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "BlueDot BME280 Library" by BlueDot from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add BlueDot BME280 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.9, so a sketch written here builds there too.

What to know in the simulator: The software and hardware SPI modes talk to the bus, but the bme280 part is wired by I2C, so init() does not return 0x60 there. Pressure comes from the int32 formula.

The calls you will use

In the order a sketch meets them.

BlueDot_BME280 bme280

Makes bme280, the BlueDot_BME280 object the calls below are made on.

bme280.init()

Starts it up. Call it once in setup().

bme280.readTempC()

Returns TempC as a decimal number.

bme280.readTempF()

Returns TempF as a decimal number.

bme280.readHumidity()

Returns the humidity as a decimal number.

bme280.readPressure()

Returns the pressure as a decimal number.

bme280.readAltitudeMeter()

Returns the altitude meter as a decimal number.

Example: The BlueDot weather station: temperature, humidity, pressure, altitude

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <Wire.h>
#include "BlueDot_BME280.h"

BlueDot_BME280 bme280 = BlueDot_BME280();

void setup() {
  Serial.begin(9600);
  Serial.println(F("Basic Weather Station"));

  bme280.parameter.communication = 0;          // I2C
  bme280.parameter.I2CAddress = 0x77;          // the module's default address
  bme280.parameter.sensorMode = 0b11;          // normal mode
  bme280.parameter.IIRfilter = 0b100;          // filter coefficient 16
  bme280.parameter.humidOversampling = 0b101;  // 16x
  bme280.parameter.tempOversampling = 0b101;
  bme280.parameter.pressOversampling = 0b101;
  bme280.parameter.pressureSeaLevel = 1013.25; // default value of 1013.25 hPa
  bme280.parameter.tempOutsideCelsius = 15;    // default value of 15 C

  if (bme280.init() != 0x60) {
    Serial.println(F("Ops! BME280 could not be found!"));
    Serial.println(F("Please check your connections."));
    while (1);
  } else {
    Serial.println(F("BME280 detected!"));
  }
  Serial.println();
}

void loop() {
  Serial.print(F("Temperature in Celsius:\t\t"));
  Serial.println(bme280.readTempC());
  Serial.print(F("Temperature in Fahrenheit:\t"));
  Serial.println(bme280.readTempF());
  Serial.print(F("Humidity in %:\t\t\t"));
  Serial.println(bme280.readHumidity());
  Serial.print(F("Pressure in hPa:\t\t"));
  Serial.println(bme280.readPressure());
  Serial.print(F("Altitude in Meters:\t\t"));
  Serial.println(bme280.readAltitudeMeter());
  Serial.println();
  delay(1000);
}

Wiring

  • Arduino Uno R3 A4 to Pressure, humidity and temperature, BME280 SDA
  • Arduino Uno R3 A5 to Pressure, humidity and temperature, BME280 SCL
  • Arduino Uno R3 5V to Pressure, humidity and temperature, BME280 VIN
  • Arduino Uno R3 GND to Pressure, humidity and temperature, BME280 GND

Open it in the editor, wired and ready to run

Try BlueDot BME280 Library without installing anything

Open the example, change the sketch, and keep your version in a free account.