TMP108
A #[no_std] platform-agnostic driver for the
TMP108 temperature sensor using
the embedded-hal traits.
I²C addresses
The TMP108 can take one of 4 I²C addresses depending on the state of the A0 pin:
| A0 | Addr |
|---|---|
| GND | 0x48 |
| V+ | 0x49 |
| SDA | 0x4a |
| SCL | 0x4b |
The driver has dedicated constructors for each — new_with_a0_gnd,
new_with_a0_vplus, new_with_a0_sda, new_with_a0_scl — so an invalid
address cannot be requested.
Usage
Blocking one-shot read
let hal = new;
let i2c = hal.i2c;
let mut tmp = new_with_a0_gnd;
let temperature = tmp.temperature.map_err?;
println!;
Async continuous conversions
let hal = new;
let i2c = hal.i2c;
let mut delay = hal.delay;
let mut tmp = new_with_a0_gnd;
tmp.continuous
.await
.map_err?;
Async interrupt-mode threshold alert
let mut tmp = new_with_a0_gnd;
tmp.tmp108
.configure
.await
.map_err?;
tmp.set_temperature_threshold_low
.await
.map_err?;
tmp.set_temperature_threshold_high
.await
.map_err?;
println!;
let temperature = tmp
.wait_for_temperature_threshold
.await
.map_err?;
println!;
See examples/ for complete, runnable versions of each snippet (and more).
Cargo features
| Feature | Effect | Requires |
|---|---|---|
| (none) | Blocking Tmp108 over embedded-hal. |
— |
async |
Async Tmp108 over embedded-hal-async. Tmp108::continuous is unlocked. |
— |
embedded-sensors-hal |
Blocking TemperatureSensor impl on Tmp108. |
— |
embedded-sensors-hal-async |
Async TemperatureSensor, TemperatureThresholdSet, TemperatureHysteresis impls on Tmp108, plus the AlertTmp108 wrapper with TemperatureThresholdWait. |
async |
Gotchas
Tmp108::newdoes not take a delay. The delay only appears onwait_for_temperature, where it is genuinely needed to wait out a conversion period.- Comparator vs interrupt mode latching. In comparator mode the ALERT pin
stays asserted until temperature returns inside
(T_low + HYS, T_high − HYS). In interrupt mode the pin clears as soon as the configuration register is read (the driver does this for you insidewait_for_temperature_threshold). Seeexamples/alert_comparator.rsfor a demonstration. - ALERT polarity is set on-chip. Wire your pull resistor for the polarity you configured. Examples assume active-low + external pull-up.
Tmp108::continuousis async-only. For blocking continuous-mode use, callconfigure(...)to setMode::Continuousmanually, loop onwait_for_temperature(&mut delay), then callshutdown().- Temperature scale. Raw register values are 12-bit signed in the upper
bits of a 16-bit register; the driver returns
f32Celsius at 0.0625 °C/LSB.
MSRV
Rust 1.90 and up.
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.
See CONTRIBUTING.md for the full contribution workflow, including the Conventional Commits v1.0.0 commit-message format this repository uses.