Crate sdp8xx

Crate sdp8xx 

Source
Expand description

A platform agnostic Rust driver for the Sensirion SDP8xx differential pressure sensor, based on the embedded-hal traits. Heavily inspired by the sgp30 driver by Danilo Bergen

§The Device

The Sensirion SDP8xx is a differential pressure sensor. It has an I2C interface.

§Usage

§Instantiating

Import this crate and an embedded_hal implementation, then instantiate the device:

use linux_embedded_hal as hal;

use hal::{Delay, I2cdev};
use sdp8xx::Sdp8xx;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = 0x25;
let mut sdp = Sdp8xx::new(dev, address, Delay);

See sdp8xx-rpi-test for an example on the raspberry pi.

§Fetching Device Information

You can fetch the product id of your sensor:

use linux_embedded_hal as hal;
use hal::{Delay, I2cdev};
use sdp8xx::ProductIdentifier;
use sdp8xx::Sdp8xx;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sdp = Sdp8xx::new(dev, 0x25, Delay);
if let Ok(product_id) = sdp.read_product_id() {
    println!("{:?}", product_id);
} else {
    eprintln!("Error during reading product ID.");
}

§Fetching Some Data

You can fetch the differential pressure:

use linux_embedded_hal as hal;
use hal::{Delay, I2cdev};
use sdp8xx::Sdp8xx;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sdp = Sdp8xx::new(dev, 0x25, Delay);

let data = match sdp.trigger_differential_pressure_sample() {
    Ok(d) => dbg!(d),
    Err(_) => panic!(),
};

Re-exports§

pub use product_info::ProductIdentifier;
pub use crate::sample::*;

Modules§

command
I2C commands for SDP8xx differential pressure sensor
product_info
Product Identification Types
sample
Sample type for SDP8xx differential pressure sensor
states
State types for the SDP8xx

Structs§

Sdp8xx
State of the SDP8xx

Enums§

SdpError
All possible errors in this crate