Improve SCD30 readout flow
This commit is contained in:
parent
c0e8685f83
commit
8d5b1a425b
40
src/main.cpp
40
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue