| Crates.io | as5048a-async |
| lib.rs | as5048a-async |
| version | 0.1.0 |
| created_at | 2025-10-15 12:02:33.631307+00 |
| updated_at | 2025-10-15 12:02:33.631307+00 |
| description | Async driver for AS5048A 14-bit magnetic rotary position sensor with SPI interface |
| homepage | |
| repository | https://github.com/MightySCollins/as5048a-async |
| max_upload_size | |
| id | 1884240 |
| size | 33,625 |
Async Rust driver for the AS5048A 14-bit magnetic rotary position sensor using the SPI interface.
This driver is designed for embedded systems using embedded-hal-async and works seamlessly with async runtimes like Embassy.
embedded-hal-async traitsdefmt logging for debuggingno_std compatibleforbid(unsafe_code) - 100% safe RustThe AS5048A is a 14-bit rotary position sensor with SPI interface:
For more details read the full AS5048A Datasheet.
Add to your Cargo.toml:
[dependencies]
as5048a-async = "0.1"
embedded-hal-async = "1.0"
use as5048a_async::As5048a;
// Create sensor with an SpiDevice (bus + CS pin)
let mut sensor = As5048a::new(spi_device);
// Read angle (0-16383, representing 0-360°)
let angle = sensor.angle().await?;
let degrees = (angle as f32) * 360.0 / 16384.0;
For complete examples see the examples folder.
// Check magnetic field strength and sensor status
let diag = sensor.diagnostics().await?;
if diag.is_valid() {
// Read AGC value, check COMP flags, etc.
}
// Clear error flags
sensor.clear_error_flag().await?;
See the API documentation for complete details on available methods and types.
Main methods:
angle() - Read 14-bit angle (0-16383)angle_degrees() - Read angle in degrees (0-359) using integer mathmagnitude() - Read CORDIC magnitudediagnostics() - Read diagnostics with AGC value and status flagsclear_error_flag() - Clear error flagConstants:
ANGLE_MAX - Maximum angle value (16384) for custom conversionsThis crate requires Rust 1.87 or later.
Contributions are welcome! Please run cargo test and cargo clippy before submitting.