Bosch XDK

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import serial
import numpy
import threading
import time

app = QtGui.QApplication([])

win = pg.GraphicsWindow()
p1 = win.addPlot()
win.nextRow()
p2 = win.addPlot()
p1.setLabel('bottom', 'Time', units='s')
p1.setLabel('left', 'Acceleration', units='m/s^2')
p2.setLabel('bottom', 'Time', units='s')
p2.setLabel('left', 'Angular velocity', units='mDeg/s')
accl_curves = [p1.plot(), p1.plot(), p1.plot()]
gyro_curves = [p2.plot(), p2.plot(), p2.plot()]

ser = serial.Serial('/dev/ttyACM0', 19200, timeout=1)

acl_rd = 'BMI160 Accel Raw Data'
acl_cd = 'BMI160 Accel Converted Data'
gyro_rd = 'BMI160 Gyro Raw Data'
gyro_cd = 'BMI160 Gyro Converted Data'

N = 1000
acl_rd_data = numpy.zeros((4,N))
acl_cd_data = numpy.zeros((4,N))
gyro_rd_data = numpy.zeros((4,N))
gyro_cd_data = numpy.zeros((4,N))

running = True

def read_serial():
    def get_nums(line):
        return map(int, line[line.find('(')+1:line.find(')')].split(','))

    def append(buf, data, tiden):
        buf[:, :-1] = buf[:, 1:]
        buf[:3, -1] = data
        buf[-1, -1] = tiden

    while running:
        line = ser.readline()
        try:
            nums = get_nums(line)
        except:
            continue
        tiden = time.clock()
        if line[:len(acl_rd)] == acl_rd:
            append(acl_rd_data, nums, tiden)
        elif line[:len(acl_cd)] == acl_cd:
            append(acl_cd_data, nums, tiden)
        elif line[:len(gyro_rd)] == gyro_rd:
            append(gyro_rd_data, nums, tiden)
        elif line[:len(gyro_cd)] == gyro_cd:
            append(gyro_cd_data, nums, tiden)

thread = threading.Thread(target=read_serial, args=())
thread.start()

def update_curve():
    accl_curves[0].setData(acl_cd_data[3, :], acl_cd_data[0,:], pen='r')
    accl_curves[1].setData(acl_cd_data[3, :], acl_cd_data[1,:], pen='g')
    accl_curves[2].setData(acl_cd_data[3, :], acl_cd_data[2,:], pen='b')

    gyro_curves[0].setData(gyro_cd_data[3, :], gyro_cd_data[0,:], pen='r')
    gyro_curves[1].setData(gyro_cd_data[3, :], gyro_cd_data[1,:], pen='g')
    gyro_curves[2].setData(gyro_cd_data[3, :], gyro_cd_data[2,:], pen='b')        
    app.processEvents()

timer = QtCore.QTimer()
timer.timeout.connect(update_curve)
timer.start(0)

QtGui.QApplication.instance().exec_()
running = False

IMU graph visualization with pyqtgraph