sparkfun / SparkFun_SCD4x_Arduino_Library

An Arduino library for the Sensirion SCD4x (SCD40 and SCD41) family of CO2 sensors
Other
11 stars 8 forks source link

Add Sleep\Wake feature #8

Open chinswain opened 3 months ago

chinswain commented 3 months ago

I've attempted to add the sleep\wake feature: https://github.com/chinswain/SparkFun_SCD4x_Arduino_Library

added to .h

  bool scd4x_power_down(void);
  uint8_t scd4x_wake_up(void);

added to .cpp

bool scd4x_power_down() {
    Wire.beginTransmission(SCD4x_ADDRESS);
    Wire.write(0x36);
    Wire.write(0xE0);
    int error = Wire.endTransmission();

    if (error) {
        return error;
    }

    delayMicroseconds(1000);  // Sleep for 1000 microseconds
    return (true);
}

int16_t scd4x_wake_up() {
    Wire.beginTransmission(SCD4x_ADDRESS);
    Wire.write(0x36);
    Wire.write(0xF6);
    (void)Wire.endTransmission();  // Ignore the error as per the original function

    delay(20);  // Sleep for 20 milliseconds
    return (true);
}

Docs: https://sensirion.com/media/documents/E0F04247/631EF271/CD_DS_SCD40_SCD41_Datasheet_D1.pdf

image