In [1]:
from mindwave.parser import ThinkGearParser, TimeSeriesRecorder
import bluetooth
import time
import sys

from mindwave.bluetooth_headset import connect_magic, connect_bluetooth_addr
from mindwave.bluetooth_headset import BluetoothError

In [6]:
from IPython.display import Image
Image(filename='Images/20150629095945.jpg',width=300)


Out[6]:

In [2]:
def mindwave_start():
    socket, socket_addr = connect_magic()
    if socket is None:
        print "No MindWave found"
        sys.exit(-1)
    print "Connected at %s" % socket_addr
    return socket

In [20]:
socket = mindwave_start()


found
Connected with MindWave Mobile at 74:E5:43:D5:71:0A

In [21]:
recorder = TimeSeriesRecorder()
parser = ThinkGearParser(recorders=[recorder])

In [25]:
while 1:
        time.sleep(0.25)
        data = socket.recv(20000)
        parser.feed(data)
        print recorder.attention


2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
2015-06-29 13:33:18.233400    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
2015-06-29 13:33:18.233400    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
2015-06-29 13:33:18.233400    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
2015-06-29 13:33:18.233400    44
2015-06-29 13:33:19.038693    44
dtype: int64
2015-06-29 13:32:59.318952    30
2015-06-29 13:33:00.116438    29
2015-06-29 13:33:01.180214    29
2015-06-29 13:33:02.234344    29
2015-06-29 13:33:03.286529    29
2015-06-29 13:33:04.075832    30
2015-06-29 13:33:05.122458    37
2015-06-29 13:33:06.167077    44
2015-06-29 13:33:07.219940    44
2015-06-29 13:33:08.011067    44
2015-06-29 13:33:09.063324    44
2015-06-29 13:33:10.117609    44
2015-06-29 13:33:11.189678    44
2015-06-29 13:33:11.981058    44
2015-06-29 13:33:13.531796    44
2015-06-29 13:33:14.531796    44
2015-06-29 13:33:15.059625    44
2015-06-29 13:33:16.114716    44
2015-06-29 13:33:17.169653    44
2015-06-29 13:33:18.233400    44
2015-06-29 13:33:19.038693    44
dtype: int64
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-25-a0d3efbdd3bd> in <module>()
      1 while 1:
----> 2        time.sleep(0.25)
      3        data = socket.recv(20000)
      4        parser.feed(data)
      5        print recorder.attention

KeyboardInterrupt: 

In [26]:
recorder.meditation


Out[26]:
2015-06-29 13:32:59.316767    30
2015-06-29 13:33:00.113987    40
2015-06-29 13:33:01.177768    40
2015-06-29 13:33:02.231874    40
2015-06-29 13:33:03.284071    40
2015-06-29 13:33:04.073325    43
2015-06-29 13:33:05.120480    38
2015-06-29 13:33:06.165084    57
2015-06-29 13:33:07.217460    57
2015-06-29 13:33:08.008636    57
2015-06-29 13:33:09.060861    57
2015-06-29 13:33:10.114070    57
2015-06-29 13:33:11.187494    57
2015-06-29 13:33:11.978591    57
2015-06-29 13:33:13.529708    57
2015-06-29 13:33:14.529708    57
2015-06-29 13:33:15.055491    57
2015-06-29 13:33:16.112290    57
2015-06-29 13:33:17.167188    57
2015-06-29 13:33:18.230941    57
2015-06-29 13:33:19.035533    57
dtype: int64

In [ ]:
%matplotlib inline
import time
import pylab as pl
from IPython import display

pl.style.use('ggplot')
pl.figure(figsize=(20,10))
while 1:
    time.sleep(0.15)
    data = socket.recv(20000)
    parser.feed(data)
    # print recorder.attention
    pl.plot(recorder.attention.values, 'r-')
    #pl.plot(recorder.meditation.values, 'b-')
    
    display.clear_output(wait=True)
    display.display(pl.gcf())
    #time.sleep(1.0)



In [19]:
recorder.raw.values.shape, recorder.meditation.shape


Out[19]:
((461643,), (900,))