Improve SCD30 readout flow

This commit is contained in:
Thomas Kolb 2024-06-16 17:16:58 +02:00
parent c0e8685f83
commit 8d5b1a425b

View file

@ -9,18 +9,24 @@ void initSCD30(void)
{
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
Serial.println("scd30: Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
Serial.println("scd30: SCD30 Found!");
if (!scd30.setMeasurementInterval(2)){
Serial.println("Failed to set measurement interval");
scd30.reset();
if (!scd30.setMeasurementInterval(15)){ // seconds
Serial.println("scd30: Failed to set measurement interval");
while(1) {delay(10);}
}
Serial.print("Measurement Interval: ");
Serial.print("scd30: Measurement Interval: ");
Serial.print(scd30.getMeasurementInterval());
Serial.println(" seconds");
if(!scd30.startContinuousMeasurement()) {
Serial.println("scd30: Could not start continuous measurement");
}
}
@ -34,6 +40,7 @@ void setup(void)
void loop(void)
{
if(scd30.dataReady()) {
if (!scd30.read()) {
Serial.println("Error reading sensor data");
return;
@ -42,5 +49,14 @@ void loop(void)
Serial.print("CO2: ");
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.print("Temperature: ");
Serial.print(scd30.temperature, 3);
Serial.println(" °C");
Serial.print("Rel. humidity: ");
Serial.print(scd30.relative_humidity, 2);
Serial.println(" %");
Serial.println("");
}
delay(1000);
}