@@ -13,12 +13,17 @@ Arduino library for I2C DHT20 temperature and humidity sensor.
1313
1414## Description
1515
16+ The DHT20 is a humidity an temperature sensor.
17+
18+ The sensor has a fixed address of ** 0x38** .
19+ It is not known if the address can be changed.
20+
1621The library must be initiated by calling the ** begin()** function,
1722or ** begin(dataPin, clockPin)** for ** ESP32** and similar platforms.
1823
1924Thereafter one has to call the ** read()** function to do the actual reading,
20- and with ** getTemperature()** and ** getHumidity()** to get the measured values.
21- Calling these latter again will return the same values until a new ** read()** is called .
25+ and call ** getTemperature()** and ** getHumidity()** to get the measured values.
26+ Calling these latter again will return the same values until a new ** read()** is done .
2227
2328The ** read()** call of this sensor is blocking for 80+ milliseconds (datasheet 7.4)
2429so the library also has a asynchronous interface. See below.
@@ -27,9 +32,30 @@ Since 0.1.3 and 0.1.4 the performance of **read()** has been optimized,
2732still blocking but less long for about 45 milliseconds.
2833
2934
35+ ### 0.2.0
36+
37+ In #8 a bug is described that the sensor "freezes".
38+ Cause is not well understood.
39+
40+ Two solutions / workarounds are found:
41+ - call ** resetSensor()** before EVERY ** read()** .
42+ This is the preferred solution.
43+ - use ** Wire.setClock(200000)** 100 K and lower speeds freezes the sensor.
44+ With clock set to 200 K and above the sensor seems to work for longer periods.
45+ Tested several speeds on UNO, no pull ups, < 10 cm wire.
46+
47+ Note: setting the I2C clock possibly interferes with other devices on the I2C bus,
48+ so it is not a solution in the end.
49+
50+ The 0.2.0 version embeds the ** resetSensor()** into ** requestData()** to
51+ reset the sensor if needed in both synchronous and asynchronous calls.
52+ This keeps the API simple. The reads are 1-2 ms slower than 0.1.4. (< 50 ms).
53+ Still far below the 80 ms mentioned in the datasheet.
54+
55+
3056### Connection
3157
32- Always check datasheet
58+ Always check datasheet!
3359
3460Front view
3561```
@@ -43,7 +69,7 @@ Front view
4369
4470### Tested
4571
46- Verified to work with Arduino UNO and ESP32.
72+ Verified to work with Arduino UNO and ESP32 and ESP8266 (see # 8 )
4773Please let me know if other platforms work (or not).
4874
4975
@@ -61,29 +87,32 @@ Please let me know if other platforms work (or not).
6187### Core
6288
6389- ** int8_t read()** read the sensor and store the values internally.
64- It returns the status of the read which should be 0.
90+ Returns the status of the read which should be 0 == ** DHT20_OK ** .
6591- ** float getHumidity()** returns last Humidity read.
92+ Multiple calls will return same value until a new ** read()** is made.
6693- ** float getTemperature()** returns last Temperature read.
94+ Multiple calls will return same value until a new ** read()** is made.
6795
6896
6997### Offset
7098
71- - ** void setHumOffset(float offset)** set an offset to calibrate (1st order) the sensor .
72- - ** float getHumOffset()** return current offset, default 0.
73- - ** void setTempOffset(float offset)** set an offset to calibrate (1st order) the sensor .
74- - ** float getTempOffset()** return current offset, default 0.
99+ - ** void setHumOffset(float offset)** set an offset to calibrate the sensor (1st order).
100+ - ** float getHumOffset()** return current humidity offset, default 0.
101+ - ** void setTempOffset(float offset)** set an offset to calibrate the sensor (1st order).
102+ - ** float getTempOffset()** return current temperature offset, default 0.
75103
76104
77105### Asynchronous interface
78106
79- There are two timings that need to be considdered,
80- - time between requests = 1000 ms
81- - time between request and data ready = 80 ms
107+ There are two timings that need to be considered (from datasheet):
108+ - time between requests = 1000 ms.
109+ - time between request and data ready = 80 ms.
82110
83111The async interface allows one to continue processing after a ** requestData()** has been made.
84- Note that there should be at least ** 1000 milliseconds** between subsequent requests.
112+ Note there should be at least ** 1000 milliseconds** between subsequent requests.
85113
86114With ** bool isMeasuring()** one can check if a new measurement is ready.
115+ Alternative is to delay for up to 80 ms.
87116If so the sensor can be read with ** readData()** .
88117
89118To interpret the read bits to temperature, humidity and status one needs to call ** convert()** as last step.
@@ -116,14 +145,17 @@ This function blocks a few milliseconds to optimize communication.
116145
117146#### Experimental 0.1.4 resetSensor
118147
119- Use with care, as this is not tested.
148+ Use with care!
120149
121150- ** uint8_t resetSensor()** if at startup the sensor does not return a status of 0x18,
122151three registers 0x1B, 0x1C and 0x1E need to be reset.
123152See datasheet 7.4 Sensor Reading Process, point 1.
124153There is no documentation about the meaning of these registers.
125154The code is based upon example code for the AHT20 (from manufacturer).
126155
156+ The call is needed to get the ** read()** working well so it has been embedded into
157+ the read calls. (0.2.0)
158+
127159
128160### Timing
129161
@@ -152,20 +184,20 @@ See examples
152184## Future
153185
154186#### must
155-
187+ - improve documentation.
188+ - investigate the bug from #8 further
156189
157190#### should
158191
159192
160193#### could
161-
162194- improve unit tests.
163195- investigate
164196 - sensor calibration (website aosong?)
165197- investigate optimizing timing in readStatus()
166198 - delay(1) ==> microSeconds(???).
167- - separate changelog.md
168199- connected flag?
200+ - add ** uint8_t getAddress()** to return the address (convenience).
169201
170202#### won't
171203
0 commit comments