#i2c #pressure-sensor #async #ms5611 #embassy-hal

no-std ms5611-i2c

no_std Library for the MS5611 barometric pressure sensor only for I2C with embassy

1 unstable release

new 0.1.0 Feb 24, 2025

#2084 in Embedded development

MIT/Apache

20KB
247 lines

MS5611 Library for Rust Latest Version Documentation

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.
  • 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 is_sync and is_async features. Only one of these features can be enabled at a time.

Features

  • is_sync: Enables synchronous mode using embedded_hal traits.
  • is_async: Enables asynchronous mode using embedded_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.3–2MB
~39K SLoC