Part of code, where is reading from serial.
// D5 -> TX na MH-Z19B
// D6 -> RX na MH-Z19B
SoftwareSerial co2_senzor(D5, D6);
// measure CO2
int16_t zmeritKoncentraci() {
// send 9B instruction with request co2 value
uint8_t command[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
co2_senzor.write(command, sizeof(command));
// read 9B from serial
uint8_t answer[9];
co2_senzor.readBytes(answer, sizeof(answer));
if ((answer[0] == 0xFF) && (answer[1] == 0x86)) {
// checksum
uint8_t ks = 0;
for (uint8_t i = 1; i < 8; i++) {
ks += answer[i];
}
ks = (255 - ks) + 1;
if (answer[8] == ks) {
uint16_t ppm = (answer[2] << 8) ^ answer[3];
return ppm;
}
else {
return -1;
}
}
else {
return -1;
}
}So, where could be problem? Can you help me with debug serial message- how can i serial.print answer in raw format?