Rev Author Line No. Line
4584 kaklik 1 #!/usr/bin/python
2  
3 # Python library for ISL2902001A MLAB module with I2C light 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 cfg = config.Config(
25 i2c = {
26 "port": port,
27 },
28 bus = [
29 {
30 "name": "sensor",
31 "type": "ISL01",
32 },
33 ],
34 )
35  
36  
37 cfg.initialize()
38  
39 print "ISL2902001A light senzor readout example \r\n"
40 sensor = cfg.get_device("sensor")
41  
42 #### Data Logging ###################################################
43  
44 try:
45 while True:
46 sys.stdout.write("IR Light intensity: " + str(sensor.get_lux_IR()) + \"\r\n")
47 sys.stdout.flush()
48 time.sleep(0.2)
49 except KeyboardInterrupt:
50 sys.exit(0)