Commit b47849e8 authored by Melroy van den Berg's avatar Melroy van den Berg

Add humidity compensation

parent efbeed2b
Pipeline #1063 passed with stages
in 13 seconds
......@@ -31,6 +31,9 @@
#define I2C_PATH_LEN 20 /**< max length of /dev/i2c-N */
#define I2C2_BUS 2 /**< Connected to /dev/i2c-2 */
// Hack solution, global
uint32_t absoluteHumidity = {0};
/**
* \brief Execute gas measurement using SGP30
* \param i2c_fd I2C bus file descriptor
......@@ -49,22 +52,24 @@ bool DoGasMeasurement(int i2c_fd) {
return false;
}
// TODO: first 15 seconds after init, returns fixed values (so should be ignored)
// According to the specs we need to sent regular internals of 1s to ensure proper dynamic baseline compensation algo
// although, it doesn't say for how long.
// Also: According to the specs we need to sent regular internals of 1s to ensure proper dynamic baseline compensation algo.
// This time interval needs to be done forever.
printf("INFO: Absolute humidty is set to: %u\n", absoluteHumidity);
sgp.SetHumidity(absoluteHumidity);
int counter = 0;
while(counter < 35) {
while(counter < 40) {
// Do measurement
if(!sgp.DoMeasurement()) {
printf("Error: Air quality measurement failed.");
return false;
}
// Print!
printf("TVOC : %dppb\n", sgp.TVOC);
printf("eCO2 : %dppm\n", sgp.eCO2);
// Sleep 1 second
// TODO: embedded a delay within DoMeasurement()
// TODO: embedded a delay within DoMeasurement()?
usleep(1000000);
counter++;
}
......@@ -90,7 +95,7 @@ bool DoDustMeasurement() {
printf("%.3f μ g/m3 PM10\n\n", pmsa.pm10);
}
// Sleep 1 second
// TODO: embedded a delay within DoMeasurement()
// TODO: embedded a delay within DoMeasurement()?
usleep(1000000);
counter++;
}
......@@ -110,8 +115,9 @@ bool DoCO2Measurement() {
printf("%d ppm CO2\n", mhz19b.CO2);
printf("%d degrees C\n\n", mhz19b.temperature);
}
// Sleep 1 second
// TODO: embedded a delay within DoMeasurement()
// TODO: embedded a delay within DoMeasurement()?
usleep(1000000);
counter++;
}
......@@ -157,12 +163,14 @@ bool DoTempMeasurement(int i2c_fd) {
// 1/60Hz = 60000 ms
// 25Hz = 40ms (use 45ms on the safe side)
usleep(45000);
bme280_data data = bme.getAllSensorData();
printf("%.2f °C\n", data.temperature);
printf("%.2f %%\n", data.humidity);
printf("%.2f hPa\n", data.pressure);
printf("%.2f humidity (mg/m3)\n\n", WeatherEnvironment::GetAbsoluteHumidity(data.temperature, data.humidity) * 1000.0);
// Absolute humidity in (mg/m3)
absoluteHumidity = static_cast<uint32_t>(1000.0f * WeatherEnvironment::GetAbsoluteHumidity(data.temperature, data.humidity));
counter++;
}
return true;
......@@ -189,14 +197,14 @@ int OpenI2C() {
* \return status code
*/
int main() {
LED led;
LED led; // default init seq
//DoDustMeasurement();
//DoCO2Measurement();
int i2c_fd = OpenI2C();
//DoGasMeasurement(i2c_fd);
DoTempMeasurement(i2c_fd);
DoGasMeasurement(i2c_fd);
// Close the I2C file descriptor
close(i2c_fd);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment