Crate embedded_qmp6988

Crate embedded_qmp6988 

Source
Expand description

crates.io License Documentation

§embedded-qmp6988

This is a platform agnostic Rust driver the QMP6988 digital barometric pressure sensor using the embedded-hal traits.

§The device

The QMP6988 sensors is high accuracy and small size barometric pressure sensor with low current consumption.

It can be addressed through an I²C or an SPI interface. This driver uses the I²C interface.

§Documentation:

§Features

  • Choose the oversampling setting used for measurements.
  • Choose the IIR filter used to reduce the noise in the measurements.
  • Perform a single measurement (using the force power mode).
  • Do a sofware set.
  • Perform repeated measurements using the normal power mode.
  • Include a no floating-point variant for systems without fpu.

§Usage

To use this driver, import what you need from this crate and an embedded-hal implentation, then instatiate the device.

use embedded_qmp6988::{IirFilter, OverSamplingSetting, Qmp6988, DEFAULT_I2C_ADDRESS};
use linux_embedded_hal as hal;

fn main() -> Result<(), embedded_qmp6988::Error<hal::I2CError>> {
    // Create the I2C device from the chosen embedded-hal implementation,
    // in this case linux-embedded-hal
    let i2c = match hal::I2cdev::new("/dev/i2c-1") {
        Err(err) => {
            eprintln!("Could not create I2C device: {}", err);
            std::process::exit(1);
        }
        Ok(i2c) => i2c,
    };

    // Create the sensor and configure its repeatability
    let mut sensor = Qmp6988::new(i2c, DEFAULT_I2C_ADDRESS, hal::Delay {})?;
    sensor.set_filter(IirFilter::Off)?;
    sensor.set_oversampling_setting(OverSamplingSetting::HighSpeed)?;

    // Perform a barometric pressure measurement
    let measurement = sensor.measure()?;
    println!("Pressure: {:.2} hPa", measurement.pressure);
    Ok(())
}

§License

Licensed under either of

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Structs§

Measurement
The result of a measurement.
Qmp6988
QMP6988 device driver

Enums§

Error
All possible errors generated when using the Qmp6988 struct
IirFilter
IIR (Infinite Impulse Response) filter.
OverSamplingSetting
The oversampling setting.

Constants§

DEFAULT_I2C_ADDRESS
The default I2C address (SDO pin connected to low)
I2C_ADDRESS_LOGIC_HIGH
The I2C address when the SDO pin is connected to logic high
I2C_ADDRESS_LOGIC_LOW
The I2C address when the SDO pin is connected to logic low

Functions§

calculate_altitude
Calculate the altitude (in m) from a measurement.