diff --git a/MH-Z19B.ino b/MH-Z19B.ino index d47b5ad..63d2c97 100644 --- a/MH-Z19B.ino +++ b/MH-Z19B.ino @@ -26,16 +26,23 @@ void loop() { // Serial.print("\n----- Time from start: "); // Serial.print(millis() / 1000); // Serial.println(" s"); + int ppm_uart = co2.readCO2UART(); + if (ppm_uart > 0) { + Serial.print("PPMuart: "); + Serial.print(ppm_uart); + } + // int ppm_pwm = co2.readCO2PWM(); - int temperature = co2.getLastTemperature(); - Serial.print("PPMuart: "); - Serial.print(ppm_uart); // Serial.print(", PPMpwm: "); // Serial.print(ppm_pwm); - Serial.print(", Temperature: "); - Serial.println(temperature); + + int temperature = co2.getLastTemperature(); + if (temperature > 0) { + Serial.print(", Temperature: "); + Serial.println(temperature); + } // Serial.println("\n------------------------------"); - // delay(3000); + delay(1000); } diff --git a/MHZ.cpp b/MHZ.cpp index 2dcb8ec..05c7119 100644 --- a/MHZ.cpp +++ b/MHZ.cpp @@ -84,28 +84,30 @@ int MHZ::readCO2UART() { Serial.println(response[8], HEX); Serial.print("MHZ: Should be: "); Serial.println(check, HEX); + temperature = -1; // TODO maybe change to another magic value + return -1; } int ppm_uart = 256 * (int)response[2] + response[3]; temperature = response[4] - 44; // - 40; + byte status = response[5]; if (debug) { Serial.print(" # PPM UART: "); Serial.println(ppm_uart); Serial.print(" # Temperature? "); Serial.println(temperature); + } - // status - // not sure about this... - byte status = response[5]; - Serial.print(" Status? "); - Serial.print(status); - if (status == 0x40) { - Serial.println(" - Status OK"); - } else { - Serial.println(" ! Status not OK !"); - } + // Is always 0 for version b + // Version a: status != 0x40 + if (debug || status != 0) { + Serial.print(" ! Status not OK ! "); + Serial.println(status, HEX); + } else if (debug) { + Serial.print(" Status OK: "); + Serial.println(status, HEX); } return ppm_uart;