Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9a210bd
fix example for reading_temperature.rs
dnutiu Feb 24, 2024
ccfcf8b
update embedded-hal and linux-embedded-hal to latest stable versions
dnutiu Feb 25, 2024
9a6893f
rename calc to calculation
dnutiu Feb 25, 2024
160b178
add linux embedded hall to dependencies
dnutiu Feb 25, 2024
81005c1
remove tests
dnutiu Feb 25, 2024
b261eb6
remove doctest from lib
dnutiu Feb 25, 2024
28eedb1
refactor read temperature example
dnutiu Feb 25, 2024
38cf107
remove influx client example
dnutiu Feb 25, 2024
109a268
update README.md and Cargo.toml
dnutiu Feb 25, 2024
9bdc746
add doctest
dnutiu Feb 25, 2024
2c3fc02
update rust edition to 2021
dnutiu Feb 25, 2024
5468a27
update README.md
dnutiu Feb 25, 2024
053e44d
update examples
dnutiu Feb 25, 2024
02baa8f
rename example to read_sensor_data.rs
dnutiu Feb 25, 2024
70f192c
add .idea folder
dnutiu Feb 25, 2024
c46cd20
remove res folder from examples
dnutiu Feb 25, 2024
7174dde
remove .expect calls from lib
dnutiu Feb 25, 2024
fa4cc73
simplify error handling
dnutiu Feb 26, 2024
30b60b2
fix lib.rs doc test
dnutiu Feb 26, 2024
6eee3c1
update README.md
dnutiu Feb 26, 2024
99923f3
refactor: rename struct fields
dnutiu Feb 26, 2024
cb90ea4
refactor: remove generic type from boundary_check_u8
dnutiu Feb 26, 2024
43991b5
refactor: add docstrings to calculation
dnutiu Feb 26, 2024
43ca150
refactor: extract i2c utility in its own file
dnutiu Feb 26, 2024
b5d2f80
refactor: fix settings variable names
dnutiu Feb 27, 2024
4dc1064
todo: use anyhow crate to improve readability and maintenance
dnutiu Feb 27, 2024
432d364
refactor: soft_reset, init and set registers
dnutiu Feb 27, 2024
cf9b0fb
refactor: format code
dnutiu Feb 27, 2024
35c2ade
refactor: fix clippy hints
dnutiu Feb 27, 2024
d63fcf0
remove license check from flow
dnutiu Feb 27, 2024
14c2e61
refactor: store i2c bus handle as refcell
dnutiu Feb 27, 2024
80c1ee5
update read_sensor_data.rs example
dnutiu Feb 27, 2024
dfadb52
refactor lib.rs variables
dnutiu Mar 3, 2024
fe38f02
use anyhow crate for error handling
dnutiu Mar 3, 2024
f77e251
fix code formatting
dnutiu Mar 3, 2024
ebb40f0
Merge pull request #1 from dnutiu/v0.8.0
dnutiu Mar 3, 2024
64e5c06
update Cargo.toml to v0.8.0
dnutiu Mar 3, 2024
ffa9bf9
prepare v0.9.0
Nov 16, 2024
877c8bb
Downgrade bitflags back to version 1
dnutiu Nov 16, 2024
46c0c67
Add complete example for reading sensor data
dnutiu Nov 16, 2024
c3b200b
Fix example path
dnutiu Nov 16, 2024
3e09c52
Update bitflags to 2.6
dnutiu Nov 16, 2024
cd6f7a3
delete old example file
dnutiu Nov 16, 2024
6a26ba4
fix read sensor data example
dnutiu Nov 16, 2024
56d9b7a
add example to module
dnutiu Nov 16, 2024
bd54956
use clamp instead of computing min-max
dnutiu Nov 16, 2024
300bd90
make look-up table static
dnutiu Nov 16, 2024
eede29b
remove linux embedded hal
dnutiu Nov 16, 2024
48d7a04
Merge pull request #3 from dnutiu/v0.9.0
dnutiu Nov 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ jobs:
with:
command: check

test:
name: Run Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Check Formatting
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,16 +48,3 @@ jobs:
with:
command: clippy
args: -- -D warnings

license-check:
name: Check Licenses and Security Advisories
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories bans licenses sources
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check ${{ matrix.checks }}
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/bme680-rust.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
[package]
authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
authors = ["marcelbuesing <buesing.marcel@googlemail.com>", "denisnutiu <denis.nutiu@googlemail.com>"]
description = "A pure Rust implementation for the BME680 environmental sensor."
documentation = "https://docs.rs/bme680"
documentation = "https://github.com/dnutiu/bme680-rust"
license = "MIT"
name = "bme680"
repository = "https://github.com/marcelbuesing/bme680-hal"
version = "0.6.0"
edition = "2018"
repository = "https://github.com/dnutiu/bme680-rust"
version = "0.9.0"
edition = "2021"

[badges]
travis-ci = { repository = "https://github.com/marcelbuesing/bme680-hal", branch = "master" }
maintenance = { status = "passively-maintained" }

[dependencies]
bitflags = "1.2"
embedded-hal = "=1.0.0-alpha.5"
bitflags = "2.6"
embedded-hal = "=1.0.0"
log = "0.4"
serde = { version = "1.0", optional = true, default-features = false }
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
anyhow = { version = "1.0" , default-features = false}

[dev-dependencies]
env_logger = "0.9"
futures = { version = "0.3" }
i2cdev = "0.5"
influx_db_client = { version = "0.5", default-features= false, features = ["rustls-tls"] }
tokio = {version = "1.5", features = ["full"] }
url = "2.1"
env_logger = "0.11.5"

[target.'cfg(target_os = "linux")'.dev-dependencies]
linux-embedded-hal = "0.4.0-alpha.1"
[target.'cfg(target_os = "linux")'.dependencies]
linux-embedded-hal = "0.4.0"
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
BME680 + Rust [![Actions Status](https://github.com/marcelbuesing/bme680/workflows/Continuous%20integration/badge.svg)](https://github.com/marcelbuesing/bme680/actions?query=workflow%3A"Continuous+integration")
[![Cargo Deny Status](https://img.shields.io/badge/cargo--deny-license%20checked-green)](https://github.com/marcelbuesing/bme680/actions?query=workflow%3A"Continuous+integration")
BME680 Rust Library
=============

This repository contains a pure Rust implementation for the [BME680](https://www.bosch-sensortec.com/bst/products/all_products/bme680) environmental sensor. The library can be used to read the gas, pressure, humidity and temperature sensors via I²C.
This repository contains a pure Rust implementation for the [BME680](https://www.bosch-sensortec.com/bst/products/all_products/bme680) environmental sensor.
The library can be used to read the gas, pressure, humidity and temperature sensors via I²C.

The library uses the [embedded-hal](https://github.com/japaric/embedded-hal) library to abstract reading and writing via I²C. In the examples you can find a demo how to use the library in Linux using the [linux-embedded-hal](https://github.com/japaric/linux-embedded-hal) implementation.
It is a fork of the library written by Marcel Buessing: https://github.com/marcelbuesing/bme680.

# Alternative
[drogue-bme680](https://github.com/drogue-iot/drogue-bme680)
To use this library, create a new project and add it as a dependency:

# Example getting started Linux
```toml
[dependencies]
bme680 = {git = "https://github.com/dnutiu/bme680-rust.git", version = "0.9.0"}
```

# Getting started on Raspberry Pi

Assuming that you have connected the sensor to the Raspberry PI's GPIO ports.

Install required libraries for developing I2C.

```bash
sudo apt-get install build-essential libi2c-dev i2c-tools python-dev libffi-dev
```

Determine the I2C device path

Expand All @@ -34,11 +46,16 @@ pi@raspberrypi:~ $ i2cdetect -y 1
70: -- -- -- -- -- -- 76
```

# Example Influx Client
The examples folder contains an example for a simple influx database client inserting collected values.
Below you may find examples of Chronograf graphs of an indoor measurement over a period of 30 days.
The read-sensor-data from the examples folder is configured to use the I2C device `/dev/i2c-1` and the `0x76` address.

To run the example, clone the repository and go to the examples' folder:

![Temperature Graph](examples/res/influx_temperature.png "Temperature measurement in C°")
![Humidity Graph](examples/res/influx_humidity.png "Humidity measurement in %")
![Air pressure Graph](examples/res/influx_pressure.png "Air pressure measurement in hPa")
![Gas resistance Graph](examples/res/influx_gas_resistance.png "Gas resistance measurement")
```bash
git clone https://github.com/dnutiu/bme680-rust.git && cd bme680-rust/examples/read-sensor-data
```
Then run the example:

```bash
export RUST_LOG=info
cargo run
```
9 changes: 0 additions & 9 deletions ci/no_std_test/Cargo.toml

This file was deleted.

8 changes: 0 additions & 8 deletions ci/no_std_test/src/lib.rs

This file was deleted.

90 changes: 0 additions & 90 deletions examples/influx_client.rs

This file was deleted.

12 changes: 12 additions & 0 deletions examples/read-sensor-data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "read-sensor-data"
version = "0.1.0"
edition = "2021"

[dependencies]
bme680 = {path = "../../"}
env_logger = "0.11.5"
linux-embedded-hal = "0.4.0"
anyhow = { version = "1.0.80" }
log = "0.4"
embedded-hal = "=1.0.0"
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
#![no_std]

use bme680::*;
use core::result;
use bme680::i2c::Address;
use bme680::{Bme680, IIRFilterSize, OversamplingSetting, PowerMode, SettingsBuilder};
use core::time::Duration;
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::blocking::i2c;
use embedded_hal::delay::DelayNs;
use linux_embedded_hal as hal;
use linux_embedded_hal::Delay;
use log::info;

fn main(
) -> result::Result<(), Error<<hal::I2cdev as i2c::Read>::Error, <hal::I2cdev as i2c::Write>::Error>>
{
// Please export RUST_LOG=info in order to see logs in the console.
fn main() -> Result<(), anyhow::Error> {
env_logger::init();

let i2c = hal::I2cdev::new("/dev/i2c-1").unwrap();
let mut delayer = Delay {};

let mut dev = Bme680::init(i2c, &mut delayer, I2CAddress::Primary)?;
let mut dev = Bme680::init(i2c, &mut delayer, Address::Primary)?;
let mut delay = Delay {};

let settings = SettingsBuilder::new()
.with_humidity_oversampling(OversamplingSetting::OS2x)
.with_pressure_oversampling(OversamplingSetting::OS4x)
.with_temperature_oversampling(OversamplingSetting::OS8x)
.with_temperature_filter(IIRFilterSize::Size3)
.with_gas_measurement(Duration::from_millis(1500), 320, 25)
.with_temperature_offset(-2.2)
.with_gas_measurement(Duration::from_millis(1500), 320, 23)
.with_run_gas(true)
.build();

let profile_dur = dev.get_profile_dur(&settings.0)?;
let profile_dur = dev.get_profile_duration(&settings.0)?;
info!("Profile duration {:?}", profile_dur);
info!("Setting sensor settings");
dev.set_sensor_settings(&mut delayer, settings)?;
dev.set_sensor_settings(&mut delayer, &settings)?;
info!("Setting forced power modes");
dev.set_sensor_mode(&mut delayer, PowerMode::ForcedMode)?;

let sensor_settings = dev.get_sensor_settings(settings.1);
info!("Sensor settings: {:?}", sensor_settings);

loop {
delay.delay_ms(5000u32);
let _ = delay.delay_ms(5000u32);
let power_mode = dev.get_sensor_mode();
info!("Sensor power mode: {:?}", power_mode);
info!("Setting forced power modes");
dev.set_sensor_mode(&mut delayer, PowerMode::ForcedMode)?;
info!("Retrieving sensor data");
let (data, _state) = dev.get_sensor_data(&mut delayer)?;
let (data, _state) = dev.get_measurement(&mut delayer)?;
info!("Sensor Data {:?}", data);
info!("Temperature {}°C", data.temperature_celsius());
info!("Pressure {}hPa", data.pressure_hpa());
info!("Humidity {}%", data.humidity_percent());
info!("Gas Resistence {}Ω", data.gas_resistance_ohm());
}
}
}
Binary file removed examples/res/influx_gas_resistance.png
Binary file not shown.
Binary file removed examples/res/influx_humidity.png
Binary file not shown.
Binary file removed examples/res/influx_pressure.png
Binary file not shown.
Binary file removed examples/res/influx_temperature.png
Binary file not shown.
Loading