DEV Community

Cover image for Using 🧠 BrainFlow with the Neurosity headset
Alex Castillo for Neurosity

Posted on • Updated on

Using 🧠 BrainFlow with the Neurosity headset

The Neurosity OS features a full JavaScript SDK for web apps. But what if you want to use other awesome programming languages to get brainwaves?

Enter BrainFlow.

BrainFlow is multi-purpose biosensor library that provides a uniform data acquisition API for many devices.

You can use BrainFlow in Python, Java, C#, C++, R, Matlab, and Julia.

BrainFlow is ideal for:

  • Research
  • Unity Integration
  • Unreal Engine Integration
  • Neuroscience Experiments

Enabling BrainFlow

1) Open Neurosity's Developer Console
2) Go to Settings by clicking the ⚙️ gear icon next to your device's name
3) Enable Open Sound Control (OSC)

Alt Text

The OS running on your Neurosity device is now streaming data to BrainFlow via OSC.

We recommend disabling OSC if you are not using BrainFlow as it will consume extra battery life.

Installing BrainFlow

In this example we'll use Python 3 to work with BrainFlow.

Install the latest release from PYPI with the following command in terminal:

python -m pip install brainflow
Enter fullscreen mode Exit fullscreen mode

📖 For installation instruction for other languages, please visit the BrainFlow docs.

Getting real-time brainwaves

Next, create a new file called brainflow-test.py and add the following snippet to it:

import brainflow

from brainflow import BoardIds
from brainflow.board_shim import BoardShim, BrainFlowInputParams
from brainflow.data_filter import DataFilter, FilterTypes, AggOperations

def main ():
    board_id = BoardIds.CROWN_BOARD.value # or BoardIds.NOTION_2_BOARD.value or BoardIds.NOTION_1_BOARD.value
    params = BrainFlowInputParams ()
    params.board_id = board_id
    BoardShim.enable_dev_board_logger ()
    board = BoardShim (board_id, params)
    board.prepare_session ()
    board.start_stream ()
    data = board.get_board_data ()
    board.stop_stream ()
    board.release_session ()

    print (data)

if __name__ == "__main__":
    main ()
Enter fullscreen mode Exit fullscreen mode

Run the code via terminal.

python3 brainflow-test.py
Enter fullscreen mode Exit fullscreen mode

And finally, you should see the data in the terminal.

...
 [-2.27709781e+05 -2.27785156e+05 -2.27140344e+05 -2.26998656e+05
  -2.27617781e+05 -2.27845906e+05 -2.27248578e+05 -2.26956891e+05
  -2.27517125e+05 -2.27874938e+05 -2.27355188e+05 -2.26924359e+05
  -2.27395156e+05 -2.27880234e+05 -2.27474953e+05 -2.26928188e+05
  -2.27283438e+05 -2.27850938e+05 -2.27579297e+05 -2.26961781e+05
  -2.27188766e+05 -2.27806875e+05 -2.27681078e+05 -2.27022875e+05
  -2.27094812e+05]
 [-3.49463312e+05 -3.49478594e+05 -3.49025500e+05 -3.48958906e+05
  -3.49402500e+05 -3.49527812e+05 -3.49097719e+05 -3.48925125e+05
  -3.49332969e+05 -3.49551812e+05 -3.49167250e+05 -3.48893688e+05
  -3.49243031e+05 -3.49560875e+05 -3.49251094e+05 -3.48890188e+05
  -3.49161750e+05 -3.49542906e+05 -3.49322031e+05 -3.48906938e+05
  -3.49094312e+05 -3.49517031e+05 -3.49395438e+05 -3.48944156e+05
  -3.49023562e+05]
Enter fullscreen mode Exit fullscreen mode

📖 For other Python code examples like writing to a file, data transforms, and signal filtering, check out these examples.

Gotchas

Some Windows 10 users reported the following error.

brainflow.board_shim.BrainFlowError: BOARD_NOT_READY_ERROR:7 unable to start streaming session
Enter fullscreen mode Exit fullscreen mode

If this is the case for you, try disabling your firewall, and try again.

EEG Notebooks

Alt Text

The amazing EEG Notebooks project by the NeuroTechX community now supports the Neurosity Crown device via BrainFlow.

EEG-Notebooks is a collection of classic EEG experiments, implemented in Python 3 and Jupyter notebooks. The goal is to make cognitive neuroscience and neurotechnology more accessible, affordable, and scalable.

With EEG Notebooks you can explore BCI methods such as Visual N170, P300, SSVEP, and more.

Give it a try!

GitHub logo NeuroTechX / eeg-notebooks

A collection of classic EEG experiments implemented with Python and Jupyter notebooks

Top comments (1)

Collapse
 
twabi profile image
Ahmed twabi

Nice one. Save to say, it would have been even greater if you explained the setup on the connection between the laptop and Crown headset, e.g. they have to be on the same wifi network. Also, a small distinction in installation if you were running it on the raspberry pi for example. Overrall still decent.