Compare commits

...

16 commits

Author SHA1 Message Date
7713e3ec9d Add README.md
Some checks failed
Continuous integration / Cargo Check (push) Has been cancelled
Continuous integration / Check Formatting (push) Has been cancelled
Continuous integration / Check Lints (push) Has been cancelled
2025-01-07 11:40:36 +00:00
753af2629f Delete README.md
Some checks are pending
Continuous integration / Cargo Check (push) Waiting to run
Continuous integration / Check Formatting (push) Waiting to run
Continuous integration / Check Lints (push) Waiting to run
2025-01-07 11:39:52 +00:00
48d7a04679
Merge pull request #3 from dnutiu/v0.9.0
V0.9.0
2024-11-16 17:18:56 +02:00
eede29b24b remove linux embedded hal 2024-11-16 17:17:26 +02:00
300bd90f8e make look-up table static 2024-11-16 17:13:50 +02:00
bd54956320 use clamp instead of computing min-max 2024-11-16 17:10:23 +02:00
56d9b7a58a add example to module 2024-11-16 16:43:32 +02:00
6a26ba4397 fix read sensor data example 2024-11-16 16:43:18 +02:00
cd6f7a34cd delete old example file 2024-11-16 16:42:20 +02:00
3e09c52548 Update bitflags to 2.6 2024-11-16 16:41:00 +02:00
c3b200bae9 Fix example path 2024-11-16 16:26:16 +02:00
46c0c67c67 Add complete example for reading sensor data 2024-11-16 16:05:40 +02:00
877c8bb6bc Downgrade bitflags back to version 1 2024-11-16 15:23:30 +02:00
Denis-Cosmin NUTIU
ffa9bf9b5b prepare v0.9.0 2024-11-16 14:44:51 +02:00
64e5c06c83 update Cargo.toml to v0.8.0 2024-03-03 19:09:33 +02:00
ebb40f0047
Merge pull request #1 from dnutiu/v0.8.0
V0.8.0
2024-03-03 19:06:02 +02:00
8 changed files with 91 additions and 117 deletions

View file

@ -4,6 +4,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/read-sensor-data/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/examples/read-sensor-data/target" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />

View file

@ -5,19 +5,21 @@ documentation = "https://github.com/dnutiu/bme680-rust"
license = "MIT"
name = "bme680"
repository = "https://github.com/dnutiu/bme680-rust"
version = "0.7.0"
version = "0.9.0"
edition = "2021"
[badges]
maintenance = { status = "passively-maintained" }
[dependencies]
bitflags = "1.2"
bitflags = "2.6"
embedded-hal = "=1.0.0"
log = "0.4"
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
linux-embedded-hal = "0.4.0"
anyhow = "1.0.80"
anyhow = { version = "1.0" , default-features = false}
[dev-dependencies]
env_logger = "0.9"
env_logger = "0.11.5"
[target.'cfg(target_os = "linux")'.dependencies]
linux-embedded-hal = "0.4.0"

View file

@ -10,13 +10,18 @@ To use this library, create a new project and add it as a dependency:
```toml
[dependencies]
bme680 = {git = "https://github.com/dnutiu/bme680-rust.git", version = "0.8.0"}
bme680 = {git = "https://github.com/dnutiu/bme680-rust.git", version = "0.9.0"}
```
# Alternative
[drogue-bme680](https://github.com/drogue-iot/drogue-bme680)
# Getting started on Raspberry Pi
# Example getting started Linux
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
@ -40,3 +45,17 @@ pi@raspberrypi:~ $ i2cdetect -y 1
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76
```
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:
```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
```

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -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"

View file

@ -1,5 +1,3 @@
#![no_std]
use bme680::i2c::Address;
use bme680::{Bme680, IIRFilterSize, OversamplingSetting, PowerMode, SettingsBuilder};
use core::time::Duration;
@ -30,7 +28,7 @@ fn main() -> Result<(), anyhow::Error> {
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)?;

View file

@ -4,6 +4,44 @@ use core::time::Duration;
/// Calculates values needed or returned by the BME80 Sensor.
pub struct Calculation {}
static GAS_LOOKUP_TABLE_1: [u32; 16] = [
2147483647u32,
2147483647u32,
2147483647u32,
2147483647u32,
2147483647u32,
2126008810u32,
2147483647u32,
2130303777u32,
2147483647u32,
2147483647u32,
2143188679u32,
2136746228u32,
2147483647u32,
2126008810u32,
2147483647u32,
2147483647u32,
];
static GAS_LOOKUP_TABLE_2: [u32; 16] = [
4096000000u32,
2048000000u32,
1024000000u32,
512000000u32,
255744255u32,
127110228u32,
64000000u32,
32258064u32,
16016016u32,
8000000u32,
4000000u32,
2000000u32,
1,
500000u32,
250000u32,
125000u32,
];
impl Calculation {
/// Calculates and returns the sensor's heater resistance.
/// * `calibration_data` - The calibration data of the sensor.
@ -141,13 +179,8 @@ impl Calculation {
let var4: i32 = (var4 + temp_scaled * calibration_data.par_h7 as i32 / 100i32) >> 4i32;
let var5: i32 = ((var3 >> 14i32) * (var3 >> 14i32)) >> 10i32;
let var6: i32 = (var4 * var5) >> 1i32;
let mut calc_hum: i32 = (((var3 + var6) >> 10i32) * 1000i32) >> 12i32;
if calc_hum > 100000i32 {
calc_hum = 100000i32;
} else if calc_hum < 0i32 {
calc_hum = 0i32;
}
calc_hum as u32
let calc_hum: i32 = (((var3 + var6) >> 10i32) * 1000i32) >> 12i32;
calc_hum.clamp(0, 100000) as u32
}
/// Calculates and returns the gas resistance.
@ -159,47 +192,11 @@ impl Calculation {
gas_resistance_adc: u16,
gas_range: u8,
) -> u32 {
let lookup_table1: [u32; 16] = [
2147483647u32,
2147483647u32,
2147483647u32,
2147483647u32,
2147483647u32,
2126008810u32,
2147483647u32,
2130303777u32,
2147483647u32,
2147483647u32,
2143188679u32,
2136746228u32,
2147483647u32,
2126008810u32,
2147483647u32,
2147483647u32,
];
let lookup_table2: [u32; 16] = [
4096000000u32,
2048000000u32,
1024000000u32,
512000000u32,
255744255u32,
127110228u32,
64000000u32,
32258064u32,
16016016u32,
8000000u32,
4000000u32,
2000000u32,
1,
500000u32,
250000u32,
125000u32,
];
let var1: i64 = ((1340 + 5 * calibration_data.range_sw_err as i64)
* lookup_table1[gas_range as usize] as i64)
* GAS_LOOKUP_TABLE_1[gas_range as usize] as i64)
>> 16;
let var2: u64 = (((gas_resistance_adc as i64) << 15) - 16777216 + var1) as u64;
let var3: i64 = (lookup_table2[gas_range as usize] as i64 * var1) >> 9;
let var3: i64 = (GAS_LOOKUP_TABLE_2[gas_range as usize] as i64 * var1) >> 9;
let calc_gas_res: u32 = ((var3 + ((var2 as i64) >> 1i64)) / var2 as i64) as u32;
calc_gas_res
}

View file

@ -3,62 +3,6 @@
//!
//! The library uses the embedded-hal crate 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 crate (e.g. on a RPI).
//! ```no_run
//! use bme680::{Bme680, IIRFilterSize, OversamplingSetting, PowerMode, SettingsBuilder};
//! use core::time::Duration;
//! use embedded_hal::delay::DelayNs;
//! use linux_embedded_hal as hal;
//! use linux_embedded_hal::Delay;
//! use log::info;
//! use bme680::i2c::Address;
//!
//! // 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, 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_run_gas(true)
//! .build();
//!
//! 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)?;
//! 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 {
//! 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_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());
//! }
//! }
#![no_std]
#![forbid(unsafe_code)]
@ -416,7 +360,7 @@ where
pub fn set_sensor_settings(
&mut self,
delay: &mut D,
settings: Settings,
settings: &Settings,
) -> Result<(), anyhow::Error> {
let (sensor_settings, desired_settings) = settings;
let tph_sett = sensor_settings.temperature_settings;

View file

@ -140,7 +140,7 @@ bitflags! {
/// To set NB conversion setting.
const NBCONV_SEL = 128;
/// To set all gas sensor related settings
const GAS_SENSOR_SEL = Self::GAS_MEAS_SEL.bits | Self::RUN_GAS_SEL.bits | Self::NBCONV_SEL.bits;
const GAS_SENSOR_SEL = Self::GAS_MEAS_SEL.bits() | Self::RUN_GAS_SEL.bits() | Self::NBCONV_SEL.bits();
}
}