-
Notifications
You must be signed in to change notification settings - Fork 1
/
SHT25.py
51 lines (40 loc) · 1.31 KB
/
SHT25.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# SHT25
# This code is designed to work with the SHT25_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Humidity?sku=SHT25_I2CS#tabs-0-product_tabset-2
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(2)
# SHT25 address, 0x40(64)
# Send temperature measurement command
# 0xF3(243) NO HOLD master
bus.write_byte(0x40, 0xF3)
time.sleep(0.5)
# SHT25 address, 0x40(64)
# Read data back, 2 bytes
# Temp MSB, Temp LSB
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
temp = data0 << 8 + data1
cTemp= -46.85 + ((temp * 175.72) / 65536.0)
fTemp = cTemp * 1.8 + 32
# SHT25 address, 0x40(64)
# Send humidity measurement command
# 0xF5(245) NO HOLD master
bus.write_byte(0x40, 0xF5)
time.sleep(0.5)
# SHT25 address, 0x40(64)
# Read data back, 2 bytes
# Humidity MSB, Humidity LSB
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
# Convert the data
humidity = data0 * 256 + data1
humidity = -6 + ((humidity * 125.0) / 65536.0)
# Output data to screen
print "Relative Humidity is : %.2f %%" %humidity
print "Temperature in Celsius is : %.2f C" %cTemp
print "Temperature in Fahrenheit is : %.2f F" %fTemp