## # Python script to read samples from VSV board. # # USE: ./getaccdata.py | tee output.txt import time import serial import sys # Set serial port for your PC serialport = '/dev/tty.usbserial-A4001lcR' # Configure pySerial serial port. Official documentation can be found here: # http://pyserial.sourceforge.net/ ser = serial.Serial(serialport, 115200, timeout=1) sys.stderr.write('Delaying 4 seconds to allow Arduino to boot...') # Delay 4 seconds to allow Arduino to 'boot-up' # (newer Decimilia-type Arduino's only) time.sleep(4) sys.stderr.write(' Done.\n') # Turn on 'PC' light on VSV board ser.write('v') while 1: # Send 'read' command ser.write('r') # Read in 1024 samples for i in range(1024): # Read in upper/lower byte input_h = ser.read() input_l = ser.read() # Python reads serial data as strings; the following # two lines convert the upper and lower byte to ints sample_h = int(hex(ord(input_h)), 16) sample_l = int(hex(ord(input_l)), 16) # Convert two's complement data to a signed int if (sample_h > 127): sample_h = sample_h-255 # Sample = (UpperByte << 8) + LowerByte sample = sample_h * 256 + sample_l print str(sample)