Skip to content

Commit

Permalink
moved reference voltage from xbee_api.py. This way we keep
Browse files Browse the repository at this point in the history
this package dealing with protocol level, without need to know
specifics of actual schematics, like Vref.
  • Loading branch information
vzaliva committed Mar 9, 2013
1 parent d6104d2 commit f4100f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 9 additions & 5 deletions data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@
logger = None
global_lock = lockfile.FileLock(LOCK_FILE)

VREF = 1235 #LM385-1.2

def cleanup():
if global_lock.is_locked():
global_lock.release()


def usage():
print """
%s [-s /dev/ttyUSB0]
-s port -- use serial port <port>. Default is /dev/ttyUSB0
-c -- output packet log to console
""" % sys.argv[0]

def get_adc_v(pkt, adc_idx):
"Retruns ADC value in volts"
return float(pkt.get_adc(adc_idx)/pkt.num_samples * VREF / 1024)

def main():
global logger
Expand Down Expand Up @@ -94,9 +99,9 @@ def main():
pkt = pkt_reader.next()

try:
adc0 = float(pkt.get_adc(0))
adc1 = float(pkt.get_adc(1))
temp_C = tmp36.get_t_from_adc(adc1)
adc0 = float(get_adc_v(pkt,0))
adc1 = float(get_adc_v(pkt,1))
temp_C = tmp36.get_t_from_adc(adc0)

time_now = time.time()
report = 'packet_size={0} adc0={1:.3f} mV adc1={2:.3f} mV T={3:.1f} C'.format(
Expand All @@ -118,6 +123,5 @@ def main():
except serial.SerialException,e:
print e


if __name__ == '__main__':
main()
11 changes: 1 addition & 10 deletions xbee_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

logger = logging.getLogger('default')

# Vref = 2500.0 # MCP1525
Vref = 2048 # LM4040D20 (actually measured 2036.4 mV, 0.5% difference)

# Sample packet:
# 7e 0 e 83 56 78 3f 0 1 7 0 1 0 3 ff 3 ff 62
#
Expand Down Expand Up @@ -116,8 +113,6 @@ def decode_packet(self, frame, length):
self.d_channels_data = [0 for x in range(0,9)]
self.a_channels_data = [0 for x in range(0,8)]

adc_data = [0.0 for x in range(0,8)]

frame_byte = 8
for n in range(0, self.num_samples):
if self.have_d_channels:
Expand All @@ -126,14 +121,10 @@ def decode_packet(self, frame, length):

for adc_idx in range(0, len(self.a_channels_enabled)):
if self.a_channels_enabled[adc_idx]:
adc_data[adc_idx] += self.a_data(
self.a_channels_data[adc_idx] += self.a_data(
frame[frame_byte], frame[frame_byte+1])
frame_byte += 2

# store ADC channel data in mV
for adc_idx in range(0, len(self.a_channels_enabled)):
self.a_channels_data[adc_idx] = (
float(adc_data[adc_idx]) / self.num_samples * Vref / 1024)
except IndexError:
logger.error('Invalid XBee API frame: "{0}"'.format(frame))

Expand Down

0 comments on commit f4100f3

Please sign in to comment.