/Designs/Measuring_instruments/AWS01B/SW/Python/AWS_read.py
0,0 → 1,74
#!/usr/bin/python
 
# Python driver for MLAB MAG01A module with HMC5888L Magnetometer sensor wrapper class
 
import time
import datetime
import sys
 
from pymlab import config
 
 
#### Script Arguments ###############################################
 
if len(sys.argv) != 2:
sys.stderr.write("Invalid number of arguments.\n")
sys.stderr.write("Usage: %s #I2CPORT\n" % (sys.argv[0], ))
sys.exit(1)
 
port = eval(sys.argv[1])
 
 
#### Sensor Configuration ###########################################
 
cfg = config.Config(
port = port,
bus = [
{
"type": "i2chub",
"address": 0x72,
"children": [
{
"type": "i2chub",
"address": 0x70,
"channel": 0,
"children": [
{"name": "barometer", "type": "altimet01" , "channel": 0, },
{"name": "hum_temp", "type": "sht25" , "channel": 1, },
# {"name": "wind_direction", "type": "mag01" , "channel": 1, },
],
},
# {"name": "barometer2", "type": "altimet01" , "channel": 6, },
],
},
],
)
 
cfg.initialize()
 
barometer = cfg.get_device("barometer")
hum_temp = cfg.get_device("hum_temp")
#wind_direction = cfg.get_device("wind_direction")
time.sleep(0.5)
 
#### Data Logging ###################################################
 
filename = datetime.datetime.now().isoformat()
 
 
try:
with open(filename+".log", "a") as f:
while True:
barometer.route()
(t1, p1) = barometer.get_tp()
hum_temp.route()
t2 = hum_temp.get_temp()
h1 = hum_temp.get_hum()
 
sys.stdout.write(" Temperature: %.2f Pressure: %d TempSHT: %.2f HumSHT: %.1f " % (t1, p1, t2, h1,))
f.write("%d\t%.2f\t%d\t%.2f\t%.1f\n" % (time.time(),t1, p1, t2, h1,))
sys.stdout.flush()
time.sleep(10)
except KeyboardInterrupt:
sys.exit(0)