Useful (?) Code to share - brainflow on the Raspberry Pi wearable system
grahambriggs
Corvallis
I am not a neuroscientist, nor do I play one on TV. I am a software engineer who loves to learn new technology and hack around on cool projects in his spare time.
I recently had the opportunity to begin playing with the Open BCI Cyton biosensing board, and I learned a few basic things about brain wave scanning. I also developed a bunch of software for reading data from the board and doing some simple signal filtering and band power detection data processing. The software system was designed to run on the Raspberry Pi, but it also works on Windows.
My goal was to build a self contained wearable brain scanning system to participate in a company sponsored hack-a-thon. We went on to build this BCI Hard Hat

The system includes a blink detector to send commands to control another piece of software (and trigger some cool LEDs on the hat), plus an Alpha wave detector that triggered a haptic feedback motor in the hard hat (because of course you should not get too relaxed on any job site that requires a hard hat
.

Although it made for a cool hack-a-thon project, there is not really much that is practical about a BCI hard hat. Also, as you would expect, cramming all those electronics so close to the EEG sensors did increase the noise a bit.
However, the code we developed for this project might be useful to you. For example, if you are trying to develop a more practical wearable system, or maybe your PC in the lab is not conveniently located to where your test subjects are wearing the headgear and you want to have a low cost Raspberry Pi close to the test subject and broadcast raw data on any number of PC's connected to the same LAN.
In case it is useful to anyone else, you are welcome to check it out the code here:
https://github.com/GrahamBriggs/bcibeginner
Here is a system diagram:

Along with some basic data processing and playing around with blink and alpha wave detection, the brainHatClient program is also capable of recording data files.
Enter a root name for your test series, and tap the [Start Recording] button.

A .txt file in OpenBCI format will be saved in a folder on your desktop. You can view and analyze these files using the OpenBCI_GUI software.

You can find more details about this system in this document we published:
brainHat System Description
If anyone is interested to learn more about this system, I would love to hear from you. Maybe I can help you with some software development if you can help me learn more about processing and understanding BCI raw data.
Thanks for reading
GB
Comments
Wow! At first glance, this looks really cool!
If this project is mostly completed, I would also recommend creating a Community post here: https://openbci.com/community
RW
Thank you. I am still polishing and testing a few things before this project is wrinkle free, but when it is a bit more refined I will consider a post on the community as well.
can this be implemented with ganglion board ?
Thanks for making a new forum post here
https://openbci.com/forum/index.php?p=/discussion/2772/how-to-connect-my-ganglion-to-the-raspberry-pi#latest
@Khaled I like this idea, since it could make the whole helmet/system cheaper! Also, might be difficult to fit the Ganglion+WiFi Shield (currently not in production) into the helmet. The cool part about using the Raspberry PI in this project is that maybe some edge computing and initial processing can be done before sending data to a master server/computer.
I'm sure it would be a massive project, but maybe this could act as an IoT device. Multiple workers at a job site wear this, and data is uploaded to a private cloud infrastructure in real-time (might be expensive). Then, analysis scripts look for [insert behavior here] and provides a real-time report to supervisor to ensure that workers are being safe.
Example: Detect anger or severe stress from employee(s) who are not nearby. Supervisor becomes aware and steps in to help de-escalate.
Khaled
Today the software has several parts that are hard coded for the Cyton 8 channel. This was done to cut corners and get our first project done. I do plan to continue working on the software. One of my next tasks will be to make the interfaces for the data more generic, with the goal of supporting the different OpenBCI boards. I will update this post where there is new code to share in the coming weeks.
Thank you for your interest.
GB