Tested on:RPi 3; Raspbian Jessie; Python 2.7
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:Neurosky Mindwave EEG (wifi, not the bluetooth one)
LED and a fitting resistor
2 Jumper cables male to female
Breadboard
18

Raspberry Pi mindcontrol! Neurosky mindwave as simple EEG interface

An electroencephalogram (EEG) measures brain activity with electrodes directly attached to the head. Nowadays, EEGs are very affordable- the one used in this tutorial, the Neurosky Mindwave, costs around 100€. Luckily, Moonshot Barkley already built a Python framework for accessing the Neurosky EEG. A big “thank you” to the developers!
In this tutorial, the Neurosky Mindwave will be used to display brain activity by controlling an LEDs intensity with a Raspberry Pi. Measuring brain activity allows developing a fast range of interesting devices, ranging from fun applications to scientific experiments.

Demo Video

Thousand thanks to Alex, Thesi, Alex and Tim for making this amazing demo video! For one of us, we measured absolutely zero brain activity- they are among us!

Neurosky Mindwave models
There are different product lines of Neurosky EEG sets. Some of them connect over Wifi and others use Bluetooth. This tutorial is for the Neurosky Mindwave (not Mindwave mobile!) which connects over Wifi. The bluetooth ones should run on the Raspberry Pi as well, but not with the framework in this tutorial. This is what a Neurosky Mindwave looks like:

Neurosky Mindwave EEG

Neurosky Mindwave EEG

Circuit
Assemble this circuit on a breadboard:

LED circuit

LED circuit

The LED is connected to pin 11 of the Raspberry Pi in BOARD-numbering and to ground (pin 6). Make sure the resistor fits the LED; ask your vendor for an LED with resistor for 3.3V and 20mA if unsure.

Software installation
Boot the Raspberry Pi, then plug the Mindwave USB dongle into it. Enter

in the terminal and find the device identifier. Without other USB devices attached, it is ttyUSB0 like in

Also, write down the headset identifier. It is a code of four letters and located inside the battery case.
Turn on the Mindwave headset- both the headset and the dongle should show a red light for not being connected.
Type the following in the terminal:

The script needs to be configured. In the line

enter the USB identifier and headset identifier noted earlier. Save and exit nano, attach the headset to your head and start the script by typing

in the terminal.
This should print connected and the light of both the headset and the dongle should turn blue.
The current attention level is printed to the terminal and controls the intensity of the LED. The more focused you are, the brighter it will glow and it will go off if a certain level of relaxation is reached.

Code explained
The hard work of building the wifi interface is done by the great mindwave-python framework from Moonshot Barkley. The script mindwave_LED.py simply configures the LED pin for pulse-width-modulation with

Then, the attention level is being scaled in the main loop for improved visibility:

This only displays an attention level above 30 and restricts the pwm signal to a max of 100.

Click on Full Script to show all of the code.

Sample Video

Links
Software PWM tutorial: http://www.knight-of-pi.org/simple-dc-motor-board-for-the-raspberry-pi-with-ic-l293-and-software-pulse-width-modulation/
Moonshot Barkley Neurosky Mindwave Python interface: https://github.com/BarkleyUS/mindwave-python

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

18 Comments

  1. Hi!

    This setup is closest to what I need but since I actually never done any RaspberryPi or Python or EEG or any equivalents for that matter, I’m real need for precise directions… :D :/

    I need RaspberryPi camera to shoot every time I blink (not intentionally but literally every time I do a blink, yes, that’s about 28,000 blinks per day…)

    As far as I understand:
    – option 1: NeuroSky got a blink camera for Android phone – https://store.neurosky.com/products/blink-camera-android. If I change its setting to recognise not a 3 sec long blink but literally every (0.3-0.4 sec long) blink and also send this not to phone camera but to a RaspberryPi camera or a mini spy camera https://www.amazon.co.uk/gp/product/B06WLMGJV5/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
    – option 2: Python mediates between Neurosky and RaspberryPi camera: headset detects blinks – Python colour codes them and sets RaspberryPi to react by making a shot each time

    In both cases Bluetooth is easier.

    Once again, I really have no understanding of what I’m talknig about, so I would so appreciate a desription of what and how to do in this case…

    Thank you so much in advance!

    ^_^
    Zhenya

    • Hi Zhenya,
      i do not think the Neurosky Mindwave will suit your needs. Will the camera and the eye always have the same position to each other? If so, it might be possible to catch blinks with pixel changes from frame to frame with MotionPie for example. If the camera is fixed, but you move, you’d probably need face detection and then mimic recognition, which will be difficult to build.

  2. thank you so much for useful article , i work on simillar project but with arduino usb host shield can you help me what libraries to use ?

    • I don’t know, but you could google “arduino robot mind control”. There’s a book ect. how to hack the Mindwave for an Arduino, if that’s an option.

  3. Is there any intuituve way for vizualing all of data? Something like a bar graph or linear graph. I would like to view alpha, theta…

    • I’d strongly recommend Numpy, Pandas and Mathplotlib for data visualisation. I’m planning tutorial on that, but it’ll take some time.
      For Alpha and Theta: The Python interface
      https://github.com/JoBergs/mindwave-python/blob/master/mindwave.py
      only gives “attention” and “meditation”.
      I remember an Amazon customer review discussing the accuracy of the Neurosky Mindwave for scientific experiments. The point is, this model uses an ear clip for measuring the pulse. The output combines that and the front sensor reading, so no Alpha and Theta.
      That might be different for newer models. If you experiment into that direction and find a better EEG interface, please let me know!

      EDIT: Clarity

  4. My neurosky has only a bluetooth connectivity. I have a raspberry pi3 . How can i connect the headset to my raspberry pi and how to do the above stuff.pls help

    • I don’t know the bluetooth models, but Neurosky supplies open interfaces for their headsets generally, so chances are good. Just google your specific model number plus “Python interface” and look around.

      • I think you can get a bit more out of the headset.
        https://pypi.python.org/pypi/NeuroPy/0.1
        Alpha, theta, blinking appear to be available at some level if you can get into the code.
        It must also have custom software supplied with it? Proabably runs as a stand alone program in windows?

  5. Hi!
    I am working on same issue, but instead of neurosky. I was wondring if I can build my own EEG electrodes at cheap cost. I am getting problem with the Amplifiers, if you have any suggestions for me then please reply to my email.
    My project: EEG Game Simulator using BCI. I completed Hand Gesture Game Simulator & trying to create at different level: https://www.youtube.com/watch?v=4pJtTksczvs

  6. This is a subject close to my heart cheers.
    Thanks

  7. I was waiting for this form of issue. Thank you very much for
    the place.

Comment

Time limit is exhausted. Please reload CAPTCHA.