Basic and noob question.
Posted: Sat May 25, 2024 11:21 pm
- hello everyone, i am new to esp8266 and arduino and i have a very basic question, i am using sensiron scd41 sensor to measure C02, temp and humidity and below is the example code provided by sensiron. My question is if i only want to measure CO2, how can i do that as the scd4x.readMeasurement function needs the 3 arguments( co2, temp and humidity) but how can i only pass one argument or just one or two values?
#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>
SensirionI2CScd4x scd4x;
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Wire.begin();
uint16_t error;
char errorMessage[256];
scd4x.begin(Wire);
// Start Measurement
error = scd4x.startPeriodicMeasurement();
if (error) {
Serial.print("Error trying to execute startPeriodicMeasurement(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
Serial.println("Waiting for first measurement... (5 sec)");
}
uint16_t co2 = 0;
float temperature = 0.0f;
float humidity = 0.0f;
void loop() {
uint16_t error;
char errorMessage[256];
delay(100);
// Read Measurement
bool isDataReady = false;
error = scd4x.getDataReadyFlag(isDataReady);
if (error) {
Serial.print("Error trying to execute getDataReadyFlag(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
return;
}
if (!isDataReady) {
return;
}
error = scd4x.readMeasurement(co2, temperature, humidity);
if (error) {
Serial.print("Error trying to execute readMeasurement(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
} else if (co2 == 0) {
Serial.println("Invalid sample detected, skipping.");
} else {
Serial.print("Co2:");
Serial.print(co2);
Serial.print("\t");
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("\t");
Serial.print("Humidity:");
Serial.println(humidity);
}
}
```