Tags:
create new tag
view all tags

Solutions to exercise 6: The DHT-11 temperature and humidity sensor

Exercise 6.0 Using the library

This is of course the easiest way to access the DHT11 because all the difficult (and interesting) parts are hidden in the library. Nevertheless I give you an example of how to use the library here. The program reads out the DHT11 and prints the results as a sequence of zeros and ones to standard out. You can of course easily redirect this output to a file for further evaluation.

There are different ways to find the shared library on the system. You may extent the LD_LIBRARY_PATH environment variable with the directory in which your shared library is located (see run.sh) or you can put the library into a library that is part of the system library search path.

https://afnog.iotworkshop.africa/pub/UCC_Course_2018/Exercise6Solutions/dht11Lib.tar.gz

Exercise 6.2: Data taking

You may have a look into the implementation of the library, which you can find in the tar archive above. The function dht11Measurement does this.

Exercise 6.2 Manual Analysis

Here is a screen dump from a gnuplot image showing the DHT11 data:

protocol.png

The first long pulse is still due to the start sequence. Then the data are:

0001 0010 = 0x12 = 18 humidity
0000 0000

0001 0101 = 0x15 = 21 temperature
0000 0000

0010 0111 = 0x27 = 0x12 + 0x15 checksum

This clearly shows that the measurement has not been made in Ghana!

Exercise 6.3: Analysis done by program

This is actually quite tricky and I am pretty sure you have not come this far during the exercise session. If you want to know how it is done, have a look at the library. The function dht11Evalute does this analysis. It uses a function readBit which take a pointer into the protocol data. It then finds out if the next bit is a zero or a one and advances the pointer to the next bit. Since the pointer is updated we have to pass a pointer to a pointer (int **data) to the routine.

-- Uli Raich - 2018-11-07

Comments

Topic attachments
I Attachment History ActionSorted ascending Size Date Who Comment
Unknown file formatgz dht11Lib.tar.gz r1 manage 4.7 K 2018-11-20 - 16:05 UliRaich  
PNGpng protocol.png r1 manage 45.8 K 2018-11-20 - 15:44 UliRaich  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2018-11-20 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback