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! // Try to initialize!
if (!scd30.begin()) { if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip"); Serial.println("scd30: Failed to find SCD30 chip");
while (1) { delay(10); } while (1) { delay(10); }
} }
Serial.println("SCD30 Found!"); Serial.println("scd30: SCD30 Found!");
if (!scd30.setMeasurementInterval(2)){ scd30.reset();
Serial.println("Failed to set measurement interval");
if (!scd30.setMeasurementInterval(15)){ // seconds
Serial.println("scd30: Failed to set measurement interval");
while(1) {delay(10);} while(1) {delay(10);}
} }
Serial.print("Measurement Interval: "); Serial.print("scd30: Measurement Interval: ");
Serial.print(scd30.getMeasurementInterval()); Serial.print(scd30.getMeasurementInterval());
Serial.println(" seconds"); Serial.println(" seconds");
if(!scd30.startContinuousMeasurement()) {
Serial.println("scd30: Could not start continuous measurement");
}
} }
@ -34,13 +40,23 @@ void setup(void)
void loop(void) void loop(void)
{ {
if (!scd30.read()) { if(scd30.dataReady()) {
Serial.println("Error reading sensor data"); if (!scd30.read()) {
return; Serial.println("Error reading sensor data");
return;
}
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("");
} }
Serial.print("CO2: "); delay(1000);
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.println("");
} }