spl06-007

Crates.iospl06-007
lib.rsspl06-007
version0.3.3
sourcesrc
created_at2023-02-20 01:33:06.106254
updated_at2023-02-22 02:46:16.166609
descriptionDriver for the SPL06-007 barometric pressure sensor
homepage
repositoryhttps://github.com/roxgib/SPL06-007
max_upload_size
id789421
size1,547,406
Sam Bradshaw (roxgib)

documentation

README

Crates.io Version Crates.io Downloads No Std

An I2C driver for the SPL06-007 barometric pressure and temperature sensor, intended for use in embedded environments.

Usage

The driver is designed to be used with embedded-hal and requires an I2C interface to be passed to the driver. The driver is generic over the I2C interface and the error type, allowing it to be used with any I2C implementation so long as it supports the required traits.

Add the following to your Cargo.toml:

[dependencies]
spl06_007 = "0.3"

Example usage on an Arduino Uno:

#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use panic_halt as _;

use spl06_007::Barometer;

#[arduino_hal::entry]
fn main() -> ! {
    let dp = arduino_hal::Peripherals::take().expect("Failed to take peripherals");
    let pins = arduino_hal::pins!(dp);
    let mut serial = arduino_hal::default_serial!(dp, pins, 57600);

    let mut i2c = arduino_hal::I2c::new(
        dp.TWI,
        pins.a4.into_pull_up_input(),
        pins.a5.into_pull_up_input(),
        50000,
    );

    let mut barometer = Barometer::new(&mut i2c).expect("Failed to initialise barometer");

    loop {
        ufmt::uwriteln!(&mut serial, "T: {:?}", barometer.get_temperature().unwrap() as u16).void_unwrap();
        ufmt::uwriteln!(&mut serial, "P: {:?}", barometer.get_pressure().unwrap() as u16).void_unwrap();
        ufmt::uwriteln!(&mut serial, "A: {:?}", barometer.altitude(1020.0).unwrap() as u16).void_unwrap();
    }
}

You can set the mode, sample rate, and oversampling values manually:

barometer.set_pressure_config(SampleRate::Single, SampleRate::Eight);
barometer.set_temperature_config(SampleRate::Single, SampleRate::Eight);

This is useful for more rapid updates, better precsion, or lower power draw.

It is also possible to set the mode to Mode::Standby to reduce power consumption:

barometer.set_mode(Mode::Standby);
Commit count: 34

cargo fmt