查看: 13868|回复: 31
收起左侧

[传感器] 树莓派上使用SHT20高精度温湿度传感器模块教程

2018-3-29 21:43:49 | 显示全部楼层 |阅读模式
##…………2020年6月1日更新………………
## *************************
       本教程只有VIP用户可以查看,须在论坛官方网店购买树莓派套装(点此购买,Z装除外)方可获得VIP权限
适用于树莓派4代B、3代B+、3代B,2代B,1代B+,1代B,zero等树莓派全型号。
## *************************
本教程供大家学习参考如何在树莓派上使用高精度的温湿度传感器——SHT20模块,提供PYthon代码等。

一、所需设备:
1、SHT20温湿度模块,1个(点此购买
2、杜邦线,10条(点此购买
3、树莓派及树莓派相关配套设备,(点此购买



二、教程开始:
0、接线如下:
游客,如果您要查看本帖隐藏内容请回复

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2018-5-9 21:07:22 | 显示全部楼层
import smbus
import time

eSHT2xAddress       = 0x40
eTempHoldCmd            = 0xE3
eRHumidityHoldCmd   = 0xE5
eTempNoHoldCmd      = 0xF3
eRHumidityNoHoldCmd = 0xF5
writeUserRegister   = 0xE6
readUserRegister    = 0xE7
softReset           = 0xFE
bus = smbus.SMBus(1)

#******************************************************************************
#* Global Functions
#******************************************************************************/

#**********************************************************
#* GetHumidity
#*  Gets the current humidity from the sensor.
#*
#* @return float - The relative humidity in %RH
#**********************************************************/
def getRHumidity():
                return (-6.0 + 125.0 / 65536.0 * float(readSensor(eRHumidityNoHoldCmd)))

#**********************************************************
#* GetTemperature
#*  Gets the current temperature from the sensor.
#*
#* @return float - The temperature in Deg C
#**********************************************************/
def getTemperature():
       
                return (-46.85 + 175.72 / 65536.0 * float(readSensor(eTempNoHoldCmd)))
       


#******************************************************************************
#* Private Functions
#******************************************************************************/

def readSensor(command):       
                bus.write_quick(eSHT2xAddress)
                bus.write_byte(eSHT2xAddress,command)
                time.sleep(0.1)
                result =(bus.read_byte(eSHT2xAddress)<<8)
                result += bus.read_byte(eSHT2xAddress)
                result &= ~0x0003   # clear two low bits (status bits)(0x0003=00000000 00000011 =>~0x0003=11111111 11111100=> &=xxxxxxxx xxxxxx00)
                print result
                return result
       

print "H=",getRHumidity()
print "T=",getTemperature()
回复 支持 1 反对 0

使用道具 举报

2018-3-31 10:35:54 | 显示全部楼层
那啥。。老大。。下载这个后面是个逗号啊。。。没代码学orz
回复 支持 反对

使用道具 举报

2018-4-3 16:38:46 | 显示全部楼层
看一下谢谢
回复 支持 反对

使用道具 举报

2018-5-7 20:50:03 | 显示全部楼层
看不到教程,怎办?
回复 支持 反对

使用道具 举报

2018-5-9 21:07:59 | 显示全部楼层
这个可以用
回复 支持 反对

使用道具 举报

2018-6-9 23:27:33 | 显示全部楼层
666666666666666666
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注我们,了解更多

官方微信

服务时间:10:00-16:00

13714503811

公司地址:深圳市龙岗区南湾街道东门头路8号

Copyright © 2012-2020 Powered by 树莓派论坛 2019.4  粤ICP备15075382号-1
快速回复 返回列表 返回顶部