| Crates.io | mmc5983_rs |
| lib.rs | mmc5983_rs |
| version | 0.0.1 |
| created_at | 2024-12-27 16:38:23.345914+00 |
| updated_at | 2025-01-04 01:56:08.07628+00 |
| description | A Rust library for interacting with the MMC5983 magnetometer |
| homepage | https://docs.rs/mmc5983_rs |
| repository | https://github.com/RaulTrombin/MMC5983-rs |
| max_upload_size | |
| id | 1496484 |
| size | 75,711 |
A pure Rust driver for the MEMSIC's MMC5983 3-axis magnetic sensor.
embedded-hal-async (optional feature)The MMC5983MA sensor features:
Add this to your Cargo.toml:
cargo add mmc5983_rs
use mmc5983_rs::Mmc5983;
let mut mag = Mmc5983::new_with_i2c(i2c);
// Initialize the device
mag.init()?;
// Optional: Calibrate offset
let offset = mag.calibrate_offset(&mut delay)?;
// Read magnetic field (one-shot mode)
let field = mag.magnetic_field()?;
println!("Magnetic field: X={} Y={} Z={} Gauss",
field.x_gauss(), field.y_gauss(), field.z_gauss());
// Read temperature
let temp = mag.temperature()?;
println!("Temperature: {}°C", temp.degrees_celsius());
// Switch to continuous mode with 100Hz measurements
let mut mag = mag.into_continuous(MagOutputDataRate::Hz100, None)?;
// Read measurements continuously
loop {
if let Ok(field) = mag.magnetic_field() {
let (x, y, z) = field.gauss();
println!("Magnetic field: X={} Y={} Z={} Gauss", x, y, z);
}
}
Enable the async feature in your Cargo.toml:
[dependencies]
mmc5983_rs = { version = "0.0.1", features = ["async"] }
Then use with embedded-hal-async:
let mut mag = Mmc5983::new_with_i2c(i2c);
mag.init().await?;
let field = mag.magnetic_field().await?;
Check the examples directory for more usage examples:
navigator.rs: Example using Linux embedded HAL on Navigator boardmicrobit-v2.rs: Example for BBC micro:bit v2 using Embassy ( Embedded Async)Licensed under MIT license.
For more details about the sensor, see the MMC5983MA datasheet.