Using BrainFlow with OpenBCI EEG recorder on a Raspberry Pi

Thanasis Koutras
5 min readApr 4, 2022
Photo by Milad Fakurian on Unsplash

OpenBCI is a company with a mission to create open-source tools for biosensing and neuroscience. Two of the company’s great projects that have drawn the attention of many researchers as well as a lot of biosensing enthousiasts, are the Cyton (with 8 / 16 EEG channels) as well as its smaller brother the Ganglion board (with 4 EEG channels). One of the greatest advantages that has made both of these boards so popular, is the open source philosophy that makes brain signals available for processing to anyone using tools written in different languages.

OpenBCI-GUI, the standalone Graphical User Interface, is an open source software tool available for various operating systems and platforms including Windows, Linux, Mac. It is the easiest and fastest way to connect the OpenBCI hardware, visualize the physiological data (whether EEG or EMG), and stream it to other applications and tools for further analysis.

In this article, I would like to present a complete way of setting up both OpenBCI boards and connect them to a Raspberry Pi 3(model B+). The purpose of this setup is part of an ongoing project that I’m running, that involves recording and analysis of my brain signals during sleep. For this purpose, I wanted to make a more “compact” and light recording setup that uses a small and power efficient computer together with the OpenBCI board. This article presents the use of Cyton and Ganglion with a Raspberry Pi 3B+, however the same can be applied if the most recent and efficient Raspberry Pi 4 is to be used.

A quick search in various online sources, revealed a great number of different methods that can be used to record EEG signals, most of them relying on the OpenBCI GUI — a program that uses the Processing language. Unfortunately, I didn’t have any luck when I tried to make the OpenBCI GUI to run on my Raspberry Pi board, as it is rather tricky and involves many complicated steps, from installing Processing (that was the easy part), to compiling the GUI and running it without error. The later was something that took me much more time than I wanted, so I decided to explore different and more simple (and light-weight) solutions. And that’s when BrainFlow came into my attention.

From the Brainflow site we read:

Brainflow is a library intended to obtain, parse and analyze EEG, EMG, ECG and other kinds of data from biosensors. It provides a uniform data acquisition API for all supported boards, it means that you can switch boards without any changes in code and applications on top of BrainFlow are board agnostic. Also there is powerful API to perform signal processing which you can use even without BCI headset. Both of these two APIs are the same across bindings.

Brainflow supports a great number of boards including the Cyton and the Ganglion boards, among others. It can be used on machines with different operating systems (Windows, Mac, Linux) and the most important for my case, the Raspberry Pi board! In the site, you can find pre-compiled libraries, but if you want to use it with the Raspberry Pi, you’ll have to compile it by yourself.

Installing BrainFlow on Raspberry Pi

Using Raspberry Pi, we head to the Brainflow project’s github page and clone the repo:

$ git clone https://github.com/brainflow-dev/brainflow.git

I’m mainly interested in using Brainflow in python, however we need to first compile the core module using build.py and avoid the CMake hassle in Raspberry Pi.

$ python3 -m pip install cmake
$ cd tools
$ python3 build.py
# to get info about args and configure your build you can run
python3 build.py --help

After that, the installation of the python packages follows, a matter of using only the two following commands:

$ cd python-package
$ python -m pip install -U .

Connecting the OpenBCI Cyton

To connect the OpenBCI Cyton board, we attach the USB dongle to the Raspberry Pi and check the serial port where it is connected. In my case, it is the /dev/ttyUSB0 port, chances are that this may be the same for yours too. In order to check and see if all went well with the installation, we head to the python directory, in the examples section and run the test program that plots the signals that are acquired by the board in real time: (note that board-id is 0 for the Cyton board)

$ cd python-package/examples/plot-real-time/
$ python plot_real_time.py --board-id 0 --serial-port /dev/ttyUSB0

and voilà! We have a lift off! Of course, the signals shown in the picture are not by any means anything like brain signals, rather some noise generated by brushing my fingers to the pins of the board. (Real brain activity needs to wait for a little bit longer)

Getting data from OpenBCI Cyton on a Raspberry Pi 3

Connecting the OpenBCI Ganglion

Next I wanted to test the Ganglion board. I plugged the Bluetooth v4.0, Low Energy (BLE) Smart Dongle and checked the successful recognition using the hcitool command:

pi@raspberrypi:~/EEG_Research/brainflow $ hcitool dev
Devices:
hci0 B8:27:EB:1E:70:1F

Additionally, the lsusb command shows the bus and the device ID of my BLED112 dongle:

Bus 001 Device 014: ID 2458:0001 Bluegiga Technologis BLED112 Bluetooth 4.0 Single Mode Dongle

while in the /dev directory we can see the port that was recognized by the system (that will be used later to connect to the Ganglion board).

crw-rw — — 1 root dialout 166, 0 Apr 4 18:00 /dev/ttyACM0

In the same manner as previously, we run the test program changing only the board-id from 0 (Cyton) to 1 (Ganglion)

$ python plot_real_time_min.py — board-id 1 — serial-port /dev/ttyACM0

and again, success! Four noisy signals generated by me are presented in the BrainFlow Plot Window in all their glory!

Getting data from OpenBCI Ganglion on a Raspberry Pi 3

Conclusion

This concludes this article that describes the installation of Brainflow on a RaspberryPi 3 board for use with the OpenBCI Cyton or Ganglion boards. The installation is very straight forward, easy, fast and lightweight and saves us from all the heavy load of running OpenBCI GUI from Processing (something that couldn’t be accomplished by me).

If you found this article useful, drop me a comment. If you had any trouble setting up your Brainflow + OpenBCI board, please feel free to comment!

Until the next time!

--

--

Thanasis Koutras

Trying and playing around with all kinds of gadgets that get into my hands. Researcher as well as biosensing enthousiast.