1 unstable release
0.1.0 | Jun 18, 2023 |
---|
#16 in #analog-devices
12KB
187 lines
LTC2497 Rust Driver
This is a platform agnostic driver for the Analog Devices LTC2497 16-Bit 8-/16-Channel DSADC with I2C Interface.
Device
LTC2497 is a low power 16-bit analog-to-digital converter with 16 single-ended inputs, that can be used as 8 differential inputs.
The device has an I2C interface with possibility to set one of 27 addresses via GPIO pins and possibility to synchronise readings on the batch of devices via hardcoded global address. Device has internal oscillator but may be configured to use external one.
Device info and Datasheet
lib.rs
:
A platform agnostic Rust driver for the LTC2497 ADC, based on the embedded-hal
traits.
Device can be used with embedded HAL directly or with RPPAL (Raspberry Pi Peripheral Access Library) with "hal" feature.
Usage
Import this crate and one of embedded HAL implementation (e.g. linux-embedded-hal or rppal). Then instantiate the device.
use std::error::Error;
use ltc2497::LTC2497;
use ltc2497::{AddressPinState::Low, Channel};
use rppal::hal::Delay;
use rppal::i2c::I2c;
let i2c = I2c::new()?;
let mut adc = LTC2497::new_from_pins(i2c, Low, Low, Low, 5.0, 0.0, Delay);
for ch in 0..=15 {
match adc.read_channel(Channel::from(ch)) {
Ok(v) => println!("Channel {ch}: {v}V"),
Err(e) => println!("error {e:?} at channel {ch}"),
};
}
Ok(())
Also you can instantiate device with address directly. For example, if you configured pins to set device address 0x20:
let mut adc = LTC2497::new(i2c, 0x20, 5.0, 0.0, Delay);
Dependencies
~71KB