pub struct Bmp390<I> { /* private fields */ }Expand description
A driver for the BMP390 pressure sensor over any I2c implementation.
This driver utilizes uom to provide automatic, type-safe, and zero-cost units of measurement. Measurements can
be retrieved with Bmp390::measure, which returns a Measurement struct containing the pressure, temperature,
and altitude. The altitude is calculated based on the current pressure, standard atmospheric pressure at sea level,
and a reference altitude, which can be set with Bmp390::set_reference_altitude. The reference altitude defaults
to zero, so the default altitude is measured from sea level.
§Example
use bmp390::Bmp390;
let config = bmp390::Configuration::default();
let mut sensor = Bmp390::try_new(i2c, bmp390::Address::Up, delay, &config).await?;
let measurement = sensor.measure().await?;
defmt::info!("Measurement: {}", measurement);A reference altitude can be set to calculate the altitude relative to a different reference point:
let measurement = sensor.measure().await?;
sensor.set_reference_altitude(measurement.altitude);
// Some time later...
let measurement = sensor.measure().await?;
defmt::info!("Altitude: {}", measurement.altitude.get::<uom::si::length::meter>());Implementations§
source§impl<I, E> Bmp390<I>where
I: I2c<Error = E>,
impl<I, E> Bmp390<I>where
I: I2c<Error = E>,
sourcepub async fn try_new<D: DelayNs>(
i2c: I,
address: Address,
delay: D,
config: &Configuration
) -> Result<Self, Error<E>>
pub async fn try_new<D: DelayNs>( i2c: I, address: Address, delay: D, config: &Configuration ) -> Result<Self, Error<E>>
Creates a new BMP390 driver. This will initialize the barometer with the provided configuration. It will additionally delay for 2 ms to allow the barometer to start up and read the calibration coefficients for temperature and pressure measuring.
sourcepub async fn temperature(
&mut self
) -> Result<ThermodynamicTemperature, Error<E>>
pub async fn temperature( &mut self ) -> Result<ThermodynamicTemperature, Error<E>>
Reads the temperature from the barometer.
sourcepub async fn pressure(&mut self) -> Result<Pressure, Error<E>>
pub async fn pressure(&mut self) -> Result<Pressure, Error<E>>
Reads the pressure from the barometer.
sourcepub async fn measure(&mut self) -> Result<Measurement, Error<E>>
pub async fn measure(&mut self) -> Result<Measurement, Error<E>>
Measures the pressure and temperature from the barometer.
sourcepub fn set_reference_altitude(&mut self, altitude: Length)
pub fn set_reference_altitude(&mut self, altitude: Length)
Set the reference altitude for altitude calculations.
Following this, the altitude can be calculated using Bmp390::altitude. If the current pressure matches
the pressure when the reference altitude is set, the altitude will be 0.