Solutions to exercise 4: The DHT11 Temperature and Humidity Sensor

Exercise 1:

The solution to the exercise is quasi already given in the MicroPython manual. All you need to do is replacing the Pin (4 in the manual) by the pin used with our hardware: pin 16. Here is the solution:

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheDHT11TemperatureAndHumiditySensor/dht11.py.txt

It takes a new measurement every 2 s and prints the result.

Exercise 2:

The manual evaluation you must do yourself, the program for automatic data extraction is here:

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheDHT11TemperatureAndHumiditySensor/dht11Eval.py.txt

and here a screen dump when running it on the data taken:

dht11Result.png

Exercise 3:

The exercise sheet pretty much explains how to proceed. Therefore I just supply the solution for your study. There are 2 different ways on how to convert the binary values in the 32*32 bit array to strings such that you can write them to the file. In the solution I use the newer method while the old style is given in the comments.

Here is the solution that starts a measurement, reads out the raw data and write them to a file named "/data/dht11.txt". If the "/data" directory does not yet exist on the ESP32 it is created.

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheDHT11TemperatureAndHumiditySensor/dht11RawRead.py.txt

Exercise 4:

In the script

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheDHT11TemperatureAndHumiditySensor/dht11Unpack.py.txt

the file dth11.txt is opened and unpacked. The sequence if bits is written to the file "dht11Unpacked.txt". This file can be easily plotted with gnuplot:

gnuplot
plot [0:900][0:1.5] "dht11Unpacked.txt" with lines

The script

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToTheDHT11TemperatureAndHumiditySensor/dht11Plot.py.txt

does unpacking and plotting in a single script. It uses matplotlib to produce the plot.

-- Uli Raich - 2020-05-14

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
Texttxt dht11.py.txt r1 manage 0.7 K 2020-05-14 - 12:56 UliRaich  
Texttxt dht11Eval.py.txt r2 r1 manage 1.9 K 2020-05-14 - 13:54 UliRaich  
Texttxt dht11Plot.py.txt r2 r1 manage 1.1 K 2020-05-14 - 13:51 UliRaich  
Texttxt dht11RawRead.py.txt r1 manage 0.8 K 2020-05-14 - 13:42 UliRaich  
PNGpng dht11Result.png r1 manage 18.5 K 2020-05-14 - 13:26 UliRaich  
Texttxt dht11Unpack.py.txt r2 r1 manage 1.1 K 2020-05-14 - 13:53 UliRaich  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2020-05-14 - UliRaich
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback