Advertisement
Guest User

Sean Brewer

a guest
Jan 23rd, 2010
1,678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  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. #
  9.  
  10.  
  11. import serial
  12. import array
  13.  
  14. def startAccessPoint():
  15.     return array.array('B', [0xFF, 0x07, 0x03]).tostring()
  16.  
  17. def accDataRequest():
  18.     return array.array('B', [0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00]).tostring()
  19.  
  20. #Open COM port 6 (check your system info to see which port
  21. #yours is actually on.)
  22. #argments are 5 (COM6), 115200 (bit rate), and timeout is set so
  23. #the serial read function won't loop forever.
  24. ser = serial.Serial(5,115200,timeout=1)
  25.  
  26. #Start access point
  27. ser.write(startAccessPoint())
  28.  
  29.  
  30. while True:
  31.     #Send request for acceleration data
  32.     ser.write(accDataRequest())
  33.     accel = ser.read(7)
  34.  
  35.     if len(accel) != 7 or (ord(accel[0]) == 0 and ord(accel[1]) == 0 and ord(accel[2]) == 0):
  36.         continue
  37.     print "x: " + str(ord(accel[2])) + " y: " + str(ord(accel[1])) + " z: " + str(ord(accel[0]))
  38.     print "Datatype: " + str(ord(accel[3]))
  39.    
  40. ser.close()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement