2 unstable releases
0.2.0 | Mar 18, 2025 |
---|---|
0.1.0 | Feb 24, 2025 |
#2294 in Embedded development
90 downloads per month
20KB
247 lines
MS5611 Library for Rust

A library for the MS5611 barometric pressure sensor. Only supports the i2c interface (no SPI). Works with embassy-hal. Support sync and async-i2c Based on https://github.com/braincore/ms5611-rs
Features
- Per datasheet, computes the second order temperature compensation.
- Validates the PROM's checksum.
- runs with embassy-hal
- supports embedded_hal_async::i2c::I2c
lib.rs
:
MS5611 pressure sensor driver using I2C.
This library supports both synchronous and asynchronous modes of operation.
The mode is selected using the sync
and async
features. Only one
of these features can be enabled at a time.
Features
sync
: Enables synchronous mode usingembedded_hal
traits.async
: Enables asynchronous mode usingembedded_hal_async
traits.
Example
use ms5611_i2c::{Ms5611, OversamplingRatio};
use embedded_hal::blocking::i2c::{Write, WriteRead};
// Create an instance of the I2C bus (implementation specific)
let i2c = ...;
// Create an instance of the MS5611 sensor
let mut sensor = Ms5611::new(i2c, None).unwrap();
// Reset the sensor
sensor.reset().unwrap();
// Read a sample with a specific oversampling ratio
let sample = sensor.read_sample(OversamplingRatio::Opt4096).unwrap();
println!("Pressure: {} mbar, Temperature: {} °C", sample.pressure_mbar, sample.temperature_c);
Errors
The library defines a custom error type MS5611Error
which can represent
the following errors:
I2CError
: An error occurred during I2C communication.BadChecksum
: The checksum of the PROM data did not match.BadProm
: The PROM data is invalid.NoProm
: The PROM data could not be read.BadAddress
: The I2C address is invalid.BadOsr
: The oversampling ratio is invalid.
Structs
Ms5611
: Represents the MS5611 pressure sensor.Ms5611Sample
: Represents a sample of pressure and temperature data.Prom
: Represents the factory calibrated data stored in the sensor's ROM.
Enums
MS5611Error
: Represents the possible errors that can occur.OversamplingRatio
: Represents the available oversampling ratios.
Methods
Ms5611::new
: Creates a new instance of the MS5611 sensor.Ms5611::reset
: Resets the sensor.Ms5611::read_sample
: Reads a sample of pressure and temperature data.OversamplingRatio::get_delay
: Returns the delay required for the given oversampling ratio.OversamplingRatio::addr_modifier
: Returns the address modifier for the given oversampling ratio.
Dependencies
~1.2–1.9MB
~37K SLoC