bme280-rs
bme280-rs copied to clipboard
Example from README not working
Hi!
I was trying to implement the bme280 crate in a project of mine. While trying I always ran into some issues. I was then running the example from the README and the basic.rs
example from the examples folder..
I always run into the following errors:
error[E0277]: the trait bound `I2cdev: embedded_hal::i2c::blocking::I2c` is not satisfied
--> src/main.rs:8:44
|
8 | let mut bme280 = BME280::new_secondary(i2c_bus);
| --------------------- ^^^^^^^ the trait `embedded_hal::i2c::blocking::I2c` is not implemented for `I2cdev`
| |
| required by a bound introduced by this call
|
note: required by a bound in `bme280::i2c::BME280::<I2C>::new_secondary`
--> /cargo/registry/src/github.com-1ecc6299db9ec823/bme280-0.4.4/src/i2c.rs:22:10
|
22 | I2C: I2c + ErrorType,
| ^^^ required by this bound in `bme280::i2c::BME280::<I2C>::new_secondary`
error[E0599]: the method `init` exists for struct `bme280::i2c::BME280<I2cdev>`, but its trait bounds were not satisfied
--> src/main.rs:10:12
|
10 | bme280.init(&mut delay).unwrap();
| ^^^^ method cannot be called on `bme280::i2c::BME280<I2cdev>` due to unsatisfied trait bounds
|
::: /cargo/registry/src/github.com-1ecc6299db9ec823/linux-embedded-hal-0.3.2/src/lib.rs:124:1
|
124 | pub struct I2cdev {
| -----------------
| |
| doesn't satisfy `I2cdev: embedded_hal::i2c::ErrorType`
| doesn't satisfy `I2cdev: embedded_hal::i2c::blocking::I2c`
|
= note: the following trait bounds were not satisfied:
`I2cdev: embedded_hal::i2c::blocking::I2c`
`I2cdev: embedded_hal::i2c::ErrorType`
error[E0599]: the method `measure` exists for struct `bme280::i2c::BME280<I2cdev>`, but its trait bounds were not satisfied
--> src/main.rs:12:35
|
12 | let measurements = bme280.measure(&mut delay).unwrap();
| ^^^^^^^ method cannot be called on `bme280::i2c::BME280<I2cdev>` due to unsatisfied trait bounds
|
::: /cargo/registry/src/github.com-1ecc6299db9ec823/linux-embedded-hal-0.3.2/src/lib.rs:124:1
|
124 | pub struct I2cdev {
| -----------------
| |
| doesn't satisfy `I2cdev: embedded_hal::i2c::ErrorType`
| doesn't satisfy `I2cdev: embedded_hal::i2c::blocking::I2c`
|
= note: the following trait bounds were not satisfied:
`I2cdev: embedded_hal::i2c::blocking::I2c`
`I2cdev: embedded_hal::i2c::ErrorType`
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `bmetest` due to 3 previous errors
I suppose it's an issue in the linux-embedded-hal crate but I wanted to ask for advice on how to fix this in case I'm doing something wrong...
Also, would you mind a MR removing the example from the README and replace it with a link to the examples folder? Or do you have the example in the README for docs.rs/crates.io?
I have been running into the same problem with the latest version (0.4.4).
With
[dependencies]
bme280 = "0.3.0"
linux-embedded-hal = { version = "0.3", features = ["gpio_cdev"] }
The code compiles and runs, so it seems to be a regression.
Can you please try the linux-embedded-hal with the latest embedded-hal alpha releases? Those errors are related to the traits introduced in the e-h alpha releases. https://lib.rs/crates/linux-embedded-hal
With
bme280 = "0.4.4"
linux-embedded-hal = "0.4.0-alpha.3"
I get:
error: failed to select a version for `embedded-hal`.
... required by package `linux-embedded-hal v0.4.0-alpha.3`
versions that meet the requirements `=1.0.0-alpha.8` are: 1.0.0-alpha.8
all possible versions conflict with previously selected packages.
previously selected package `embedded-hal v1.0.0-alpha.7`
... which is depended on by `bme280 v0.4.4`
failed to select a version for `embedded-hal` which could resolve this conflict
With one version older:
bme280 = "0.4.4"
linux-embedded-hal = "0.4.0-alpha.2"
it compiles (Delay argument is at different places, though)
I opened https://github.com/VersBinarii/bme280-rs/pull/23 to update to 1.0.0-alpha.8
The PR has been merged