Changed status handling as it seems as if the mhz19B returns 0 instead of 0x40 like the mhz19.

This commit is contained in:
Tobias Schürg 2018-06-24 14:38:42 +02:00
parent 29ea8e92bc
commit a66da23b89
2 changed files with 25 additions and 16 deletions

View file

@ -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);
}

22
MHZ.cpp
View file

@ -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;