Home

Awesome

Arduino Brain Library

Overview

Brain is an Arduino Library for parsing data from Neurosky-based EEG headsets. Tested units include the Star Wars Force Trainer and Mattel MindFlex.

It's designed to make it simple to send out an ASCII string of comma-separated values over serial, or to access processed brain wave information directly in your Arduino sketch. See the examples for code demonstrating each use case.

Instructions for the hardware-end of this hack are available here:

https://frontiernerds.com/brain-hack

This library pairs nicely with the Processing-based BrainGrapher.

The getCSV() function returns a string (char*) listing the most recent brain data, in the following format:

signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma

Signal strength ranges from 0 – 200. Counterintuitively, 0 means the unit has connected successfully, and 200 means there is no signal.

The attention and meditation values both run from 0 – 100. Intuitively, higher numbers represent more attention or meditation.

The EEG power values — delta, theta, etc... — are a heavily filtered representation of the relative activity in different brain wavelengths. These values can not be mapped directly to physical values (e.g. volts), but are still of use when considered over time or relative to each other.

Compatibility

This library expects a certain serial protocol from attached devices. Hardware that uses a different protocol won't work and you will see serial or parsing related errors.

DeviceCompatibility
Star Wars Force Trainer✅ Yes
Mattel Mindflex✅ Yes
Star Wars Force Trainer II❌ No
Neurosky MindWave Mobile 2❌ No

If you've tested with additional headsets, please feel free to open an issue to report your findings.

Support for additional devices is definitely feasible, and pull requests are welcome, but I currently don't have the time or hardware access to implement this on my own.

Repository rename

This project was formerly Arduino-Brain-Library on GitHub, but was renamed to just Brain in 2014 to play nicely with the Arduino IDE's new "Sketch → Import Library..." menu item.

Software serial

Past versions of this library relied on a separate branch implementing support for NewSoftSerial. Improvements to both the bundled SoftwareSerial library and the underlying class hierarchy in Arduino 1.0 has allowed a single version of the Brain library to cover both use cases. Please do not use the old softserial branch of this library!

Examples

Three examples are provided with the library:

Installation

There are two ways to install the library:

Installation through the Arduino IDE

Download the latest release, and then in the Arduino IDE go to "Sketch → Import Library..." and point the file dialogue to the Brain.zip file you just downloaded.

Manual Installation

Download the latest release, decompress, rename it to Brain, and drag "Brain" folder to Arduino's "libraries" folder inside your sketch folder. (On the Mac, this is ~/Documents/Arduino/libraries by default. You may need to create this folder if it does not exist.) Restart the Arduino environment.

Function Overview

Minutiae

Note that the connection to the Neurosky headset is half-duplex — it will use up the RX pin on your Arduino, but you will still be able to send data back to a PC via USB. (Although in this case you won't be able to send data to the Arduino from the PC.)

You may wish to read brain data over a software serial connection instead of the Arduino's hardware serial (this frees up the hardware serial for full-duplex operation). There's a different branch of this library designed for use with NewSoftSerial: https://github.com/kitschpatrol/Arduino-Brain-Library/tree/softserial

The MindFlex provides access to more brain data than the Force Trainer — in addition to the signal strength, attention and meditation values, the MindFlex gives access to 8 bands of EEG power data.

Brain data comes in quite slowly. Expect a fresh packet every second or so.

Contact

Eric Mika
eric@ericmika.com
https://github.com/kitschpatrol
https://frontiernerds.com

Colophon

Created by Eric Mika at NYU ITP in the spring of 2010. Updated for Arduino 1.0 in 2013. Revised, retested, and cleaned up in early 2014.

My thanks to Tom Igoe for his assistance during development. Thanks to my collaborators Sofy Yuditskaya and Arturo Vidich. (E>)

Thanks also to Eero af Heurlin for making some considered changes in his fork.

License

Copyright Eric Mika, 2010–2023 Licensed under the GNU Lesser General Public License.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.