Program to capture and plot data from the 10x10 temperature sensor array.
import serial, sys
from pylab import *
size = 12 # size of display window
minT = float(sys.argv)
maxT = float(sys.argv)
port = sys.argv
except (ValueError, IndexError):
Call program with three or four parameters: At a minimum, give
minimum expected temperature,
maximum expected temperature,
location of serial port.
If you wish to save your data, add the base filename for saved data
frames as a fourth parameter.
# start the serial port
ser = serial.Serial(port, 57600, timeout=2)
print "Could not open port %s, exiting." % port
# check to see if data is to be saved
baseFName = sys.argv
print "Data will be saved as %sxxxx.txt" %baseFName
save = True
print "Data will not be saved."
save = False
# allow animation
# set up matrix for temperature data
grid = zeros([10,10])
# read and discard a line to help get things in sync.
junk = ser.readline()
# open the view window
fig = figure(figsize=(size+1, size))
# define the levels at which to draw contours. The resolution
# of the sensors at 9-bit (default) sensitivity is about 0.12,
# so setting level spacing below this does not help.
levels = arange(minT, maxT+0.12, 0.12)
FrameNumber = 0
# now the main loop, which continues until an error occurs.
# this is the stuff to do unless a problem occurs.
# Read a line of temperature data from the Arduino
line = ser.readline()
# split the line into a list of floating-point values
temperatures = [float(T) for T in line.split()]
# sort the list of temperatures into a matrix for plotting
for j in range(10):
for k in range(10):
grid[j,k] = temperatures[j*10+k]
# Save the data if required
fname = "%s%04d.txt" % (baseFName, FrameNumber)
savetxt(fname, grid, fmt='%0.2f')
# plot the data
if FrameNumber == 0: # We've just started, so add scale.
cbar = colorbar(ticks=linspace(minT, maxT, 11))
cbar.ax.set_yticklabels(linspace(minT, maxT, 11))
# increment frame number and continue
FrameNumber += 1
# Handle problems here
# error at float conversion
print "Conversion error: frame dropped, continuing collection."
# not all values received for a measurement set
print "Partial frame received: frame dropped, continuing collection."
# Someone just unplugged the device, or other loss of communication.
print "Device disconnected, exiting."
# problem saving data
print "Input/Output Error, exiting."
print "Unknown error! Exiting program..."
Generated by GNU enscript 1.6.4.