Skip to content

Commit

Permalink
add : add comments and description for DHT10
Browse files Browse the repository at this point in the history
  • Loading branch information
downeyboy committed Aug 15, 2019
1 parent e7714c7 commit 1e7601a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
31 changes: 26 additions & 5 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ void DHT::begin(void) {

}


/**Common interface to get temp&humi value.support all DHT device.
*
* @return 0 for calibrated failed,1 for succeed.
**/
int DHT::readTempAndHumidity(float *data)
{
uint32_t target_val[2] = {0};
Expand Down Expand Up @@ -218,7 +221,9 @@ boolean DHT::read(void) {
/*****************************************************************************/
/*****************************************************************************/


/**Reset sensor.
* @return 0 for calibrated failed,1 for succeed.
**/
int DHT::DHT10Reset(void)
{
if(_type == DHT10)
Expand All @@ -230,6 +235,11 @@ int DHT::DHT10Reset(void)

}

/** Read status register.check the calibration flag - bit[3]: 1- calibrated ok ,0 - Not calibrated.
*
* @return 0 for calibrated failed,1 for succeed.
*
**/
int DHT::DHT10ReadStatus(void)
{

Expand All @@ -245,12 +255,15 @@ int DHT::DHT10ReadStatus(void)
return 0;
}
else{
return 0;
SERIAL.println("This function only support for DHT10");
SERIAL.println("This function only support for DHT10");
return 0;
}

}

/** Init sensor,send 0x08,0x00 to register 0xe1.
* @ return : 0 if success, non-zero if failed.
**/
int DHT::setSystemCfg(void)
{
uint8_t cfg_param[] = {0xe1,0x08,0x00};
Expand All @@ -263,6 +276,10 @@ int DHT::setSystemCfg(void)
}


/** Read temp & humi result buf from sensor.
* total 6 bytes,the first byte for status register,other 5 bytes for temp & humidity data.
* @ return : 0 if success, non-zero if failed.
**/
int DHT::readTargetData(uint32_t *data)
{
uint8_t statu = 0;
Expand All @@ -277,6 +294,7 @@ int DHT::readTargetData(uint32_t *data)
}

delay(75);
// check device busy flag, bit[7]:1 for busy, 0 for idle.
while(statu & 0x80 == 0x80){
SERIAL.println("Device busy!");
delay(200);
Expand Down Expand Up @@ -308,7 +326,10 @@ int DHT::readTargetData(uint32_t *data)
}
}


/**DHT10 Init function.
* Reset sensor and wait for calibration complete.
* @ return : 0 if success, non-zero if failed.
**/
int DHT::DHT10Init(void)
{
int ret = 0;
Expand Down
27 changes: 27 additions & 0 deletions DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class DHT {
float convertCtoF(float);
float readHumidity(void);

/**Common interface to get temp&humi value.support all DHT device.
*
* @return 0 for calibrated failed,1 for succeed.
**/
int readTempAndHumidity(float *data);

// DHT10 digital interfaces(i2c),onlu for DHT10 .
Expand All @@ -80,10 +84,33 @@ class DHT {
int i2cWriteBytes(uint8_t *bytes,uint32_t len);
int i2cWriteByte(uint8_t byte);


/**Reset sensor.
* @return 0 for calibrated failed,1 for succeed.
**/
int DHT10Reset(void);

/** Read status register.check the calibration flag - bit[3]: 1- calibrated ok ,0 - Not calibrated.
*
* @return 0 for calibrated failed,1 for succeed.
*
**/
int DHT10ReadStatus(void);
/** Init sensor,send 0x08,0x00 to register 0xe1.
* @ return : 0 if success, non-zero if failed.
**/
int setSystemCfg(void);

/** Read temp & humi result buf from sensor.
* total 6 bytes,the first byte for status register,other 5 bytes for temp & humidity data.
* @ return : 0 if success, non-zero if failed.
**/
int readTargetData(uint32_t *data);

/**DHT10 Init function.
* Reset sensor and wait for calibration complete.
* @ return : 0 if success, non-zero if failed.
**/
int DHT10Init(void);


Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This temperature & humidity sensor provides a pre-calibrated digital output. A u

For more information please visit [wiki DHT11](http://wiki.seeedstudio.com/Grove-TemperatureAndHumidity_Sensor/) and [wiki AM2302](http://wiki.seeedstudio.com/Grove-Temperature_and_Humidity_Sensor_Pro/)

****

Add support for DHT10 , The different from other DHT* device is that it uses i2c interface.

----

This demo is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check LINCESE for more information.<br>
Expand Down
2 changes: 1 addition & 1 deletion examples/DHTtester/DHTtester.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

/*Notice: The DHT10 is different from other DHT* sensor ,it use i2c interface rather than one wire*/
/*Notice: The DHT10 is different from other DHT* sensor ,it uses i2c interface rather than one wire*/
/*So it doesn't require a pin.*/

//#define DHTTYPE DHT10
Expand Down
8 changes: 8 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#######################################
# Datatypes (KEYWORD1)
DHT KEYWORD1
#######################################


Expand All @@ -18,6 +19,13 @@ readTemperature KEYWORD2
convertCtoF KEYWORD2
readHumidity KEYWORD2

readTempAndHumidity KEYWORD2
DHT10Reset KEYWORD2
DHT10ReadStatus KEYWORD2
setSystemCfg KEYWORD2
readTargetData KEYWORD2
DHT10Init KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

0 comments on commit 1e7601a

Please sign in to comment.