Comments (6)
Let me first say that I'm just a Rust beginner. As far as I know VersBinarii's version does not consume the delay. That's the whole point. It takes mutable reference (or whatever that's called in Rust).
/// Initializes the BME280
pub fn init<D>(&mut self, delay: &mut D) -> Result<(), Error<E>>
where
D: DelayMs<u8>,
{...}
The constructor doesn't even see the delay.
With VersBinarii's version I was able to build my little nRF example, reading sensor data in a loop with a 1s delay.
let mut delay = Delay::new(cp.SYST);
// initialize the BME280 using the primary I2C address 0x76
let mut bme280 = BME280::new_secondary(i2c);
let _ = bme280.init(&mut delay).unwrap();
loop {
delay.delay_ms(1000u16);
let measurements = bme280.measure(&mut delay).unwrap();
rprintln!("Relative Humidity = {:.2}%", measurements.humidity);
rprintln!("Temperature = {:.1} °C", measurements.temperature);
rprintln!("Pressure = {:.2} hPa", measurements.pressure / 100f32);
}
from bme280-rs.
I agree, this feature makes the driver practically unusable on embedded where Delay
cannot be cloned.
from bme280-rs.
I am looking to write a version that will allow this to work by borrowing but as a first pass i have implemented a very simple release()
function here https://github.com/fishrockz/bme280-rs/tree/willsalmon/release
Release is not ideal but it lets you do things like
loop {
delay(clocks.sysclk().0 / 100);
// The Aidafruit boards have address 0x77 without closing the jumper on the back, the BME280 lib connects to 0x77 with `new_secondary`, use
// `new_primary` for 0x76 if you close teh jumper/solder bridge.
{
let mut bme280 = BME280::new(spi, cs_bme, delay_ob).unwrap();
bme280
.init()
.map_err(|error| {
hprintln!("Could not initialize bme280, Error: {:?}", error).unwrap();
panic!();
})
.unwrap();
match bme280.measure() {
Ok(measurements) => {
hprintln!("Relative Humidity = {}%", measurements.humidity).unwrap();
hprintln!("Temperature = {} deg C", measurements.temperature).unwrap();
hprintln!("Pressure = {} pascals", measurements.pressure).unwrap();
write!(&mut arr_message, "The presure is {}", measurements.pressure)
.expect("Can't write");
}
Err(error) => {
hprintln!("Could not read bme280 due to error: {:?}", error).unwrap();
}
}
for (i, c) in arr_message.chars().enumerate() {
buffer[i] = c as u8;
}
hprintln!("buffer {:?}?", buffer).unwrap();
(spi, cs_bme, delay_ob) = bme280.release();
}
{
//lora.set_mode(sx127x_lora::RadioMode::Tx).unwrap();
let mut lora = sx127x_lora::LoRa::new(spi, cs_lora, reset, 434, delay_ob).unwrap();
lora.set_tx_power(17, 1).unwrap(); //Using PA_BOOST. See your board for correct pin.
let transmit = lora.transmit_payload(buffer, arr_message.len());
match transmit {
Ok(()) => hprintln!("Sent packet").unwrap(),
Err(e) => hprintln!("Error {:?}", e).unwrap(),
};
delay(clocks.sysclk().0 * 5);
(spi, cs_lora, reset, delay_ob) = lora.release();
}
}
Which is no good if you need to quickly swap back and forth but dose let you swap back and for slowly.
I have not created a PR yet as I am working on top of #6 which is approved but not merged.
from bme280-rs.
Notice that VersBinarii has a solution.
from bme280-rs.
Notice that VersBinarii has a solution.
I'm missing something: what is the solution? Looks to me like it has the same problem, consuming the delay. Which unfortunately is a problem of some other sensors, too, those that require a specific amount of time between one thing and another. Ideally there is a bit you can keep reading, but if the datasheet says "wait 30 ms", the delay seems to be the (only?) option.
from bme280-rs.
Let me first say that I'm just a Rust beginner. As far as I know VersBinarii's version does not consume the delay. That's the whole point. It takes mutable reference (or whatever that's called in Rust).
Gotcha! Yes, I didn't notice that it was only borrowing the delay (yep, it is called a mutable reference). Thanks!!!
from bme280-rs.
Related Issues (20)
- RTIC example? HOT 5
- BME280 not working on ESP32 HOT 2
- Suggestion to add embedded-hal feature flag HOT 3
- Ability to configure oversampling and IIR filter HOT 2
- Build fails for ESP32 HOT 11
- Example from README not working HOT 5
- SPI communication doesn't work HOT 6
- I2C address inconsistency HOT 2
- Is a pinned embedded-hal necessary? HOT 2
- Use configurable readout delay HOT 1
- New Release? HOT 2
- New crates.io release for eh v1.0.0 update HOT 2
- failed to select a version for `embedded-hal`
- called `Result::unwrap()` on an `Err` value: InvalidData HOT 10
- `SensorMode` is not available
- How to use without delay provider HOT 1
- Driver panics when trying to make a measurement with BME280 HOT 3
- Allow sharing the I2C bus. HOT 2
- Implement `std::error::Error` for public `Error` struct HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bme280-rs.