Simple parser for Mindwave Mobile EEG headsets.
This is a fork from orgicus master branch: https://github.com/orgicus/Mindwave
The new version includes now also eye blink detection!
- Download the library
- Unzip Mindwave-master.zip and rename the Mindwave-master folder to Mindwave
- Move the freshly renamed Mindwave folder into the Documents/Arduino/libraries and restart Arduino
Alternatively, you can simply copy the two files "Mindwave.h" and "Mindwave.cpp" to your sketch folder.
If you're using the Serial class and simply want to get the attention/meditation values, it's as simple as shown below.
The example includes also eye blink detection. Single and double blink detection is implemented.
In the example a HC-05 Bluetooth module is connected to Serial2 on an ESP32. But it should work for all Arduino/ESP boards using the Serial class.
Here is explained how to prepare the HC-05 for connecting to the headset.
#include "Arduino.h"
#include "Mindwave.h"
Mindwave mindwave;
void setup() {
Serial.begin(115200);
Serial.println("Start");
Serial2.begin(MINDWAVE_BAUDRATE);
}
void onMindwaveBlink() {
if (mindwave.blink() == 1) {
Serial.println();
Serial.println("Single Blink!");
Serial.println();
}
if (mindwave.blink() == 2) {
Serial.println();
Serial.println("Double Blink!");
Serial.println();
}
}
void onMindwaveData() {
Serial.print("Quality: ");
Serial.println(mindwave.quality());
Serial.print("Attention: ");
Serial.println(mindwave.attention());
Serial.print("Meditation: ");
Serial.println(mindwave.meditation());
Serial.println();
}
void loop() {
//mindwave.update(Serial2, onMindwaveData); // This works without blink detection
mindwave.update(Serial2, onMindwaveData, onMindwaveBlink); // This with blink detection. onMindwaveBlink is an optional parameter.
}
For more examples go to Arduino > File > Examples > Mindwave
The code is mostly based on the official NeuroSky wiki article and the ThinkGear protocol specs
Blink detection is based on the code shown here: orgicus#5