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:

When doing the manual evaluation you get:
                      Combined Decimal Value  
Humidity High 0 0 1 1   1 1 1 1   0x3f 63 Humidity = 63%
Humidity Low 0 0 0 0   0 0 0 0   0x00    
Temperature 0 0 0 1   0 1 1 1   0x17 23 Temperature = 23.4\xB0C
Temperature Decimal 0 0 0 0   0 1 0 0   0x04 4  
Checksum 0 1 0 1   1 0 1 0   0x5a    

Adding the first 4 hex numbers should result in the same value as the checksum:

dht11Checksum.png

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:

dht11Eval.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.

-- %USERSIG{UliRaich - 2020-05-14}%

Comments

 

I Attachment Action Size Date Who Comment
dht11.py.txttxt dht11.py.txt manage 739 bytes 14 May 2020 - 12:56 UnknownUser  
dht11Checksum.pngpng dht11Checksum.png manage 4 K 30 May 2020 - 14:31 UnknownUser  
dht11Eval.pngpng dht11Eval.png manage 19 K 30 May 2020 - 14:28 UnknownUser  
dht11Eval.py.txttxt dht11Eval.py.txt manage 1 K 30 May 2020 - 14:28 UnknownUser  
dht11Plot.py.txttxt dht11Plot.py.txt manage 1 K 14 May 2020 - 13:51 UnknownUser  
dht11RawRead.py.txttxt dht11RawRead.py.txt manage 814 bytes 14 May 2020 - 13:42 UnknownUser  
dht11Result.pngpng dht11Result.png manage 18 K 14 May 2020 - 13:26 UnknownUser  
dht11Unpack.py.txttxt dht11Unpack.py.txt manage 1 K 14 May 2020 - 13:53 UnknownUser  
This topic: IoT_Course_English > WebHome > Solutions > SolutionsToTheDHT11TemperatureAndHumiditySensor
Topic revision: 30 May 2020, UliRaich