embedded-qmp6988

Crates.ioembedded-qmp6988
lib.rsembedded-qmp6988
version0.1.0
sourcesrc
created_at2024-01-25 14:50:22.307407
updated_at2024-01-25 14:50:22.307407
description Platform-agnostic Rust driver for the QMP6988 barometric pressure sensor.
homepagehttps://gitlab.com/ghislainmary/embedded-qmp6988
repositoryhttps://gitlab.com/ghislainmary/embedded-qmp6988
max_upload_size
id1113912
size35,442
Ghislain MARY (ghismary)

documentation

https://docs.rs/embedded-qmp6988/

README

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.

Commit count: 0

cargo fmt