dbrgn / sgp30-rs

Platform agnostic Rust driver for the Sensirion SGP30 gas sensor.
Apache License 2.0
9 stars 5 forks source link

ESP32 & spg30-rs #13

Closed ds2k5 closed 10 months ago

ds2k5 commented 10 months ago

Hi, how to use spg30-rs with https://github.com/esp-rs/esp-idf-template ?

There is no device: /dev/i2c-1

cargo generate --git https://github.com/esp-rs/esp-idf-template cargo
cd projectname
cargo add sgp30
cargo add esp-idf-hal
. ~/export-esp.sh
cargo check

use esp_idf_hal::blocking::delay::DelayMs;
use hal::Delay;
use sgp30::Measurement;

fn main() {
    // It is necessary to call this function once. Otherwise some patches to the runtime
    // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
    esp_idf_svc::sys::link_patches();

    // Bind the log crate to the ESP Logging facilities
    esp_idf_svc::log::EspLogger::initialize_default();

loop {
    let measurement: Measurement = sgp.measure().unwrap();
    println!("CO₂eq parts per million: {}", measurement.co2eq_ppm);
    println!("TVOC parts per billion: {}", measurement.tvoc_ppb);
    Delay.delay_ms(1000u16 - 12);
}

}

error[E0433]: failed to resolve: could not find `blocking` in `esp_idf_hal`
 --> src/main.rs:1:18
  |
1 | use esp_idf_hal::blocking::delay::DelayMs;
  |                  ^^^^^^^^ could not find `blocking` in `esp_idf_hal`

error[E0432]: unresolved import `hal`
 --> src/main.rs:2:5
  |
2 | use hal::Delay;
  |     ^^^ help: a similar path exists: `esp_idf_svc::hal`

error[E0425]: cannot find value `sgp` in this scope
  --> src/main.rs:15:36
   |
15 |     let measurement: Measurement = sgp.measure().unwrap();
   |                                    ^^^ not found in this scope

Some errors have detailed explanations: E0425, E0432, E0433.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `esp32-spg30` (bin "esp32-spg30") due to 3 previous errors

thanks

rnestler commented 10 months ago

Hi @ds2k5

I guess you'll have to look up in the https://github.com/esp-rs/esp-idf-hal documentation how to use I2C on the platform.

Maybe https://github.com/esp-rs/esp-idf-hal/blob/master/examples/i2c_master_slave.rs helps?