BE SMARTER! Make, play and learn with the Tinusaur microcontroller boards.

TinuDHT

TinuDHT is a C library for working with the DHT11 temperature/humidity sensor intended to be used with the Tinusaur but should also work with any other board based on ATtiny85 or similar microcontroller.

There are of course may libraries (sometime called drivers) to work with DHT11 and the more advanced DHT21/DHT22 but they were written primarily for the Arduino environment and do not work well (or at all) with pure ATtiny boards. Here is a list of some of the popular libraries with short descriptions from their authors:

Class for DHTxx sensorshttp://playground.arduino.cc/Main/DHTLib
The DHT11, DHT21 and DHT22 are relative cheap sensors for measuring temperature and humidity. This article describes a library for reading both values from these sensors.

A DHT11 Class for Arduinohttp://playground.arduino.cc/Main/DHT11Lib
The DHT11 is a relatively cheap sensor for measuring temperature and humidity. This article describes a small library for reading both from the sensor. The DHT22 is similar to the DHT11 and has greater accuracy.

Adafruit TinyDHThttps://github.com/adafruit/TinyDHT
This is an Arduino library for the Adafruit Trinket and Gemma mini microcontrollers for the DHT series of low cost temperature/humidity sensors. The library returns integer values to save space on the memory constrained ATTiny85 by not requiring the floating point library.

DHT11

The DHT11 is very basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor for measurements, and sends out the info to the data pin. It is relatively simple to use it, but requires precise timing to retrieve the data correctly. One disadvantage of this sensor is that you can get new data from it no more often than once every 1 or 2 seconds.

Technical parameters of DHT11:

Humidity: 20-90 % RH, ±5％RH

Temperature:0-50 ℃, ±2℃ 1

Power supply: 3.0 – 5.5 V DC

Pinout:

1: Vdd – Power supply.

2: Data – Serial data.

3: N/C – Not connected.

4: GND – Ground.

Sending/Receiving:

The host (MCU, microcontroller) sends short 18ms LOW to the data pin, then waits a little – 20-40 us and then waits for the DHT to start sending data back. The short HIGH’s are “0” and the long HIGH’s are “1”.

DHT11 Timing Diagram

Library

The primary problem with the direct use of the Arduino libraries is that the ATtiny85 and Tinusaur in particular do not have enough resource to handle the send/receive process properly, i.e. not enough CPU power, in result of which the timing of the signals that are sent to the sensor and received from it become messed up. In addition those libraries use Arduino specific code and/or C++ specific syntax which makes them incompatible with the plain C language.

This library is based on DHT11Lib code. It was adapted for ATtiny, removed Arduino dependencies and timing was adjusted to work well on ATtiny85 at 1 MHz. There are few other changes and optimizations for speed and size.

TinuDHT is written in plain C and does not require any additional libraries to function except those that come with the WinAVR SDK.

Share this:

Like this:

3 thoughts on “TinuDHT”

Hi!
First, congratulations for your project!
I was trying to upload your code to my Attiny85, within the Arduino 1.7.6, and it gave me the following error while compiling:
“tinudht.c:64:2: note: use option -std=c99 or -std=gnu99 to compile your code”

Ah, okay. This is because we use some C language constructions that are relatively new.

The C/C++ compiler that comes with the Arduino 1.7 dev environment should be capable of doing this – you only need to specify the options mentioned above. Unfortunately, I don’t know at the moment where’s that done – somewhere in system settings maybe.