I didn't take out the whole line though, I only took out the read() part.
For example: Serial.print("DHT, \t") instead of Serial.print("DHT read(), \t")
and it works with no errors. That is why I couldn't believe my eyes.
The 4.7kΩ pull up resistor is there between the data line and VCC.
Power is stable, it's 3.28 volts measured with a DMM. It's not a hardware problem because if I only take just read() out of the string literal it has no errors at all.
So then I started running a few experiments to narrow down the problem.
I changed all the read statements in the library to the word obtain() instead. Much to my surprise, nothing changed. Everything still works perfectly unless read() is in the string literal.
Some weird results:
If I change it to lead() it has checksum errors.
If I change it to re() no errors. 0 checksum errors, 0 timeouts. Run for about a minute.
But rea() and the errors begin. Same as before, first reading is good then all checksum errors thereafter.
That is strange and it seems to me like a compiler issue. This is beta after all, to program the Due I am using Arduino IDE 1.5.8 beta.
The code I am using is your example code from github along with your library. The only mod I made is I changed all the read() to obtain() for example read22() to obtain22() throughout all of the library, .cpp and .h but that had no effect anyway. It behaves exactly the same as with read22(). So I changed back to read22() throughout the library. So the library is back to the way it was with no modifications. The only other change in the code is I use pin 12 and not 5 or 6, but that doesn't matter. The code works if it's re() but not rea(). Strange.
Maybe it's an interrupt issue like you said, but then why would rea() cause interrupt problems but re() not cause any problems at all? And inside a string literal? To me it seems to be a bug in the compiler, but I could be wrong.
DHT TEST PROGRAM
LIBRARY VERSION: 0.1.13
Type, status, Humidity (%), Temperature (C) Time (us)
DHT re(), OK, 37.2, 22.5, 4623
DHT re(), OK, 37.5, 22.4, 4295
DHT re(), OK, 37.1, 22.4, 4247
DHT re(), OK, 37.1, 22.4, 4248
DHT re(), OK, 37.0, 22.4, 4248
DHT re(), OK, 37.0, 22.4, 4247
DHT re(), OK, 36.9, 22.4, 4201
DHT re(), OK, 36.9, 22.4, 4201
DHT re(), OK, 36.9, 22.4, 4200
DHT re(), OK, 37.0, 22.5, 4248
DHT re(), OK, 37.0, 22.5, 4248
DHT re(), OK, 37.0, 22.5, 4247
DHT re(), OK, 37.0, 22.5, 4248
DHT re(), OK, 36.9, 22.4, 4200
DHT re(), OK, 37.0, 22.5, 4247
DHT re(), OK, 37.0, 22.5, 4248
DHT re(), OK, 37.0, 22.5, 4247
DHT re(), OK, 37.1, 22.5, 4341
DHT re(), OK, 37.1, 22.5, 4342
DHT re(), OK, 37.0, 22.5, 4248
DHT re(), OK, 37.1, 22.5, 4341
DHT re(), OK, 37.1, 22.5, 4342
DHT re(), OK, 37.2, 22.5, 4295
DHT re(), OK, 37.2, 22.4, 4247
DHT re(), OK, 37.3, 22.5, 4389
DHT re(), OK, 37.4, 22.5, 4295
DHT re(), OK, 37.4, 22.5, 4294
DHT re(), OK, 37.4, 22.5, 4295
DHT re(), OK, 37.4, 22.5, 4295
DHT re(), OK, 37.5, 22.5, 4388
DHT re(), OK, 37.5, 22.5, 4389
DHT re(), OK, 37.6, 22.5, 4295
DHT re(), OK, 37.6, 22.5, 4294
DHT re(), OK, 37.6, 22.5, 4295
DHT re(), OK, 37.5, 22.5, 4389
DHT re(), OK, 37.5, 22.5, 4388
The problem occurs with rea() as a string literal:
DHT TEST PROGRAM
LIBRARY VERSION: 0.1.13
Type, status, Humidity (%), Temperature (C) Time (us)
DHT rea(), OK, 36.9, 22.5, 4539
DHT rea(), Checksum error, 3295.4, 11.2, 4215
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, 11.2, 4123
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, 11.3, 4122
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, 11.3, 4123
DHT rea(), Checksum error, 3295.2, 11.2, 4123
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, -11.2, 4168
DHT rea(), Checksum error, 3295.2, -11.2, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4168
DHT rea(), Checksum error, 3295.2, -11.3, 4169
DHT rea(), Checksum error, 3295.2, -11.3, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4168
DHT rea(), Checksum error, 3295.2, -11.2, 4169
DHT rea(), Checksum error, 3295.2, -11.3, 4169
DHT rea(), Checksum error, 3295.2, -11.2, 4168
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, 11.3, 4123
DHT rea(), Checksum error, 3295.2, 11.3, 4123
DHT rea(), Checksum error, 3295.2, 11.3, 4123
DHT rea(), Checksum error, 3295.2, 11.2, 4123
DHT rea(), Checksum error, 3295.2, 11.2, 4122
DHT rea(), Checksum error, 3295.2, 11.3, 4122
DHT rea(), Checksum error, 3295.1, -11.2, 4215
//
// FILE: dht_read_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: DHT library test sketch for DHTlib read function && Arduino
// URL:
//
// Released to the public domain
//
#include <dht.h>
dht DHT;
#define DHT_PIN 12
void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
}
void loop()
{
// READ DATA
Serial.print("DHT rea(), \t"); // change rea() to re() and no errors!!! Strange.
uint32_t start = micros();
int chk = DHT.read22(DHT_PIN);
uint32_t stop = micros();
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.print(DHT.temperature, 1);
Serial.print(",\t");
Serial.print(stop - start);
Serial.println();
delay(2000);
}
//
// END OF FILE
//
Thank you for your work on this library, it is very much appreciated the hard work you put into this for the community and it has turned out to be very interesting and bizarre behavior. I still think it might be a compiler bug, but I am not sure. I can do any experiments you want I even have an oscilloscope if need be.