6 releases
0.1.5 | Mar 14, 2025 |
---|---|
0.1.4 | Mar 14, 2025 |
#701 in Embedded development
510 downloads per month
39KB
845 lines
BMPE280
An I2C driver for the BMP280 barometer, thermometer.
Usage Add the following to your Cargo.toml:
[dependencies]
bmpe280 = "0.1.1"
Use embedded-hal implementation to get I2C handle and delay then create handle.
For BMP280 and esp32 no_std:
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::i2c::master::{ Config, I2c};
use esp_hal::{delay::Delay, main};
use esp_println::println;
#[main]
fn main() -> ! {
let config=esp_hal::Config::default();
let delay = Delay::new();
let peripherals = esp_hal::init(config);
let i2c0 = I2c::new(peripherals.I2C0, Config::default())
.unwrap()
.with_sda(peripherals.GPIO3)
.with_scl(peripherals.GPIO1);
use bmpe280::bmp280::BMP280;
//
let mut bmp = BMP280::new(i2c0);
loop {
let m=bmp.measure();
println!("1:temperature:{0}℃, pressure:{1}",m.temperature,m.pressure);
delay.delay_millis(1000);
}
}
For BME280 and esp32 no_std:
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::i2c::master::{Config, I2c};
use esp_hal::{delay::Delay, main};
use esp_println::println;
#[main]
fn main() -> ! {
let config = esp_hal::Config::default();
let delay = Delay::new();
let peripherals = esp_hal::init(config);
let i2c0 = I2c::new(peripherals.I2C0, Config::default())
.unwrap()
.with_sda(peripherals.GPIO3)
.with_scl(peripherals.GPIO1);
use bmpe280::bme280::BME280;
//
let mut bmp = BME280::new(i2c0);
loop {
let m = bmp.measure();
println!(
"2:temperature:{0}℃, pressure:{1},humidity:{2}%",
m.temperature, m.pressure, m.humidity
);
delay.delay_millis(1000);
}
}
Dependencies
~56KB