18,9 → 18,9 |
print("Connected to serial port.") |
# Loop reading in data from the sensor |
while(1): |
s = ser.read(19) |
s = ser.read(21) |
# Ensure that the data properly ends in a newline |
if s[18] == ord('\n'): |
if s[20] == ord('\n'): |
# Read in accelerometer data and convert from two's compliment |
A_X = ((s[1] << 8) | s[0]) |
A_Y = ((s[3] << 8) | s[2]) |
45,9 → 45,13 |
M_Y_N = twos_comp(M_Y, 16) |
M_Z_N = twos_comp(M_Z, 16) |
|
# Read in battery status |
B_H = s[18] |
B_L = s[19] |
|
# Print out the processed data |
print("A: %-6i %-6i %-6i G: %-6i %-6i %-6i M: %-6i %-6i %-6i" % \ |
(A_X_N, A_Y_N, A_Z_N, G_X_N, G_Y_N, G_Z_N, M_X_N, M_Y_N, M_Z_N)) |
print("A: %-6i %-6i %-6i G: %-6i %-6i %-6i M: %-6i %-6i %-6i B: %u.%u" % \ |
(A_X_N, A_Y_N, A_Z_N, G_X_N, G_Y_N, G_Z_N, M_X_N, M_Y_N, M_Z_N, B_H, B_L)) |
else: |
break |
except: |