# -*- coding: utf-8 -*- #Loguino.py - Take data from an Arduino and plot a graph of it #Adam Greig, Feb 2009, NegativeAcknowledge.com #Released into the public domain, for what it's worth #We need sqrt to calculate magnitude from math import sqrt #Read in the data datfile = open('data1.dat') times = [ 0 ] mags = [ 0 ] for line in datfile: values = line.split('\t') times.append( int(values[0]) ) mags.append( sqrt( int(values[1])**2 + int(values[2])**2 + int(values[3])**2 ) ) datfile.close() #Plot a graph, requires matplotlib, opens a window that lets you scroll and save the graph import matplotlib.pyplot as plt plt.plot( times, mags ) plt.title('Magnitude of Acceleration vs Time') plt.suptitle('Measured using an accelerometer on an Arduino performing SHM') plt.ylabel( '|Acceleration|' ) plt.xlabel( 'Time (ms)' ) plt.axis( [0, 4000, 0, 45] ) plt.show()