#i2c #bmp280 #println #no-std #no-main #bmpe280

bmpe280

An I2C driver for the Bosch BMP280/BME280 barometer , thermometer

6 releases

0.1.5 Mar 14, 2025
0.1.4 Mar 14, 2025

#701 in Embedded development

Download history 386/week @ 2025-03-09 115/week @ 2025-03-16 9/week @ 2025-03-23

510 downloads per month

MIT license

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