I’ve got a quite weird behavior of DHT library.
I’ve got DHT22 sensor. If it’s signal cable is not connected, reading the sensor causes a problem: Arduino reboots or hangs in unpredictable places.
If I connect the signal cable again, the problem vanishes.
Is this normal behavior or some sort of bug? I think unsuccessful reading affects some part of Memory.
PS. The project is quite big and I can’t share the code here.
It happens that I found an evidence that dht object influences foreign memory. Look at this code:
DV("pClock->isInited 3", pClock->isInited); // prints 1
dht1.readHumidity();
DV("pClock->isInited 4", pClock->isInited); // print 0 !!!!
// nothing more can be called between these lines.
// DV is a macro which prints label and value.
// Both objects created before this.
DHT dht1(11, DHT22);
...
dht1.begin();
...
pClock = new ZhClock(); // uses RTC_DS1307
pClock->init(&rtc); // rtc is RTC_DS1307
1 Answer 1
This problem is usual if you are in shortage of RAM. Adafruit's libraries wastes lots of memory. You should be very careful to run their stuff if you are in shortage of memory.
I suggest you to try another library which quite old, but uses much lesser memory to read DHT sensor’s data: https://github.com/markruys/arduino-DHT
-
Yep! That's solved my problem!zhekaus– zhekaus2020年02月27日 18:47:56 +00:00Commented Feb 27, 2020 at 18:47
uint32_t cycles[80];
says quite something to you ;-).