Guest User

Sean Brewer

a guest
Jan 23rd, 2010
1,220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Get acceleration data from Chronos watch.
  2. #Taken from info posted at: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/32714.aspx
  3. #x, y, and z values may not be "in order". The first three bytes from the packet
  4. #of data sent from the watch seemed to be different than what was listed
  5. #on the page, though the datatype byte was in the correct place. So YMMV.
  6. #
  7. #Written by Sean Brewer (seabre)
  8. #seabre986@gmail.com
  9. #
  10.  
  11.  
  12. import serial
  13. import array
  14.  
  15. def startAccessPoint():
  16.     return array.array('B', [0xFF, 0x07, 0x03]).tostring()
  17.  
  18. def accDataRequest():
  19.     return array.array('B', [0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00]).tostring()
  20.  
  21. #Open COM port 6 (check your system info to see which port
  22. #yours is actually on.)
  23. #argments are 5 (COM6), 115200 (bit rate), and timeout is set so
  24. #the serial read function won't loop forever.
  25. ser = serial.Serial(5,115200,timeout=1)
  26.  
  27. #Start access point
  28. ser.write(startAccessPoint())
  29.  
  30.  
  31. while True:
  32.     #Send request for acceleration data
  33.     ser.write(accDataRequest())
  34.     accel = ser.read(7)
  35.  
  36.     if len(accel) != 7 or (ord(accel[0]) == 0 and ord(accel[1]) == 0 and ord(accel[2]) == 0):
  37.         continue
  38.     print "x: " + str(ord(accel[2])) + " y: " + str(ord(accel[1])) + " z: " + str(ord(accel[0]))
  39.     print "Datatype: " + str(ord(accel[3]))
  40.    
  41. ser.close()
  42.  
RAW Paste Data