first commit
This commit is contained in:
commit
e6a42e28e9
4355 changed files with 4626605 additions and 0 deletions
119
libraries/DFRobot_DHT20/DFRobot_DHT20.cpp
Normal file
119
libraries/DFRobot_DHT20/DFRobot_DHT20.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*!
|
||||
*@file DFRobot_DHT20.cpp
|
||||
*@brief Define the basic structure of class DFRobot_DHT20, the implementation of the basic methods
|
||||
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
|
||||
*@licence The MIT License (MIT)
|
||||
*@author [fengli](li.feng@dfrobot.com)
|
||||
*@version V1.0
|
||||
*@date 2021-6-24
|
||||
*@get from https://www.dfrobot.com
|
||||
*@https://github.com/DFRobot/DFRobot_DHT20
|
||||
*/
|
||||
|
||||
#include <DFRobot_DHT20.h>
|
||||
|
||||
|
||||
DFRobot_DHT20::DFRobot_DHT20(TwoWire * pWire,uint8_t address)
|
||||
: _pWire(pWire) {
|
||||
_address = address;
|
||||
}
|
||||
|
||||
int DFRobot_DHT20::begin() {
|
||||
uint8_t readCMD[3]={0x71};
|
||||
uint8_t data;
|
||||
delay(100);
|
||||
_pWire->begin();
|
||||
//check if the IIC communication works
|
||||
writeCommand(readCMD,1);
|
||||
|
||||
readData(&data, 1);
|
||||
//Serial.println(data);
|
||||
if((data | 0x8) == 0){
|
||||
return 1;
|
||||
}
|
||||
if(data == 255) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
float DFRobot_DHT20::getTemperature() {
|
||||
uint8_t readCMD[3]={0xac,0x33,0x00};
|
||||
uint8_t data[6] = {0};
|
||||
int retries = 10;
|
||||
float temperature;
|
||||
// when the returned data is wrong, request to get data again until the data is correct.
|
||||
writeCommand(readCMD, 3);
|
||||
while(retries--) {
|
||||
delay(10);
|
||||
readData(data,6);
|
||||
if((data[0] >> 7) == 0){
|
||||
DBG("bus not busy");
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint32_t temp = data[3] & 0xff;
|
||||
uint32_t temp1 = data[4] & 0xff;
|
||||
uint32_t rawData = 0;
|
||||
rawData = ((temp&0xf)<<16)+(temp1<<8)+(data[5]);
|
||||
DBG(rawData);
|
||||
DBG((temp&0xf)<<16);
|
||||
temperature = (float)rawData/5242 -50;
|
||||
DBG(temperature)
|
||||
return temperature;
|
||||
}
|
||||
|
||||
float DFRobot_DHT20::getHumidity() {
|
||||
uint8_t readCMD[3]={0xac,0x33,0x00};
|
||||
uint8_t data[6] = {0};
|
||||
int retries = 10;
|
||||
float humidity;
|
||||
// when the returned data is wrong, request to get data again until the data is correct.
|
||||
writeCommand(readCMD, 3);
|
||||
while(retries--) {
|
||||
delay(10);
|
||||
readData(data,6);
|
||||
if((data[0] >> 7) == 0){
|
||||
DBG("bus not busy");
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint32_t temp = data[1] & 0xff;
|
||||
uint32_t temp1 = data[2] & 0xff;
|
||||
uint32_t rawData = 0;
|
||||
rawData = (temp<<12)+(temp1<<4)+((data[3]&0xf0)>>4);
|
||||
DBG(rawData);
|
||||
DBG(temp<<12);
|
||||
humidity = (float)rawData/0x100000;
|
||||
DBG(humidity)
|
||||
return humidity;
|
||||
}
|
||||
void DFRobot_DHT20::writeCommand(const void *pBuf, size_t size) {
|
||||
if (pBuf == NULL) {
|
||||
DBG("pBuf ERROR!! : null pointer");
|
||||
}
|
||||
|
||||
uint8_t * _pBuf = (uint8_t *)pBuf;
|
||||
_pWire->beginTransmission(_address);
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
|
||||
_pWire->write(_pBuf[i]);
|
||||
|
||||
}
|
||||
_pWire->endTransmission();
|
||||
}
|
||||
|
||||
uint8_t DFRobot_DHT20::readData(void *pBuf, size_t size) {
|
||||
delay(10);
|
||||
if (pBuf == NULL) {
|
||||
DBG("pBuf ERROR!! : null pointer");
|
||||
}
|
||||
uint8_t * _pBuf = (uint8_t *)pBuf;
|
||||
//read the data returned by the chip
|
||||
_pWire->requestFrom(_address, size);
|
||||
uint8_t i = 0;
|
||||
for (uint8_t i = 0 ; i < size; i++) {
|
||||
_pBuf[i] = _pWire->read();
|
||||
DBG(_pBuf[i]);
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
77
libraries/DFRobot_DHT20/DFRobot_DHT20.h
Normal file
77
libraries/DFRobot_DHT20/DFRobot_DHT20.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*!
|
||||
*@file DFRobot_DHT20.cpp
|
||||
*@brief Define the basic structure of class DFRobot_DHT20, the implementation of basic methods.
|
||||
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
|
||||
*@licence The MIT License (MIT)
|
||||
*@author [fengli](li.feng@dfrobot.com)
|
||||
*@version V1.0
|
||||
*@date 2021-6-24
|
||||
*@get from https://www.dfrobot.com
|
||||
*@https://github.com/DFRobot/DFRobot_DHT20
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DFRobot_DHT20_H
|
||||
#define DFRobot_DHT20_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <string.h>
|
||||
#include <Wire.h>
|
||||
//#define ENABLE_DBG
|
||||
|
||||
#ifdef ENABLE_DBG
|
||||
#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);}
|
||||
#else
|
||||
#define DBG(...)
|
||||
#endif
|
||||
//extern Stream *dbg;
|
||||
class DFRobot_DHT20
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Construct the function
|
||||
* @param pWire IC bus pointer object and construction device, can both pass or not pass parameters, Wire in default.
|
||||
* @param address Chip IIC address, 0x38 in default.
|
||||
*/
|
||||
DFRobot_DHT20(TwoWire *pWire = &Wire, uint8_t address = 0x38);
|
||||
|
||||
/**
|
||||
* @brief init function
|
||||
* @return Return 0 if initialization succeeds, otherwise return non-zero and error code.
|
||||
*/
|
||||
int begin(void);
|
||||
|
||||
/**
|
||||
* @brief Get ambient temperature, unit: °C
|
||||
* @return ambient temperature, measurement range: -40°C ~ 80°C
|
||||
*/
|
||||
float getTemperature();
|
||||
|
||||
/**
|
||||
* @brief Get relative humidity, unit: %RH.
|
||||
* @return relative humidity, measurement range: 0-100%
|
||||
*/
|
||||
float getHumidity();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Write command into sensor chip
|
||||
* @param pBuf Data included in command
|
||||
* @param size The number of the byte of command
|
||||
*/
|
||||
void writeCommand(const void *pBuf,size_t size);
|
||||
/**
|
||||
* @brief Write command into sensor chip
|
||||
* @param pBuf Data included in command
|
||||
* @param size The number of the byte of command
|
||||
* @return Return 0 if the reading is done, otherwise return non-zero.
|
||||
*/
|
||||
uint8_t readData(void *pBuf,size_t size);
|
||||
|
||||
TwoWire *_pWire;
|
||||
uint8_t _address;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
21
libraries/DFRobot_DHT20/LICENSE
Normal file
21
libraries/DFRobot_DHT20/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 DFRobot
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
82
libraries/DFRobot_DHT20/README.md
Normal file
82
libraries/DFRobot_DHT20/README.md
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# DFRobot_DHT20
|
||||
|
||||
The DHT20 temperature & humidity sensor is the newly upgraded version of the DHT11. The DHT20 features a brand-new ASIC dedicated chip, an improved MEMS semiconductor capacitive humidity sensor element and a standard on-chip temperature element. All sensors are factory calibrated and characterized by low power, high precision & stability, fast response, and strong anti-interference. Moreover, the DHT20 performance parameters of accuracy, power supply voltage, measurement range and response time have been enhanced greatly over the previous generation,making it more cost-effective. Besides that, the DHT20 temperature & humidity sensor employs I2C digital output protocol, which is very suitable for HVAC,automobiles, data loggers, weather stations, home appliances, and other related temperature and humidity detection and controlled areas. <br>
|
||||
|
||||
<img src="https://dfimg.dfrobot.com/nobody/wiki/73694035631036647cd8872b1d083f6c.png" width="450" hegiht="" align=right/>
|
||||
|
||||
|
||||
## [Product Link](https://www.dfrobot.com/product-2391.html)
|
||||
SKU:SEN0497
|
||||
## Table of Contents
|
||||
|
||||
* [Summary](#summary)
|
||||
* [Installation](#installation)
|
||||
* [Methods](#methods)
|
||||
* [Compatibility](#compatibility)
|
||||
* [History](#history)
|
||||
* [Credits](#credits)
|
||||
|
||||
## Summary
|
||||
|
||||
|
||||
Provide an Arduino library to get Humidity and Temperature by reading data from dht20.
|
||||
|
||||
## Installation
|
||||
|
||||
To use this library, first download the library file, paste it into the \Arduino\libraries directory, then open the examples folder and run the demo in the folder.
|
||||
|
||||
## Methods
|
||||
```C++
|
||||
|
||||
/*!
|
||||
* @brief Construct the function
|
||||
* @param pWire IC bus pointer object and construction device, can both pass or not pass parameters, Wire in default.
|
||||
* @param address Chip IIC address, 0x38 in default.
|
||||
*/
|
||||
DFRobot_DHT20(TwoWire *pWire = &Wire, uint8_t address = 0x38);
|
||||
|
||||
/**
|
||||
* @brief init function
|
||||
* @return Return 0 if initialization succeeds, otherwise return non-zero and error code.
|
||||
*/
|
||||
int begin(void);
|
||||
|
||||
/**
|
||||
* @brief Get ambient temperature, unit: °C
|
||||
* @return ambient temperature, the measurement range is (-40°C ~ 80°C)
|
||||
*/
|
||||
float getTemperature();
|
||||
|
||||
/**
|
||||
* @brief Get relative humidity, unit: %RH.
|
||||
* @return Relative humidity, the measurement range is (1-100%)
|
||||
*/
|
||||
float getHumidity();
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
MCU | Work Well | Work Wrong | Untested | Remarks
|
||||
------------------ | :----------: | :----------: | :---------: | -----
|
||||
Arduino Uno | √ | | |
|
||||
Mega2560 | √ | | |
|
||||
Leonardo | √ | | |
|
||||
ESP32 | √ | | |
|
||||
ESP8266 | √ | | |
|
||||
M0 | √ | | |
|
||||
Micro:bit | √ | | |
|
||||
|
||||
## History
|
||||
|
||||
- Date 2021-6-25
|
||||
- Version V1.0.0
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
Written by fengli(li.feng@dfrobot.com), 2021.7.31 (Welcome to our [website](https://www.dfrobot.com/))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
83
libraries/DFRobot_DHT20/README_CN.md
Normal file
83
libraries/DFRobot_DHT20/README_CN.md
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# DFRobot_DHT20
|
||||
|
||||
DHT20 配有一个全新设计的 ASIC专用芯片、一个经过改进的MEMS半导体电容式湿度传感元件 <br>
|
||||
和一个标准的片上温度传感元件,其性能已经大大提升甚至超出了前一代传感器的可靠性水平 <br>
|
||||
新一代温湿度传感器,经过改进使其在恶劣环境下的性能更稳定。每一个传感器都经过严格的 <br>
|
||||
校准和测试。由于对传感器做了改良和微型化改进,因此它的性价比更高。<br>
|
||||
|
||||
<img src="https://dfimg.dfrobot.com/nobody/wiki/73694035631036647cd8872b1d083f6c.png" width="450" hegiht="" align=right/>
|
||||
|
||||
## [产品链接](https://www.dfrobot.com.cn/goods-3282.html)
|
||||
SKU:SEN0497
|
||||
## 目录
|
||||
|
||||
* [概述](#概述)
|
||||
* [库安装](#库安装)
|
||||
* [方法](#方法)
|
||||
* [兼容性](#兼容性)
|
||||
* [历史](#历史)
|
||||
* [创作者](#创作者)
|
||||
|
||||
## 概述
|
||||
|
||||
|
||||
提供一个Arduino库,通过从dht20读取数据来获取湿度和温度。
|
||||
|
||||
## 库安装
|
||||
|
||||
使用此库前,请首先下载库文件,将其粘贴到\Arduino\libraries目录中,然后打开examples文件夹并在该文件夹中运行演示。
|
||||
|
||||
## 方法
|
||||
|
||||
```C++
|
||||
|
||||
/*!
|
||||
* @brief 构造函数
|
||||
* @param IIC对象的指针,可以传参或不传默认为Wire
|
||||
* @param 产品的IIC地址,默认为0x38
|
||||
*/
|
||||
DFRobot_DHT20(TwoWire *pWire = &Wire, uint8_t address = 0x38);
|
||||
|
||||
/**
|
||||
* @brief 初始化函数
|
||||
* @return 初始化成功返回0,否则返回非零的错误码
|
||||
*/
|
||||
int begin(void);
|
||||
|
||||
/**
|
||||
* @brief 获取环境温度,单位为摄氏度(°C)
|
||||
* @return 环境温度,量程为(-40°C ~ 80°C)
|
||||
*/
|
||||
float getTemperature();
|
||||
|
||||
/**
|
||||
* @brief 获取相对湿度,单位为%RH.
|
||||
* @return 相对湿度, 量程为(1-100%)
|
||||
*/
|
||||
float getHumidity();
|
||||
```
|
||||
|
||||
## 兼容性
|
||||
|
||||
主板 | 通过 | 未通过 | 未测试 | 备注
|
||||
------------------ | :----------: | :----------: | :---------: | -----
|
||||
Arduino Uno | √ | | |
|
||||
Mega2560 | √ | | |
|
||||
Leonardo | √ | | |
|
||||
ESP32 | √ | | |
|
||||
ESP8266 | √ | | |
|
||||
M0 | √ | | |
|
||||
|
||||
## 历史
|
||||
|
||||
- 日期 2021-6-25
|
||||
- 版本 V1.0.0
|
||||
|
||||
## 创作者
|
||||
|
||||
Written by fengli(li.feng@dfrobot.com), 2021.7.31 (Welcome to our [website](https://www.dfrobot.com/))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
libraries/DFRobot_DHT20/examples/getData/getData.ino
Normal file
38
libraries/DFRobot_DHT20/examples/getData/getData.ino
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*!
|
||||
*@file getData.ino
|
||||
*@brief Read ambient temperature and relative humidity and print them to serial port.
|
||||
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
|
||||
*@licence The MIT License (MIT)
|
||||
*@author [fengli](li.feng@dfrobot.com)
|
||||
*@version V1.0
|
||||
*@date 2021-6-24
|
||||
*@get from https://www.dfrobot.com
|
||||
*@https://github.com/DFRobot/DFRobot_DHT20
|
||||
*/
|
||||
|
||||
#include <DFRobot_DHT20.h>
|
||||
/*!
|
||||
* @brief Construct the function
|
||||
* @param pWire IC bus pointer object and construction device, can both pass or not pass parameters, Wire in default.
|
||||
* @param address Chip IIC address, 0x38 in default.
|
||||
*/
|
||||
DFRobot_DHT20 dht20;
|
||||
void setup(){
|
||||
|
||||
Serial.begin(115200);
|
||||
//Initialize sensor
|
||||
while(dht20.begin()){
|
||||
Serial.println("Initialize sensor failed");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//Get ambient temperature
|
||||
Serial.print("temperature:"); Serial.print(dht20.getTemperature());Serial.print("C");
|
||||
//Get relative humidity
|
||||
Serial.print(" humidity:"); Serial.print(dht20.getHumidity()*100);Serial.println(" %RH");
|
||||
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
24
libraries/DFRobot_DHT20/keywords.txt
Normal file
24
libraries/DFRobot_DHT20/keywords.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For DFRobot_DHT20
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
DFRobot_DHT20 KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
getHumidity KEYWORD2
|
||||
|
||||
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
9
libraries/DFRobot_DHT20/library.properties
Normal file
9
libraries/DFRobot_DHT20/library.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
name=DFRobot_DHT20
|
||||
version=1.0.0
|
||||
author=fengli DFRobot <li.feng@dfrobot.com>
|
||||
maintainer=fengli DFRobot <li.feng@dfrobot.com>
|
||||
sentence=Provide an Arduino library to get Humidity and Temperature by reading data from dht20.
|
||||
paragraph=<br />Product Link: <a href="https://www.dfrobot.com/product-2391.html">https://www.dfrobot.com/product-2391.html</a><br />Product Link: <a href="https://www.dfrobot.com.cn/goods-3282.html">https://www.dfrobot.com.cn/goods-3282.html</a><br />
|
||||
category=Sensors
|
||||
url=https://github.com/DFRobot/DFRobot_DHT20
|
||||
architectures=*
|
||||
77
libraries/DFRobot_DHT20/python/raspberrypi/DFRobot_DHT20.py
Normal file
77
libraries/DFRobot_DHT20/python/raspberrypi/DFRobot_DHT20.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
# -*- coding: utf-8 -*
|
||||
"""
|
||||
*@file DFRobot_DHT20.py
|
||||
*@brief Define the basic structure of class DFRobot_DHT20
|
||||
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
|
||||
*@licence The MIT License (MIT)
|
||||
*@author [fengli](li.feng@dfrobot.com)
|
||||
*@version V1.0
|
||||
*@date 2021-6-25
|
||||
*@get from https://www.dfrobot.com
|
||||
*@https://github.com/DFRobot/DFRobot_DHT20
|
||||
"""
|
||||
import serial
|
||||
import time
|
||||
import smbus
|
||||
|
||||
class DFRobot_DHT20(object):
|
||||
''' Conversion data '''
|
||||
|
||||
_addr = 0x50
|
||||
|
||||
def __init__(self ,bus,address):
|
||||
self.i2cbus = smbus.SMBus(bus)
|
||||
self._addr = address
|
||||
self.idle = 0
|
||||
|
||||
'''
|
||||
@brief init function
|
||||
@return Return 0 if initialization succeeds, otherwise return non-zero and error code.
|
||||
'''
|
||||
def begin(self ):
|
||||
|
||||
#self.i2cbus.write_byte(self._addr,0xaa)
|
||||
time.sleep(0.5)
|
||||
data = self.read_reg(0x71,1)
|
||||
|
||||
if (data[0] | 0x08) == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
'''
|
||||
@brief Get ambient temperature, unit: °C
|
||||
@return ambient temperature,the measurement range is -40°C ~ 80°C
|
||||
'''
|
||||
def get_temperature(self):
|
||||
self.write_reg(0xac,[0x33,0x00])
|
||||
time.sleep(0.1)
|
||||
data = self.read_reg(0x71,7)
|
||||
rawData = ((data[3]&0xf) <<16) + (data[4]<<8)+data[5]
|
||||
#print(rawData)
|
||||
temperature = float(rawData)/5242 -50
|
||||
return temperature
|
||||
|
||||
'''
|
||||
@brief Get relative humidity, unit: %RH.
|
||||
@return relative humidity, the measurement range is (1-100%)
|
||||
'''
|
||||
def get_humidity(self):
|
||||
self.write_reg(0xac,[0x33,0x00])
|
||||
time.sleep(0.1)
|
||||
data = self.read_reg(0x71,7)
|
||||
rawData = ((data[3]&0xf0) >>4) + (data[1]<<12)+(data[2]<<4)
|
||||
humidity = float(rawData)/0x100000
|
||||
return humidity*100
|
||||
|
||||
|
||||
def write_reg(self, reg,data):
|
||||
time.sleep(0.01)
|
||||
self.i2cbus.write_i2c_block_data(self._addr,reg,data)
|
||||
|
||||
|
||||
def read_reg(self,reg,len):
|
||||
time.sleep(0.01)
|
||||
rslt = self.i2cbus.read_i2c_block_data(self._addr,reg,len)
|
||||
#print(rslt)
|
||||
return rslt
|
||||
65
libraries/DFRobot_DHT20/python/raspberrypi/README.md
Normal file
65
libraries/DFRobot_DHT20/python/raspberrypi/README.md
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# DFRobot_DHT20
|
||||
The DHT20 temperature & humidity sensor is the newly upgraded version of the DHT11. The DHT20 features a brand-new ASIC dedicated chip, an improved MEMS semiconductor capacitive humidity sensor element and a standard on-chip temperature element. All sensors are factory calibrated and characterized by low power, high precision & stability, fast response, and strong anti-interference. Moreover, the DHT20 performance parameters of accuracy, power supply voltage, measurement range and response time have been enhanced greatly over the previous generation,making it more cost-effective. Besides that, the DHT20 temperature & humidity sensor employs I2C digital output protocol, which is very suitable for HVAC,automobiles, data loggers, weather stations, home appliances, and other related temperature and humidity detection and controlled areas. <br>
|
||||
|
||||

|
||||
|
||||
## 产品链接(链接到英文商城)
|
||||
SKU:产品名称
|
||||
## Table of Contents
|
||||
|
||||
* [Summary](#summary)
|
||||
* [Installation](#installation)
|
||||
* [Methods](#methods)
|
||||
* [Compatibility](#compatibility)
|
||||
* [History](#history)
|
||||
* [Credits](#credits)
|
||||
|
||||
## Summary
|
||||
|
||||
Provide an RaspberryPi library to get Humidity and Temperature by reading data from dht20.
|
||||
## Installation
|
||||
|
||||
Download the DFRobot_DHT20 file to the Raspberry Pi file directory, then run the following command line to use this sensor:
|
||||
|
||||
## Methods
|
||||
```python
|
||||
'''
|
||||
@brief init function
|
||||
@return Return 0 if initialization succeeds, otherwise return non-zero and error code.
|
||||
'''
|
||||
def begin(self ):
|
||||
|
||||
'''
|
||||
@brief Get ambient temperature, unit: °C
|
||||
@return ambient temperature, its measurement range is (-40°C ~ 80°C)
|
||||
'''
|
||||
def get_temperature(self):
|
||||
|
||||
'''
|
||||
@brief Get relative humidity, unit: %RH.
|
||||
@return relative humidity, its measurement range is (1-100%)
|
||||
'''
|
||||
def get_humidity(self):
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
MCU | Work Well | Work Wrong | Untested | Remarks
|
||||
------------------ | :----------: | :----------: | :---------: | -----
|
||||
Raspberry Pi | √ | | |
|
||||
|
||||
|
||||
## History
|
||||
|
||||
- Date 2021-7-2
|
||||
- Version V0.1
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
Written by fengli(li.feng@dfrobot.com), 2021.7.2 (Welcome to our [website](https://www.dfrobot.com/))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
|
@ -0,0 +1,34 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
*@file get_data.ino
|
||||
*@brief Read ambient temperature and relative humidity and print them to serial port.
|
||||
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
|
||||
*@licence The MIT License (MIT)
|
||||
*@author [fengli](li.feng@dfrobot.com)
|
||||
*@version V1.0
|
||||
*@date 2020-12-02
|
||||
*@get from https://www.dfrobot.com
|
||||
*@https://github.com/DFRobot/DFRobot_DHT20
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
sys.path.append("../")
|
||||
from DFRobot_DHT20 import *
|
||||
|
||||
IIC_MODE = 0x01 # default use IIC1
|
||||
IIC_ADDRESS = 0x38 # default i2c device address
|
||||
'''
|
||||
# The first parameter is to select iic0 or iic1
|
||||
# The second parameter is the iic device address
|
||||
'''
|
||||
dht20 = DFRobot_DHT20(IIC_MODE ,IIC_ADDRESS)
|
||||
"""
|
||||
@brief Initialize function
|
||||
"""
|
||||
dht20.begin()
|
||||
|
||||
while True:
|
||||
#Read ambient temperature and relative humidity and print them to terminal
|
||||
print("temperature::%f C"%dht20.get_temperature())
|
||||
print("humidity::%f RH"%dht20.get_humidity())
|
||||
time.sleep(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue