SparkFun BME280: an example that runs
Yes. You can use the SparkFun 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, "Basic readings from a BME280 with the SparkFun library", runs on the Arduino Uno R3.
Built in on Mokxi: #include <SparkFunBME280.h> and it builds, with nothing to install. Free, and no account needed.
What SparkFun BME280 does
The BME280 the SparkFun way, in Fahrenheit and feet too, with the dew point, the calibration values and readRegister(). That is what SparkFun BME280 covers. The sketch below uses it on the Arduino Uno: “Basic readings from a BME280 with the SparkFun library”.
begin() returns the chip id, 0x60 or 0x58, or 0 when nothing answered; beginI2C() returns whether it worked.
The altitude is worked in integers against the reference pressure, 101325 Pa unless setReferencePressure() says otherwise.
The calls follow release 2.0.11 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 | SparkFun BME280 |
|---|---|
| Author | SparkFun |
| Include | #include <SparkFunBME280.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 <SparkFunBME280.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "SparkFun BME280" by SparkFun from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add SparkFun BME280 to lib_deps in PlatformIO. Mokxi follows the calls of release 2.0.11, so a sketch written here builds there too.
What to know in the simulator: The bme280 part is wired by I2C, so beginSPI() returns false.
- 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 mySensor
Makes mySensor, the BME280 object the calls below are made on.
mySensor.setI2CAddress(0x76)
Sets the i2c address to the value you pass in. Arguments: address.
mySensor.readFloatHumidity()
Returns the float humidity as a decimal number.
mySensor.readFloatPressure()
Returns the float pressure as a decimal number.
mySensor.readFloatAltitudeMeters()
Returns the float altitude meters as a decimal number.
mySensor.readTempC()
Returns TempC as a decimal number.
BME280_SensorMeasurements measurements
Declares measurements, a BME280_SensorMeasurements that the example uses.
Example: Basic readings from a BME280 with the SparkFun library
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <Wire.h>
#include "SparkFunBME280.h"
BME280 mySensor;
void setup() {
Serial.begin(115200);
Serial.println("Reading basic values from BME280");
Wire.begin();
mySensor.setI2CAddress(0x76); // the address jumper closed, as on most modules
if (mySensor.beginI2C() == false) {
Serial.println("The sensor did not respond. Please check wiring.");
while (1);
}
}
void loop() {
Serial.print("Humidity: ");
Serial.print(mySensor.readFloatHumidity(), 0);
Serial.print(" Pressure: ");
Serial.print(mySensor.readFloatPressure(), 0);
Serial.print(" Alt: ");
Serial.print(mySensor.readFloatAltitudeMeters(), 1);
Serial.print(" Temp: ");
Serial.print(mySensor.readTempC(), 2);
Serial.println();
BME280_SensorMeasurements measurements;
mySensor.readAllMeasurements(&measurements, 1); // 1: Fahrenheit
Serial.print("All at once: ");
Serial.print(measurements.temperature, 1);
Serial.println(" F");
delay(500);
}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 SparkFun BME280 without installing anything
Open the example, change the sketch, and keep your version in a free account.