Playing the Dino Game Using Brainwaves

Nora Zajzon
4 min readJan 17, 2021

If you have ever experienced a power outage, you are bound to come across the chrome dinosaur game. As you aimlessly press the space bar continuing to break your record, one becomes a master at the simple game. After a while, you begin to imagine playing this game with just your imagination. This farfetched dream is actually more plausable that one would think. With the use of a BCI, a user could play the game with just the blink of an eye.

Hardware

The Muse 2 EEG headband is traditionally a meditation device which uses brainwaves to determine the user’s calmness levels. The BCI has five sensors that offers access to the waves produced by blinking and more.

I will be using the sensors A7 as displayed in the image

I used the A7 sensor to monitor the movement of the left eyelid; it would indicate whether the left eye blinked or not.

Code

In order to use the Dinosaur game, I modified a Github repository to simulate the key event of pressing space bar by blinking your left eye. The JavaScript SDK that allowed me to read the EEG signal streamed by the headband is called Muse-JS. I also had to download install the JavaScript package dependency manager called Yarn. I then created a folder to unzip “Muse-JS”; I will refer to this folder as “muse-js”. To start the muse-js sample program (once you have yarn installed), in a command prompt on Windows or Terminal on the Mac in the directory you unzipped muse-js, execute: yarn then yarn start.

Now that the muse-js server is running on your computer and waiting for requests on the default port of 4445, in a Chrome tab type: http://localhost:4445/ . Turn on your Muse headband and click Connect! It should detect your device, something like Muse-9134. If you select and click “Pair”, it should start plotting the data the headband is streaming on graphs, one for each electrode. If your headband is correctly positioned, a quick test should show a steady signal on Electrode2 (channel ‘AF7’) when flinching your left eye.

Integrate the dino game into the muse-js application:

1. Copy over the scripts and assets files used by the dino game located in the muse-js/demo/src folder: everything from “assets” folder, the “index.css” and “index.js” files. Also, copy them to the muse-js/demo/dist folder (You can learn about the roles of the “src” and “dist” folders in JavaScript applications on the web).

2. Modify the muse-js/demo/src/index.html to include the game portion: Include the style sheet and script

3. Add the div elements “messageBox” and “main-frame-error”

4. copy the script after the body element (to hide button when Space bar is pressed)

5. Modify the game to have the dino jump triggered not only by pressing the Space bar but when you flinch your left eye. In order to do this, we will check the data being plotted on Electrode2 (AF7 channel) in the function
function plot(reading: EEGReading) in “\muse_js\demo\src\main.ts”.

The value 8 is empirical determined by the fact that anything below that is just noise

After hours of tweaking code and messing around with the headband, I came to many personal conclusions.

I found connecting the Muse headband directly to the computer (Windows or Mac) from the operating system’s bluetooth support doesn’t work. Some people online recommended using a bluetooth dongle. I purchased one of the recommended dongles, but it didn’t make a difference. My recommandation is to not waste your money on it.

While the company Muse no longer supports an official Software Development Kit (I contacted their support but they cannot help with development problems), there’s number of open sourced SDKs in various github repositories that can successfully pair the headband with your computer.
The ones I tried and worked are:
https://sites.google.com/a/interaxon.ca/muse-developer-site/developer-faq
https://github.com/alexandrebarachant/muse-lsl
https://github.com/kowalej/BlueMuse
https://github.com/urish/muse-js

The most important criteria for selecting an SDK depends on the type of application or game you want to integrate Muse with. While most people seem to be using the Python SDK, I chose the muse-js package, which is easy to use and is based on Web Bluetooth that works well on Chrome, since my application was in JavaScript.

Summary

It was an interesting experience to realize that you can indeed control things with EEG signals. Despite the struggle of finding a working SDK which is compatible with the headband, the results of the hours of work are incredibly entertaining!

Playing my dino game by blinking!

If you enjoyed this article, please leave a clap! Reach out to me at my LinkedIn.

--

--