Skip to content

Commit

Permalink
Add EH1 to BME280 example
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Oct 30, 2023
1 parent f6b5fb4 commit 5c4f40d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions examples/bme280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//! * https://www.adafruit.com/product/4399
//! * https://www.adafruit.com/product/4472

use eh0::prelude::*;
use eh0::blocking::i2c::WriteRead;
use eh1::i2c::I2c;
use ftdi_embedded_hal as hal;

fn main() {
Expand All @@ -27,15 +28,22 @@ fn main() {
let hal = hal::FtHal::init_default(device).unwrap();
let mut i2c = hal.i2c().unwrap();

// ID register is constant
const BME280_CHIP_ID: u8 = 0x60;

let mut buf: [u8; 1] = [0];
const BME280_ADDR: u8 = 0b1110111;
const BME280_CHIP_ID_ADDR: u8 = 0xD0;
println!("Reading chip ID from BME280");
i2c.write_read(BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf)

println!("Reading chip ID from BME280 with embedded-hal v0.2");
WriteRead::write_read(&mut i2c, BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf)
.expect("Failed to read from BME280");
assert_eq!(buf[0], BME280_CHIP_ID);
println!("Chip ID ok from embedded-hal v0.2");

// ID register is constant
const BME280_CHIP_ID: u8 = 0x60;
println!("Reading chip ID from BME280 with embedded-hal v1");
I2c::write_read(&mut i2c, BME280_ADDR, &[BME280_CHIP_ID_ADDR], &mut buf)
.expect("Failed to read from BME280");
assert_eq!(buf[0], BME280_CHIP_ID);
println!("Chip ID ok");
println!("Chip ID ok from embedded-hal v1");
}

0 comments on commit 5c4f40d

Please sign in to comment.