Rev Author Line No. Line
4607 jacho 1 #!/usr/bin/python
2  
3 # Python library for SHT3101A MLAB module with SHT31 Temperature and relative humidity sensor.
4  
5 #uncomment for debbug purposes
6 #import logging
7 #logging.basicConfig(level=logging.DEBUG)
8  
9 import time
10 import datetime
11 import sys
12 from pymlab import config
13  
14 #### Script Arguments ###############################################
15  
16 if len(sys.argv) != 2:
17 sys.stderr.write("Invalid number of arguments.\n")
18 sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], ))
19 sys.exit(1)
20  
21 port = eval(sys.argv[1])
22 #### Sensor Configuration ###########################################
23  
24 ''''
25 cfg = config.Config(
26 i2c = {
27 "port": port,
28 },
29  
30 bus = [
31 {
32 "type": "i2chub",
33 "address": 0x72,
34  
35 "children": [
36 {"name": "sht", "type": "sht31", "channel": 1, }
37 ],
38 },
39 ],
40 )
41  
42 '''
43 cfg = config.Config(
44 i2c = {
45 "port": port,
46 },
47 bus = [
48 {
49 "name": "sht",
50 "type": "sht31",
51 },
52 ],
53 )
54  
55  
56 cfg.initialize()
57  
58 print "SHT31 sensor readout example \r\n"
59 sensor = cfg.get_device("sht")
60  
61 sensor.soft_reset()
62 time.sleep(0.1)
63  
64 #### Data Logging ###################################################
65  
66 try:
67 while True:
68 sys.stdout.write("Sensor status: " + str(sensor.get_status()) + " Temperature and Humidity: " + str(sensor.get_TempHum()) + "\r\n")
69 sys.stdout.flush()
70 time.sleep(1)
71 except KeyboardInterrupt:
72 sys.exit(0)