From 8d5b1a425b77f16c0a7665692721422016596227 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sun, 16 Jun 2024 17:16:58 +0200 Subject: [PATCH] Improve SCD30 readout flow --- src/main.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 37436f1..1c68349 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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,13 +40,23 @@ void setup(void) void loop(void) { - if (!scd30.read()) { - Serial.println("Error reading sensor data"); - return; + if(scd30.dataReady()) { + if (!scd30.read()) { + 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: "); - Serial.print(scd30.CO2, 3); - Serial.println(" ppm"); - Serial.println(""); + delay(1000); }