Grove - Barometer Sensor BME280: an example that runs
Yes. You can use the Grove - Barometer Sensor 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 Grove BME280: temperature, pressure, altitude and humidity", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Seeed_BME280.h> and it builds, with nothing to install. Free, and no account needed.
What Grove - Barometer Sensor BME280 does
The Grove BME280: BME280 bme280, init(), getTemperature(), getPressure() in pascals, getHumidity() and calcAltitude(). That is what Grove - Barometer Sensor BME280, by Seeed Studio, covers. The sketch below uses it on the Arduino Uno: “The Grove BME280: temperature, pressure, altitude and humidity”.
Seeed Studio's library for the Grove Temp&Humi&Barometer sensor, a Bosch BME280 on I2C.
init() looks for chip id 0x60 five times, 100 ms apart, printing "Read Chip ID fail!" when it is not there (so a BMP280 is refused, as upstream), reads the coefficients and starts normal mode with every measurement at 16x. The readings are 0 while the sensor does not answer.
The calls follow release 1.0.2 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 name | Grove - Barometer Sensor BME280 |
|---|---|
| Author | Seeed Studio |
| Include | #include <Seeed_BME280.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Pressure, humidity and temperature, BME280 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Seeed_BME280.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Grove - Barometer Sensor BME280" by Seeed Studio from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Grove - Barometer Sensor BME280 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.2, so a sketch written here builds there too.
What to know in the simulator: init() takes only a BME280 (chip id 0x60), as upstream. The class is named BME280, as the SparkFun and finitespace libraries name theirs, so only one fits in a sketch.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
BME280 bme280
Makes bme280, the BME280 object the calls below are made on.
bme280.init()
Starts it up and returns true if it started, false if it did not. Call it once in setup().
bme280.getTemperature()
Returns the temperature as a decimal number.
bme280.getPressure()
Returns the pressure as a decimal number.
bme280.getHumidity()
Returns the humidity as a decimal number.
Example: The Grove BME280: temperature, pressure, altitude and humidity
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include "Seeed_BME280.h"
#include <Wire.h>
BME280 bme280;
void setup() {
Serial.begin(9600);
if (!bme280.init()) {
Serial.println("Device error!");
}
}
void loop() {
float pressure;
// temperature
Serial.print("Temp: ");
Serial.print(bme280.getTemperature());
Serial.println("C");
// atmospheric pressure
Serial.print("Pressure: ");
Serial.print(pressure = bme280.getPressure());
Serial.println("Pa");
// altitude
Serial.print("Altitude: ");
Serial.print(bme280.calcAltitude(pressure));
Serial.println("m");
// humidity
Serial.print("Humidity: ");
Serial.print(bme280.getHumidity());
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
Keep going
Try Grove - Barometer Sensor BME280 without installing anything
Open the example, change the sketch, and keep your version in a free account.