Tag Archives: software

Data Logger Simple – Software Bugfix

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.

Continue reading Data Logger Simple – Software Bugfix