| Crates.io | as8510 |
| lib.rs | as8510 |
| version | 0.1.0 |
| created_at | 2025-02-28 18:35:04.967042+00 |
| updated_at | 2025-02-28 18:35:04.967042+00 |
| description | An async no_std driver for the AS8510 SPI current and voltage sensor |
| homepage | https://rand12345.github.io |
| repository | https://github.com/rand12345/ad8510-rs |
| max_upload_size | |
| id | 1573059 |
| size | 17,769 |
A #![no_std] async Rust driver for the AS8510 current and voltage sensor, designed for embedded systems using the embedded-hal-async SPI interface. This crate provides an easy-to-use API to read bi-directional current and voltage measurements with configurable gain settings.
The AS8510 is a high-precision data acquisition IC commonly used in automotive and industrial applications for current sensing over a shunt resistor and voltage measurements.
embedded-hal-async for SPI communication.Gain1, Gain25, Gain40, Gain100.Gain25, Gain40.Gain1: +2076A / -1523AGain25: ±400AGain40: ±235AGain100: ±77A#![no_std] compatible for bare-metal embedded environments.Add the following to your Cargo.toml:
[dependencies]
as8510 = "0.1.0"
embedded-hal-async = "1.0"
Ensure your target platform provides an implementation of embedded_hal_async::spi::SpiDevice.
Below is an example using the esp-hal crate for an ESP32-based setup. Adjust the SPI configuration and runtime according to your hardware and executor (e.g., embassy_executor).
use as8510::{As8510, Gain};
use esp_hal::spi::{Config, SpiDeviceWithConfig, Rate};
use core::time::Duration;
#[embassy_executor::main]
async fn main(_spawner: embassy_executor::Spawner) {
let spi_bus: Mutex<_, esp_hal::spi::master::SpiDmaBus<'_, esp_hal::Async>> = Mutex::new(spi);
let spi_device_config = Config::default()
.with_frequency(Rate::from_khz(1000))
.with_mode(esp_hal::spi::Mode::_1);
let spi_device = SpiDeviceWithConfig::new(&spi_bus, ss_pin, spi_device_config);
if let Ok(mut device) = As8510::new(spi_device, Gain::Gain100, Gain::Gain25).await {
loop {
match device.get_current().await {
Ok(amps) => println!("Current: {}A", amps),
Err(e) => println!("Error reading current: {:?}", e),
}
embassy_time::Timer::after(Duration::from_millis(100)).await;
}
}
}
new(peri, current_gain, voltage_gain): Initializes the AS8510 with the specified SPI device and gain settings.get_current(): Reads the current in amperes (A) asynchronously.get_voltage(): Reads the voltage (unverified implementation).| Gain | Current Range (A) | Voltage Range |
|---|---|---|
Gain1 |
+2076 / -1523 | Not supported |
Gain25 |
±400 | Supported |
Gain40 |
±235 | Supported |
Gain100 |
±77 | Not supported |
Note: Voltage measurements are restricted to Gain25 and Gain40.
embedded-hal-async: For async SPI operations.This crate is licensed under either of:
at your option.
Contributions are welcome! Please submit issues or pull requests to the GitHub repository.
get_voltage() method is currently unverified and may require additional calibration or validation.