first commit
This commit is contained in:
commit
e6a42e28e9
4355 changed files with 4626605 additions and 0 deletions
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