update drySensor function
This commit is contained in:
@@ -38,7 +38,7 @@ def reset(extra = 0):
|
||||
CONFIG_HRES_14 |
|
||||
extra
|
||||
)
|
||||
bus.i2c([CONFIG_REG, config >> 8], 0)
|
||||
bus.i2c([CONFIG_REG, config >> 8, config & 0xff], 0)
|
||||
|
||||
def temperature():
|
||||
# Request temperature measurement
|
||||
@@ -68,10 +68,9 @@ def drySensor():
|
||||
|
||||
# Take 1000 reading as fast as possible
|
||||
# (the heater is only activated when performing a reading)
|
||||
for x in range(10000):
|
||||
for x in range(1000):
|
||||
try:
|
||||
temperature()
|
||||
time.sleep(0.1)
|
||||
except: pass
|
||||
|
||||
# Turn off the heater
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#stributed with a free-will license.
|
||||
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
|
||||
# HDC1000
|
||||
# This code is designed to work with the HDC1000_I2CS I2C Mini Module available from ControlEverything.com.
|
||||
# https://www.controleverything.com/content/Temperature?sku=HDC1000_I2CS#tabs-0-product_tabset-2
|
||||
|
||||
import smbus
|
||||
import time
|
||||
|
||||
# Get I2C bus
|
||||
bus = smbus.SMBus(1)
|
||||
|
||||
# HDC1000 address, 0x40(64)
|
||||
# Select configuration register, 0x02(02)
|
||||
# 0x30(48) Temperature, Humidity enabled, Resolultion = 14-bits, Heater on
|
||||
bus.write_byte_data(0x40, 0x02, 0x30)
|
||||
|
||||
# HDC1000 address, 0x40(64)
|
||||
# Send temp measurement command, 0x00(00)
|
||||
bus.write_byte(0x40, 0x00)
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
# HDC1000 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 * 256) + data1
|
||||
print(hex(temp))
|
||||
cTemp = (temp / 65536.0) * 165.0 - 40
|
||||
fTemp = cTemp * 1.8 + 32
|
||||
|
||||
# HDC1000 address, 0x40(64)
|
||||
# Send humidity measurement command, 0x01(01)
|
||||
bus.write_byte(0x40, 0x01)
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
# HDC1000 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
|
||||
print(hex(humidity))
|
||||
humidity = (humidity / 65536.0) * 100.0
|
||||
|
||||
# Output data to screen
|
||||
print "Relative Humidity : %.2f %%" %humidity
|
||||
print "Temperature in Celsius : %.2f C" %cTemp
|
||||
print "Temperature in Fahrenheit : %.2f F" %fTemp
|
||||
|
||||
Reference in New Issue
Block a user