bmp180-driver

Crates.iobmp180-driver
lib.rsbmp180-driver
version0.1.1
sourcesrc
created_at2024-05-25 07:09:27.543538
updated_at2024-05-25 07:36:14.21938
descriptionA driver for BMP180 Digital Pressure Sensor.
homepage
repositoryhttps://github.com/milewski/bmp180-driver
max_upload_size
id1251775
size16,335
Rafael Milewski (milewski)

documentation

README

BMP180 Driver

This library provides an interface for interacting with the BMP180 pressure sensor.

Installation

You can install the package via Cargo:

cargo add bmp180-driver

Then, you can use the library in your code as follows:

use std::error::Error;
use bmp180_driver::{Common, Resolution, BMP180};

use esp_idf_svc::hal::delay::FreeRtos;
use esp_idf_svc::hal::i2c::config::Config;
use esp_idf_svc::hal::i2c::I2cDriver;
use esp_idf_svc::hal::prelude::Peripherals;

fn main() -> Result<(), Box<dyn Error>> {
    // Initialize peripherals
    let peripherals = Peripherals::take()?;

    // Define SDA and SCL pins
    let sda = peripherals.pins.gpio6;
    let scl = peripherals.pins.gpio5;

    // Initialize I2C driver
    let i2c = I2cDriver::new(peripherals.i2c0, sda, scl, &Config::default())?;

    // Create BMP180 sensor instance
    let mut sensor = BMP180::new(i2c, FreeRtos);

    // Check connection to the sensor
    sensor.check_connection()?;

    // Initialize the sensor
    let mut sensor = sensor.initialize()?;

    // Continuously read and print sensor data
    loop {
        let (temperature, pressure, altitude) = sensor.read_all(Resolution::UltraHighResolution)?;

        println!("Temperature: {} °C", temperature);
        println!("Pressure: {} Pa", pressure);
        println!("Altitude: {} meters", altitude);
    }
}

References

License

The MIT License (MIT). Please see License File for more information.

Commit count: 11

cargo fmt