Crates.io | embedded-qmp6988 |
lib.rs | embedded-qmp6988 |
version | 0.1.0 |
source | src |
created_at | 2024-01-25 14:50:22.307407 |
updated_at | 2024-01-25 14:50:22.307407 |
description | Platform-agnostic Rust driver for the QMP6988 barometric pressure sensor. |
homepage | https://gitlab.com/ghislainmary/embedded-qmp6988 |
repository | https://gitlab.com/ghislainmary/embedded-qmp6988 |
max_upload_size | |
id | 1113912 |
size | 35,442 |
This is a platform agnostic Rust driver the QMP6988 digital barometric pressure
sensor using the embedded-hal
traits.
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.
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(())
}
Licensed under either of
at your option.
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.