Arduino library for interfacing with the BMP388 barometric pressure sensor which can be used for inferring altitude information.
This library works for
- ArduinoCore-samd:
Arduino Zero
,MKR 1000
,MKR WiFi 1010
,Nano 33 IoT
,MKR GSM 1400
,MKR NB 1500
,MKR WAN 1300/1310
✔️ - ArduinoCore-mbed:
Portenta H7
,Nano 33 BLE
,Nano RP2040 Connect
,Edge Control
✔️ - arduino-esp32:
ESP32 Dev Module
,ESP32 Wrover Module
, ... ✔️ - ArduinoCore-renesas:
Portenta C33
,Uno R4 WiFi
,Uno R4 Minima
, ... ✔️
#include <SPI.h>
#include <107-Arduino-BMP388.h>
/* ... */
static int const BMP388_CS_PIN = 2;
static int const BMP388_INT_PIN = 6;
/* ... */
using namespace drone;
/* ... */
ArduinoBMP388 bmp388([](){ digitalWrite(BMP388_CS_PIN, LOW); },
[](){ digitalWrite(BMP388_CS_PIN, HIGH); },
[](uint8_t const d) -> uint8_t { return SPI.transfer(d); },
[](unit::Pressure const pressure)
{
Serial.print(pressure.value() / 100.0);
Serial.print(" hPa / ");
Serial.print(ArduinoBMP388::convertPressureToAltitude(pressure).value());
Serial.println(" m");
},
[](unit::Temperature const temperature)
{
Serial.print(temperature.value() + 273.15);
Serial.println(" °C");
});
/* ... */
void setup()
{
Serial.begin(9600);
while(!Serial) { }
SPI.begin();
pinMode(BMP388_CS_PIN, OUTPUT);
digitalWrite(BMP388_CS_PIN, HIGH);
pinMode(BMP388_INT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BMP388_INT_PIN), [](){ bmp388.onExternalEventHandler(); }, FALLING);
bmp388.begin(BMP388::OutputDataRate::ODR_12_5_Hz);
}
void loop()
{
}