GithubHelp home page GithubHelp logo

libscd's Introduction

Lib SCD

License Version Downloads Build

LibSCD is s Rust driver implementation for SCD30, SCD40 and SCD41 sensors using the embedded-hal and embedded-hal-async interfaces.

Usage

Add the crate as a dependency in Cargo.toml and select the required features:

[dependencies.libscd]
version = "0.3"
features = ["defmt", "sync", "scd40"]

Then we can start consuming data from SCD40 using blocking I2C communication:

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p = embassy_stm32::init(Default::default());

    let i2c = I2c::new(
        p.I2C2,
        p.PB10,
        p.PB3,
        Irqs,
        NoDma,
        NoDma,
        Hertz(100_000),
        Default::default(),
    );

    let mut scd = Scd40::new(i2c, Delay);

    // When re-programming, the controller will be restarted,
    // but not the sensor. We try to stop it in order to
    // prevent the rest of the commands failing.
    _ = scd.stop_periodic_measurement();

    info!("Sensor serial number: {:?}", scd.serial_number());
    if let Err(e) = scd.start_periodic_measurement() {
        defmt::panic!("Failed to start periodic measurement: {:?}", e);
    }

    loop {
        if scd.data_ready().unwrap() {
            let m = scd.read_measurement().unwrap();
            info!("CO2: {}\nHumidity: {}\nTemperature: {}", m.co2, m.humidity, m.temperature)
        }

        Delay.delay_ms(1000)
    }
}

Crate Feature Flags

The support for each sensor and sync/async mode is controlled by a feature:

Feature Description
sync Enables the blocking driver implementation for the selected sensors
async Enables the async driver implementation for the selected sensors
scd30 Enables the driver for the SCD30 sensor
scd40 Enables the driver for the SCD40 sensor
scd41 Enables the driver for the SCD41 sensor
defmt Derive defmt::Format for the error type

License

The project is dual licensed under MIT or APACHE-2.0

libscd's People

Contributors

svetlinzarev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.