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
6

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.

6 Comments

  1. 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

Comment

Time limit is exhausted. Please reload CAPTCHA.