Created
December 5, 2016 17:59
-
-
Save tumugin/9eb86a5a7d69ca86442a322a82bfffb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import wiringpi | |
import os | |
import struct | |
from time import sleep | |
wiringpi.wiringPiSetup() #setup wiringpi | |
i2c = wiringpi.I2C() #get I2C | |
dev = i2c.setup(0x40) #setup I2C device | |
i2c.write(dev,0x02) #HDC1000 CONFIGURATION POINTER | |
i2c.write(dev,0x10) #send 1byte | |
i2c.write(dev,0x00) #send 1byte | |
sleep((6350.0 + 6500.0 + 500.0)/1000000.0) | |
dataAry = struct.unpack("BBBB",os.read(dev,4)) | |
os.close(dev) | |
temp = (dataAry[0] << 8) | (dataAry[1]) | |
hudi = (dataAry[2] << 8) | (dataAry[3]) | |
temp = ((temp / 65535.0) * 165 - 40) | |
hudi = ((hudi / 65535.0 ) * 100) | |
print("Humidity %.2f" % hudi) | |
print("Temperature %.2f" % temp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment