Expand description
I2C driver for the SPL06-007 pressure and temperature sensor. This sensor is available as a breakout board for the Arduino platform. This driver may also work with the SPL06-001, but this has not been tested.
This sensor operates on the I2c address 0x76 and is connected to the I2C bus on the Arduino Uno. Instantiate the Barometer struct with a reference to the I2C bus and call the init() method to initialise the sensor to default values. The sensor will then be ready to read temperature and pressure values.
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 instantiate barometer");
barometer.init().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();
}
}It is necessary to call init before any other methods are called. This method will set some default values for the sensor and is suitable for most use cases. Alternatively 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);
barometer.set_mode(Mode::ContinuousPressureTemperature);This is useful if you want to change the sample rate or oversampling values, such as for more rapid updates. It is also possible to set the mode to Mode::Standby to reduce power consumption. Other modes, including measuring only when polled, are not well supported at this time.