adafruit / DHT-sensor-library

Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
https://learn.adafruit.com/dht
MIT License
1.99k stars 1.42k forks source link

Program hangs up when using > 1 dynamic objects of this library with FreeRTOS #129

Closed PRO2XY closed 1 year ago

PRO2XY commented 5 years ago

Code execution stalls when trying to initialize more than one DHT object dynamically.

    std::vector<DHT> am2301;
    for (uint8_t i = 0; i < 8; i++) {
        am2301.emplace_back(SENSORS[i], DHT_TYPE);
        am2301[i].begin();
    }

If the for loop is run just once, the code runs as it should, but on a second iteration, the code stalls at the am2301.emplace_back(...) line. The result is the same when using any other way to declare iterable objects, for example:

    DHT **am2301;
    am2301 = new DHT* [8];
    uint8_t i;
    for (i=0; i<8; i++){
      am2301[i] = new DHT(SENSORS[i], DHT_TYPE);
      am2301[i]->begin();
    }

in which case it stalls at am2301[i] = new DHT(SENSORS[i], DHT_TYPE); on the second iteration.

Anhunghezo commented 3 years ago

I have the same problem with DHT11 and FreeRTOS. It crashs my tasks and suspend all program.

caternuson commented 1 year ago

This is an Arduino library meant to be used with the Arduino IDE.