Applying EEG Data to Machine Learning, Part 1
Use a consumer-grade EEG device to control and manipulate a simple video game by using TinyML.
Created By: Thomas Vikstrom
The objective of this tutorial is to show how you, by using a Muse EEG-device, can control a simple Pong game just by blinking your eyes.

As a gentle introduction to the concept of human and machine communication, the first part shows how to use Muse's built-in blink detection functionality and the second part shows how you can use Machine Learning (ML) with Edge Impulse (EI) to be able to expand the game. And while this is just playing a simple game by blinking, there is a lot happening in the area of connecting brain and machine. Research in BCI-technology (Brain Computer Interface) has enabled tasks earlier believed impossible to become reality. One example of this is when patients suffering from ALS had a brain implant inserted into a blood vessel in their brains, and after some training were able to communicate e.g. through WhatsApp messages.
Once you understand the benefits and limitations of using EEG-data from a consumer-based device, you can yourself step up and try to control external devices like robots by using eye-blinks or perhaps even by thinking!

Electroencephalography, or EEG, is a method to record the electrical activity generated by the brain via electrodes placed on the scalp surface. More detailed information is found e.g. from (Farnsworth, 2021) or from Wikipedia.
Professional or clinical EEG-devices are typically equipped with between 16 to 64 high-quality electrodes, and the cost is ~800 - 3000+ USD/EUR. They are mostly intended for research and clinical usage. Consumer-based devices on the other hand have only a few electrodes, but are much more affordable and are often also easier to use. Their main focus is on meditation and relaxation, but can with some limitations also be used for research (more about this in my Master's thesis).

Muse EEG-devices are focused on consumers and they have four EEG-electrodes, two at the forehead, two behind the ears. In addition they also have an accelerometer/gyroscope, and newer models include a PPG-sensor which measures blood flow, breathing rhythm, and heart rate. In this tutorial however are only signals from EEG-electrodes being used.
To be able to reproduce examples found in this tutorial, you'll need:
- A Muse EEG-device, any model should work, although Muse-01 (from 2014) streams with 220 Hz instead of 256 Hz and might require a few code changes if you are collecting raw data. They cost around 250 USD/EUR and are manufactured by the Canadian company Interaxon Inc.​
- iPhone or Android phone
- A computer able to run Python + WiFi
- only PC/Win10 tested although Mac and Linux computers are expected to work
- Python 3.x
The data flow for both Part 1 and Part 2 is: Your brain → Muse → Bluetooth → Phone/Mind Monitor → WiFi → Computer
Python modules
- Install Python-OSC and Tkinter from a command prompt with
pip install python-osc
andpip install tk
- For Part 2 you'll also need Tensorflow, install it with
pip install tensorflow
Mind Monitor settings
OSC Stream Target IP
: here you should add your computer's local IP-address, on Win10 you can runipconfig
in a command prompt to find it, often starts with 192.168.x.xOSC Stream Port
: set to5000
Computer
- You might need to allow the computer's firewall to allow traffic through port 5000.

In this first part you will learn how to control a Pong game just by blinking your eyes. A short video of the Pong game is available here.
As mentioned earlier, this version is not using machine learning at all. Instead it is relying on built-in functionality in the Muse EEG-devices that can detect eye blinks and jaw clenches. These events produce distinct EEG-signals which can also be seen in the Mind Monitor graphs. The Pong game is then scanning for the events and reacting on them.
- Run the game from your favourite IDE or from the command prompt with
python "Blink Pong without ML.py"
In short, you will here need to collect EEG-data (blinks and non-blinks) from your Muse device, and train a ML model in Edge Impulse. The trained model will then be used in the Pong game which otherwise functions as in Part 1.
While this is not as complex as brain surgery (