Crate tmp108

Source
Expand description

This is a platform-agnostic Rust driver for the TMP108 temperature sensor based on the embedded-hal traits.

For further details of the device architecture and operation, please refer to the official Datasheet.

§TMP108

no-std check rolling crates.io Documentation LICENSE

A #[no_std] platform-agnostic driver for the TMP108 temperature sensor using the embedded-hal traits.

The TMP108 can take one of 4 I2C addresses depending on the state of the A0 pin, as described in the table below:

A0Addr
GND0x48
V+0x49
SDA0x4a
SCL0x4b

The driver has specific constructors for each of these states, to ensure that an invalid address is not attempted.

§Usage

let delay = DelayNs;
let mut tmp = Tmp108::new_with_a0_gnd(i2c, delay);
// let mut tmp = Tmp108::new_with_a0_vplus(i2c, delay);
// let mut tmp = Tmp108::new_with_a0_sda(i2c, delay);
// let mut tmp = Tmp108::new_with_a0_scl(i2c, delay);
// let mut tmp = Tmp108::new(i2c, delay, A0::Gnd);

let cfg = Default::default()
    .with_cm(ConversionMode::OneShot)
    .with_tm(ThermostatMode::Comparator)
    .with_cr(ConversionRate::Hertz16)
    .with_hysteresis(Hysteresis::FourCelsius)
    .with_polarity(Polarity::ActiveLow);

tmp.set_configuration(cfg)?;

let temp = tmp.temperature()?;

let cfg = cfg
    .with_cm(ConversionMode::OneShot)
    .with_tm(ThermostatMode::Interrupt)
    .with_cr(ConversionRate::Hertz1)
    .with_fl(true)
    .with_fh(true);

tmp.set_configuration(cfg)?;

let high_limit = 48.0;
let low_limit = 26.5;

tmp.set_low_limit(low_limit)?;
tmp.set_high_limit(high_limit)?;

tmp.continuous(Default::default(), |t| {
	for _ in 0..10 {
		let temp = tmp.wait_for_temperature()?;
		info!("Temperature {}", temp);
	}

	Ok(())
})?;

§MSRV

Currently, rust 1.79 and up is supported, but some previous versions may work.

§License

Licensed under the terms of the MIT license.

§Contribution

Unless you explicitly state otherwise, any contribution submitted for inclusion in the work by you shall be licensed under the terms of the MIT license.

License: MIT

Modules§

blocking
Tmp108 Blocking API

Structs§

Configuration
Configuration register.
HighLimit
Temperature high limit register.
LowLimit
Temperature low limit register.
Temperature
Temperature register.

Enums§

A0
A0 pin logic level representation.
ConversionMode
Conversion mode.
ConversionRate
Conversion rate.
Hysteresis
Hysteresis control.
Polarity
Polarity
Register
Register addresses
ThermostatMode
Thermostat mode.