After analysing recorded data from the simple version of the data logger, I found a problem I had to fix with a new release v1.1 of the software.

If you look at this chart, which is showing data recorded in 30 second intervals, you can clearly see the values do not really change every 30 seconds.

Data Logger Problem Chart

The values change every 40 minutes and this can not be correct, even the sensor is slow. I found the problem in the DHT library from Adafruit. It is not actually a problem, but the library relies on the function millis() to measure the time between two reads.

From the DHT sensor library:

boolean DHT::read(void) {
  // Check if sensor was read less than two seconds ago and return early
  // to use last reading.
  uint32_t currenttime = millis();
  if (currenttime < _lastreadtime) {
    // ie there was a rollover
    _lastreadtime = 0;
  }
  if (!_firstreading && ((currenttime - _lastreadtime) < 2000)) {
    return _lastresult; // return last correct measurement
  }
  _firstreading = false;
  _lastreadtime = millis();

The function millis() relies on timer1 which is counting the time for this function. To save power, I put the microcontroller into sleep mode, which stops all timers except timer2. Therefore the time is not counted anymore, and millis() returns a wrong value.

I could just make a copy of the library and remove this part, but instead I created a own implementation which is simpler.

My own implementation has some limitations:

  • It only works with the DHT22 chip.
  • It requires a microprocessor with 16MHz or faster.
  • It only supports celsius as returned from the DHT22 chip.
  • It requires the AVR library.

Download the new version 1.1 of the data logger software here:

https://github.com/LuckyResistor/DataLoggerSimple/releases/tag/v1.1