mirror of
https://github.com/sigmasternchen/MH-Z-CO2-Sensors
synced 2025-03-15 06:38:55 +00:00
Changed status handling as it seems as if the mhz19B returns 0 instead of 0x40 like the mhz19.
This commit is contained in:
parent
29ea8e92bc
commit
a66da23b89
2 changed files with 25 additions and 16 deletions
19
MH-Z19B.ino
19
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);
|
||||
}
|
||||
|
|
22
MHZ.cpp
22
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;
|
||||
|
|
Loading…
Reference in a new issue