Adafruit BMP3XX Library: an example that runs
Yes. You can use the Adafruit BMP3XX Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Pressure sensor, BMP388). The example below, "Temperature, pressure and altitude from a BMP388", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_BMP3XX.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit BMP3XX Library does
The BMP388 and BMP390 barometers on I2C or SPI: begin_I2C(), begin_SPI(), the oversampling, IIR filter and data rate, performReading() into temperature and pressure, and readAltitude(). That is what Adafruit BMP3XX Library covers. The sketch below uses it on the Arduino Uno: “Temperature, pressure and altitude from a BMP388”.
The Adafruit BMP3XX library's interface, for the Bosch BMP388 and BMP390 barometric pressure and temperature sensors.
The bmp388 part answers all of it: the chip id 0x50 at 0x00, the soft reset, the 21 trimming bytes from 0x31, a forced conversion that takes the datasheet's time for the oversampling, and the six data bytes from 0x04. There is no BMP390 part. With nothing at the address begin_I2C() returns false and performReading() fails.
The calls follow release 2.1.6 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 | Adafruit BMP3XX Library |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_BMP3XX.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 sensor, BMP388 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Adafruit_BMP3XX.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit BMP3XX Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit BMP3XX Library to lib_deps in PlatformIO. Mokxi follows the calls of release 2.1.6, so a sketch written here builds there too.
What to know in the simulator: Over I2C at 0x77, or 0x76 with SDO to GND: the readings are the sliders, to the bit at the oversampling set; the real part is within 0.5 hPa typically. There is no BMP390 part, and begin_SPI() finds no chip. The BMP3_ constants of Bosch’s bmp3_defs.h are defined in the header; bmp3.h itself is not here.
- 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.
Adafruit_BMP3XX bmp
Makes bmp, the Adafruit_BMP3XX object the calls below are made on.
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X)
Sets the temperature oversampling to the value you pass in.
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X)
Sets the pressure oversampling to the value you pass in.
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3)
Sets the iir filter coeff to the value you pass in.
bmp.setOutputDataRate(BMP3_ODR_50_HZ)
Sets the output data rate to the value you pass in.
bmp.readAltitude(SEALEVELPRESSURE_HPA)
Returns the altitude as a decimal number. Arguments: sea level.
Example: Temperature, pressure and altitude from a BMP388
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BMP3XX bmp;
void setup() {
Serial.begin(115200);
Serial.println("Adafruit BMP388 / BMP390 test");
if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);
}
// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop() {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
Serial.print("Temperature = ");
Serial.print(bmp.temperature);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.pressure / 100.0);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
delay(2000);
}Wiring
- Arduino Uno R3 A4 to Pressure sensor, BMP388 SDA
- Arduino Uno R3 A5 to Pressure sensor, BMP388 SCL
- Arduino Uno R3 5V to Pressure sensor, BMP388 VIN
- Arduino Uno R3 GND to Pressure sensor, BMP388 GND
Projects that use Adafruit BMP3XX Library
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Keep going
Try Adafruit BMP3XX Library without installing anything
Open the example, change the sketch, and keep your version in a free account.