Crates.io | bmp180-driver |
lib.rs | bmp180-driver |
version | 0.1.1 |
source | src |
created_at | 2024-05-25 07:09:27.543538 |
updated_at | 2024-05-25 07:36:14.21938 |
description | A driver for BMP180 Digital Pressure Sensor. |
homepage | |
repository | https://github.com/milewski/bmp180-driver |
max_upload_size | |
id | 1251775 |
size | 16,335 |
This library provides an interface for interacting with the BMP180 pressure sensor.
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);
}
}
The MIT License (MIT). Please see License File for more information.