Crates.io | ak09940a |
lib.rs | ak09940a |
version | |
source | src |
created_at | 2024-12-14 18:16:08.803248 |
updated_at | 2025-01-02 01:28:52.756651 |
description | A simple library for the AK09940A magnetic sensor |
homepage | https://github.com/ProfFan/ak09940a |
repository | |
max_upload_size | |
id | 1483313 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
The AK09940A is a high-precision 3-axis magnetometer with I2C and SPI interfaces. Note that the SPI interface is in mode 0 and the max clock speed is 3MHz as specified in the datasheet.
The driver is implemented in Rust and supports both blocking and non-blocking SPI operations.
The blocking version is under the blocking
module, and the non-blocking version is under the non_blocking
module.
We support:
In order to use the driver, you need to add the following to your Cargo.toml
file:
[dependencies]
ak09940a = "0.2"
let mag = ak09940a::non_blocking::AK09940A::new(spidev)
.continuous(0x03) // Refer to the datasheet for the mode ID
.await;
let mut mag = match mag {
Ok(mag) => Some(mag),
Err(e) => {
match e {
ak09940a::non_blocking::Error::Spi(e) => defmt::error!("SPI error: {:?}", e),
ak09940a::non_blocking::Error::InvalidWhoAmI(w) => {
defmt::error!("Invalid WHO_AM_I: {:?}", w)
}
ak09940a::non_blocking::Error::SensorBusy => defmt::error!("Sensor busy"),
ak09940a::non_blocking::Error::InvalidMode => defmt::error!("Invalid mode"),
}
None
}
};
loop {
let Ok((st1, hx, hy, hz, tmps, st2)) = mag.read_data().await;
// Do something with the data
defmt::info!("hx: {}", hx.magnitude());
defmt::info!("hy: {}", hy.magnitude());
defmt::info!("hz: {}", hz.magnitude());
defmt::info!("tmps: {}", tmps.milli_celsius());
}
Apache-2.0