I am new to Arduino, and I have been trying to modify the DH11 sketch to suit my LCD screen. Everything is working perfectly, but I have a problems with the isnan and serial.
As seen on the code below, I want the serial to output a error message when the sensor is not present or working. I have been searching around for "isnan" but there is little information. When I unplug the sensor, is shows the value 0 at LCD, and nothing in Serial.
Can I also display the message on the LCD with lcd.print("Message..");??
Last question, what is the difference between print and println?
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
else...
// Check if any reads failed and exit early (to try again).
if (h==0) {
Serial.println("Failed to read from DHT sensor!");
return;
}
And this worked perfectly. Could you explain to me why the DHTester example in the library, uses the code I mentioned and does indeed report back in serial? Is it because it uses the float datatype?
I am new to Arduino, and I have been trying to modify the DH11 sketch to suit my LCD screen. Everything is working perfectly, but I have a problems with the isnan and serial.
As seen on the code below, I want the serial to output a error message when the sensor is not present or working. I have been searching around for "isnan" but there is little information.
When using floating pointg numbers and formatting the result into ASCII and you get 'float' formatted to "isnan", then the meaning is: "is not a number".
As simple as that.
Typically this isnan value is the result of DOING A SEVERE MISTAKE WITH FLOATING POINT MATH!
Especially after doing a "floating point math division by zero, the result will be nan (not a number).
And the difference between print() and println (short for "print line") is this:
The print line println() command will add two extra characters for two functions that could be executed by electric typewriters in former times:
carriage return (CR, ASCII-code 13)
line feed (LF, ASII -code 10)
On old electrical typewriters the "carriage return" and "linefeed" control characters would do mechanical functions.
But when used on the serial monitor, the same control codes will simply place the writing mark (cursor or caret) at the left-most writing position in the next line.
When used in the last line of the serial monitor, the previous contents in the serial monitor will scroll one line up and then start a new line with the cursor in the left-most writing position.