#embedded-hal-driver #voltage #no-std #power-monitor

no-std pac194x

Platform-agnostic Rust driver for the PAC194x 9V, 16-bit power monitor with alerts

3 releases

0.1.3 Mar 30, 2022
0.1.1 Mar 27, 2022
0.1.0 Mar 26, 2022

#634 in Embedded development

36 downloads per month

MIT/Apache

59KB
791 lines

Rust PAC194X Power Monitor Driver

A platform-agnostic driver crate for the Microchip PAC194X single/multi channel power monitor using the embedded-hal traits.

Build Status Docs.rs Crates.io

This driver allows you to:

  • Read/Write every available register as a Rust data structure, allowing you to configure alerts, averaging, etc.
  • Read the bus and sense voltages directly as f32s

Usage

To use this driver, import this crate and an embedded_hal implementation, then instantiate the appropriate device.

use linux_embedded_hal::I2cdev;
use pac194x::{PAC194X, AddrSelect};

const SENSE_RESISTOR: f32 = 0.5;

fn main() {
    let i2c = I2cdev::new("/dev/i2c-1").unwrap();
    let mut sensor = PAC194X::new(i2c, AddrSelect::GND).unwrap();
    loop {
        let bus_voltage_1 = sensor.read_bus_voltage_n(1).unwrap();
        let sense_voltage_1 = sensor.read_sense_voltage_n(1).unwrap();
        println!("Channel 1 has a bus voltage of: {:.2} V", bus_voltage_1);
        println!("Channel 1 is pulling a current of: {:.2} A", sense_voltage_1 / SENSE_RESISTOR);
    }
}

License

Licensed under either of

at your option.

Contributing

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.

Dependencies

~2.5MB
~59K SLoC