forcedBMX280: an example that runs
Yes. You can use the forcedBMX280 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, "A BME280 woken for one measurement every two seconds, in whole numbers", runs on the Arduino Uno R3.
Built in on Mokxi: #include <forcedBMX280.h> and it builds, with nothing to install. Free, and no account needed.
What forcedBMX280 does
ForcedBME280Float and its smaller siblings: begin(), takeForcedMeasurement(), the temperature in hundredths, pressure in pascals and humidity in hundredths, and their float versions. That is what forcedBMX280, by soylentOrange, covers. The sketch below uses it on the Arduino Uno: “A BME280 woken for one measurement every two seconds, in whole numbers”.
SoylentOrange's Forced-BMX280 library, a small forced-mode driver for the Bosch BME280 and BMP280, made for the ATtiny85.
It reads Mokxi's bme280 part (and a bmp280).
The calls follow release 1.1.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 | forcedBMX280 |
|---|---|
| Author | soylentOrange |
| Include | #include <forcedBMX280.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, Pressure and temperature, BMP280 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <forcedBMX280.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "forcedBMX280" by soylentOrange from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add forcedBMX280 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.2, so a sketch written here builds there too.
What to know in the simulator: As upstream, a reading comes from the measurement before it, since nothing waits for the conversion. The header takes TinyWireM on an ATtiny85, but a sketch that prints the readings does not fit its 8 KB.
- 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.
ForcedBME280 climateSensor
Makes climateSensor, the ForcedBME280 object the calls below are made on.
climateSensor.begin()
Starts it up. Call it once in setup().
climateSensor.getChipID()
Returns the chip id as a whole number.
climateSensor.getTemperatureCelsius()
Returns the temperature celsius as a whole number. Arguments: perform measurement.
climateSensor.getPressure()
Returns the pressure as a whole number. Arguments: perform measurement.
climateSensor.getRelativeHumidity()
Returns the relative humidity as a whole number. Arguments: perform measurement.
Example: A BME280 woken for one measurement every two seconds, in whole numbers
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <Wire.h>
#include "forcedBMX280.h"
// temperature, pressure and humidity as integers: 1234 is 12.34
ForcedBME280 climateSensor = ForcedBME280();
int32_t g_temperature; // current temperature
uint32_t g_pressure; // current pressure
uint32_t g_humidity; // current humidity
void setup() {
Serial.begin(115200);
// start I2C and BME sensor
Wire.begin();
while (climateSensor.begin()) {
Serial.println("Waiting for sensor...");
delay(1000);
}
Serial.println("BMX280 ready");
Serial.print("\tChipID: 0x");
Serial.println(climateSensor.getChipID(), HEX);
}
void loop() {
delay(2000);
climateSensor.takeForcedMeasurement();
g_temperature = climateSensor.getTemperatureCelsius();
Serial.print("Temperature: ");
Serial.print(g_temperature / 100);
Serial.print(".");
Serial.print(g_temperature % 100);
Serial.println(" C");
g_pressure = climateSensor.getPressure();
Serial.print("Pressure: ");
Serial.print(g_pressure / 100);
Serial.print(".");
Serial.print(g_pressure % 100);
Serial.println(" hPa");
g_humidity = climateSensor.getRelativeHumidity();
Serial.print("Humidity: ");
Serial.print(g_humidity / 100);
Serial.print(".");
Serial.print(g_humidity % 100);
Serial.println(" %rh");
}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 forcedBMX280 without installing anything
Open the example, change the sketch, and keep your version in a free account.