Closed enelson1001 closed 2 years ago
The problem is here:
bme280-rs
is already using the embedded-hal
1.0 alpha version which is not yet supported here in shared-bus
unfortunately (we're still on 0.2.x). This is in the works but I don't have anything ready yet...
Pull-request #36 should help. I added support for the latest embedded-hal alpha's I2C traits over there. However, your dependencies are still on alpha.7
while the latest release is alpha.8
so you'll have to get them update first as well.
Please let me know once you've tested this, I'll then merge the PR and publish a new release.
I have updated bme280-rs locally to use alpha.8. Does PR#36 support alpha.8 as esp_idf_hal requires alpha.8.
Thanks
This is what I did
Modified my project cargo.toml with the following.
shared-bus = {git = "https://github.com/Rahix/shared-bus.git", version = "0.2.3", branch = "i2c-eh-alpha", features = ["eh-alpha"]}
My code in main:
let peripherals = Peripherals::take().unwrap();
let pins = peripherals.pins;
// Create i2c interface on I2C0 with bus speed of 400kHz
let i2c0 = peripherals.i2c0;
let scl = pins.gpio22;
let sda = pins.gpio21;
let i2c_config = <i2c::config::MasterConfig as Default>::default().baudrate(400.kHz().into());
let i2c_bus_0 = i2c::Master::<i2c::I2C0, _, _>::new(i2c0, i2c::MasterPins { sda, scl }, i2c_config).unwrap();
let i2c_bus_manager = shared_bus::BusManagerSimple::new(i2c_bus_0);
let mut i2c_bme280 = BME280::new_primary(i2c_bus_manager.acquire_i2c());
//let mut i2c_bme280 = BME280::new_primary(i2c_bus_0);
let mut delay = delay::Ets;
i2c_bme280.init(&mut delay).unwrap();
thread::sleep(Duration::from_millis(5000));
let mut count = 0;
loop {
let measurements = i2c_bme280.measure(&mut delay).unwrap();
println!("Relative Humidity = {}%", measurements.humidity);
println!("Temperature = {} deg C", measurements.temperature);
println!("Pressure = {} pascals", measurements.pressure);
count += 1;
thread::sleep(Duration::from_millis(5000));
if count == 5 {
break;
}
}
And now everything works (I haven't shared bus with SSD1306 display yet but will do shortly)
One question - We can't pass i2c_bus_manager as a reference correct? But we can make static?
thanks
Great, thanks for testing! I'll get the PR merged.
One question - We can't pass i2c_bus_manager as a reference correct? But we can make static?
Please open a new issue and describe in more detail what you need.
I am trying to use shared-bus with ESP32 using esp_idf_hal and bme280-rs. If I don't use shared-bus I have no problems using bme280.
Code with problems
Errors
How can I make shared-bus work with esp_idf_hal and bme280-rs?