Skip to content

Control Chrome's T-rex game with a BCI headset streaming EEG data through a LSL server

Notifications You must be signed in to change notification settings

rameerez/brain-controlled-game

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain-controlled game

Game controlled via a Brain-Computer Interface (BCI).

Blinking fires the spacebar keydown event.

Based on urish/t-rex-brainer but modified so it can also ingest data from an EEG LSL server.

Game screenshot

Instructions

0. LSL Server

First of all, you need to have a LSL server streaming EEG data. Use Notebook 3a from the Brain-Computer Interfacing Bootcamp Course repo to start up a mock LSL server that streams EEG data from a dataset.

1. Get the code

Start by cloning this repo

git clone https://github.com/rameerez/brain-controlled-game.git

And then cd into it

cd brain-controlled-game

2. Start up the client web server

Let's first display the actual game window.

Install dependencies

npm install
npm install -g live-server

And start up the web server

live-server

3. Start up the Python event server

Now, we need a Python flask server that sends events to the game web window. The goal of this "event server" is to read EEG data from a LSL streaming and fire events when it detects the right artifacts.

Open up a new console, cd into the project folder and then cd into the Python server folder

cd python_event_server

Install dependencies

pip install flask flask-sse redis gunicorn gevent mne
pip install https://api.github.com/repos/mne-tools/mne-realtime/zipball/master

Now, we need Redis to allow the Python server message system to work. Install and run redis on your machine:

Redis on macOS

brew install redis

And then run the local redis server

redis-server /usr/local/etc/redis.conf

Redis on Windows

Download the Latest release compiled version of Redis: https://github.com/microsoftarchive/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip

Uncompress the .zip file and execute redis-server.exe

A black terminal screen with the Redis logo should pop up indicating that a local server of Redis is now up and running.

Redis on Linux

// TODO search for redis installation instructions on Linux


Once Redis is installed and running, fire up the Python event server:

gunicorn main:app --worker-class gevent --bind 127.0.0.1:50005

And everything should be set up now.

Issue on Windows

On Windows systems, the above line throws a ImportError: No module named fcntl error. This is because gunicorn relies on fcntl, which is a Linux-only library and thus not available on Windows. An (untested) workaround might be using a mock fcntl module as described here: https://stackoverflow.com/a/25471508/2565681

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 70.3%
  • HTML 25.9%
  • CSS 2.0%
  • Python 1.8%