embedded-ads111x

Crates.ioembedded-ads111x
lib.rsembedded-ads111x
version0.1.2
sourcesrc
created_at2023-03-03 19:29:51.713973
updated_at2024-09-04 19:08:05.835489
descriptionADS111x 16bit ADCs I2C rust driver no_std
homepage
repositoryhttps://github.com/wintermute101/ads111x.git
max_upload_size
id800009
size17,945
(wintermute101)

documentation

README

ADS111x 16bit ADCs I2C rust driver no_std

Tested on ESP32, STM32G421, and ADS1115 Documentation

Example

Blocking

let i2c_speed = RateExtU32::kHz(100);

let i2c = I2C::new(peripherals.I2C0, io.pins.gpio19, io.pins.gpio23, i2c_speed, &mut system.peripheral_clock_control, &clocks);

let config = ADS111xConfig::default()
    .mux(ads111x::InputMultiplexer::AIN0GND)
    .dr(ads111x::DataRate::SPS8)
    .pga(ads111x::ProgramableGainAmplifier::V4_096);

// Create a new ADS111x instance with the specified configuration
// Note: This only creates the instance, it doesn't write the configuration to the chip
let mut adc = match ADS111x::new(i2c, 0x48u8, config){
    Err(e) => panic!("Error {:?}", e),
    Ok(x) => x,
};

// Write the configuration to the chip's registers
// This step is necessary to apply the configuration
if let Err(e) = adc.write_config(None) {
    panic!("Error {:?}", e);
}

match adc.read_single_voltage(None){
    Ok(v) => println!("Val single {:.6}", v),
    Err(e) => println!("Error {:?}", e),
}

Async

Add feature async to Cargo.toml:

[dependencies]
embedded-ads111x = { features = ["async"] }
let mut i2c = I2c::new(p.I2C1, p.PA15, p.PB7, Irqs, p.DMA1_CH6, p.DMA1_CH5, hz(100_000), Default::default());

let config = ADS111xConfig::default()
    .mux(ads111x::InputMultiplexer::AIN0GND)
    .dr(ads111x::DataRate::SPS8)
    .pga(ads111x::ProgramableGainAmplifier::V4_096);

// Create a new ADS111x instance with the specified configuration
// Note: This only creates the instance, it doesn't write the configuration to the chip
let mut adc = match ADS111x::new(i2c, 0x48u8, config){
    Err(e) => panic!("Error {:?}", e),
    Ok(x) => x,
};

// Write the configuration to the chip's registers
// This step is necessary to apply the configuration
if let Err(e) = adc.write_config(None).await {
    panic!("Error {:?}", e);
}

match adc.read_single_voltage(None).await {
    Ok(v) => println!("Val single {:.6}", v),
    Err(e) => println!("Error {:?}", e),
}

License

Licensed under either of:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 12

cargo fmt