scd30_i2c

Crates.ioscd30_i2c
lib.rsscd30_i2c
version1.0.0
created_at2024-05-03 14:19:15.772183+00
updated_at2025-04-05 06:45:59.261812+00
descriptionRust Trait for SCD30 device I2C interface related operations.
homepage
repositoryhttps://github.com/FStanDev/scd30_i2c
max_upload_size
id1228841
size24,632
(FStanDev)

documentation

https://docs.rs/scd30_i2c/

README

SCD30 trait implementing basic SCD30 I2C CO2 sensor operations

Operations taken from interface description

At current version 1.0.0 we support all basic operations from the interface

Basic Example

In your Cargo.toml scd30_i2c="0.1.2"

Obtaining measurements, co2, temperature and humidity

use scd30_i2c::scd30::Scd30;
use std::thread;
use std::time::Duration;

fn main() {
    // Open the I2C device
    let mut scd = Scd30::new().unwrap();
    let mut counter = 0;
    scd.trigger_cont_measurements();

    scd.set_measurements_interval(2);

    loop {
        match scd.get_measurements() {
            Ok((a, b, c)) => {
                println!("Co2: {} ppm Temp: {} C RH: {} %", a, b, c);
                thread::sleep(Duration::from_secs(2));
                counter += 1;
                println!("{}", counter);
            }
            Err(e) => {
                println!(
                    "Error obtaining measurements. More details: {}. Waiting 10 seconds for recovering",
                    e
                );
                thread::sleep(Duration::from_secs(10));
            }
        }
    }
}

Hardware

I made and tested this library using a Raspberry Pi 5 and its I2C capabilities, for other machines running Linux should work, but I don't have more devices to test

More Info

This is my first crate made with Rust, so any suggestion is more than welcome.

Special Thanks

Special thanks to RequestForCoffe for the amazing libray in Python. I used the library a lot to understand and replicate the code in Rust.

Commit count: 18

cargo fmt