https://github.com/hacknus/acs37800-rs
Platform-agnostic rust driver for the ACS37800 current sensor.
https://github.com/hacknus/acs37800-rs
acs37800 driver embedded rust
Last synced: 7 months ago
JSON representation
Platform-agnostic rust driver for the ACS37800 current sensor.
- Host: GitHub
- URL: https://github.com/hacknus/acs37800-rs
- Owner: hacknus
- License: apache-2.0
- Created: 2024-01-04T13:06:40.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T06:27:14.000Z (about 2 years ago)
- Last Synced: 2025-06-08T14:44:50.725Z (9 months ago)
- Topics: acs37800, driver, embedded, rust
- Language: Rust
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ACS37800 Rust Driver
[](https://crates.io/crates/acs37800)
[](https://docs.rs/acs37800)
[](https://github.com/hacknus/acs37800-rs/actions/workflows/rust.yml)
This is a platform-agnostic rust driver for the [ACS37800](https://www.allegromicro.com/en/products/sense/current-sensor-ics/zero-to-fifty-amp-integrated-conductor-sensor-ics/acs37800) current sensor.
Fully supported in `#![no_std]` environments.
Features:
- [X] test DC mode
- [X] test averaging
TODO:
- [ ] test AC mode
- [ ] over/under voltage
- [ ] phase delay
- [ ] flags
## Example
To implement this driver, consult the example:
Put this into your `cargo.toml`:
```toml
[dependencies]
acs37800 = { git = "https://github.com/hacknus/acs37800-rs" }
# required for the register configs to_u32_le() function
modular-bitfield-to-value = {git = "https://github.com/hacknus/modular-bitfield-to-value"}
```
Add the following imports:
```rust
use acs37800::registers::*;
// required for the to_u32_le() function.
use modular_bitfield_to_value::ToValue;
```
Configure the I2C bus in the `main()` function as follows:
```rust
let scl = gpiob.pb6;
let sda = gpiob.pb7;
let i2c1 = dp.I2C1.i2c(
(scl, sda),
i2cMode::Standard {
frequency: 100.kHz(),
},
&clocks,
);
```
and to use the driver, implement the driver as shown below:
```rust
{
// set up current sensor in DC mode with averaging and certain gain
let mut current_sensor = Acs37800::new(i2c, 96)
.with_r_iso(1_000_000)
.with_r_sense(16_900);
acs37800.set_oversampling_1(122);
CurrentTask::delay(Duration::ms(100));
acs37800.set_oversampling_2(512);
CurrentTask::delay(Duration::ms(100));
acs37800.set_dc_mode(511);
CurrentTask::delay(Duration::ms(100));
acs37800.set_gain(7);
CurrentTask::delay(Duration::ms(100));
acs37800.select_i_and_p_avg();
CurrentTask::delay(Duration::ms(100));
loop {
let voltage = acs37800.get_voltage_rms();
let current = acs37800.get_current_avg_1_sec();
}
}
```