MI and ME-BCI Training with OpenBCI

MI-BCI training is based on visuo-motor imagination and together with other mental task imagination (e.g. mental subtraction, word association) is the only paradigm of endogenous nature that does not require external stimulation but only the user’s imaginative action. In addition, MI is considered the most importan type of BCI paradigm for motor function restoration. Results from different studies have proven mental practise of action to be useful in MI-BCI, and have shown beneficial effects of motor imagery practise during stroke recovery. Unfortunately, an estimated 15-30% of people cannot use a BCI system, resulting in a big amount of BCI illiteracy in the user base.

This post covers how to implement a MI-BCI training with OpenBCI 32bit Board by adding two external buttons to the board, adding extra features to the Processing code, and rewrite the OpenBCI Board code.

Figure 1. Overview of the OpenBCI 32 bit Headset with two external buttons attached in it ready to start MI-BCI training.


Motor imagery has become the newest trend in BCI research since imagination of movements appears to recruit neural mechanisms in the brain, which are similar – or the same – to those used to perform the same movements. However, the question of whether similar functional connectivity patterns among recruited brain areas associated with both real and imagined movements exist has been less addressed in the BCI frame.

For a better understanding of brain correlates of real and imagined movements, in the present work, we investigated the spatiotemporal EEG brain activity during a real and an imaginary rhythmic finger-tapping task. Repetitive finger movements externally paced by auditory or visual cues have been studied to investigate cortical connectivity, sensorimotor coordination. Moreover, in the frame of BCI research, repetitive finger and hand movements, real and imagined one, where used to extract characteristic features that serve as inputs for the detection of the intention of movement. These features include lateralized patterns of power decrease and an increase in the alpha and beta frequency bands.

It is widely accepted that while brain processes certain events, the ongoing brain rhythmical activity can be blocked or desynchronized. These types of changes are better detected by frequency analysis because they represent frequency-specific changes of the ongoing EEG activity. They consist, in general of a power decrease (event-related desynchronization, ERD) and of a power enhancement (event-related synchronization, ERS) of certain frequency bands. This is considered to be due to a decrease or an increase in synchrony of the underlying neuronal populations, respectively.

The evolution of ERD and ERS patterns for both actual and imagined movements is calculated by averaging the energy distributions of EEG single trials at each time instant in the time-frequency domain. We focused on the detection of beta rhythms and associated ERD/ERS patterns, previously described to occur with initiation and execution of motor actions as well as with motor imagination. Discrimination of short time activations during motor imagery based on the frequency content may improve decision-making and enhance the performance of a BCI system.


The aim of the present training is to investigate the cortical activation and connectivity sub-serving real and imaginary rhythmic finger tapping, from the analysis of multi-channel electroencephalogram (EEG) scalp recordings. Several studies in Motor Imagery involving finger tapping showed a similar methodology, emphasizing three short-period of time: focus, cue, and rest.

The experiment involves two tasks of simple limb motor imagery (left hand, right hand). The simultaneous imagination of different limbs contributes to the activation of larger cortical areas as well as two estimated sources located at corresponding motor areas within beta rhythm.

Figure 2. Graphic of the experiment for Motor Imagery (MI) and Motor Execution (ME) training.

Every trial is 10 seconds time long, and it’s composed by different status:

  • Ready: The first second of each trial command shows up an alarm
  • Focus: The following three seconds are based on a countdown before the cue, just to let the subject prepare himself for what is coming.
  • Cue: It’s only four seconds long, and it shows the cue that has to be done in the trial. In each trial the cue is different. This is the non-random version, which means that the cues appear in the following order:
Move right finger
Move left finger 
Imagine moving right finger 
Imagine moving left finger
  • Rest: The subject has two seconds to rest between trials.


OpenBCI EEG Headset

Whatever OpenBCI EEG Headset version that you have will work. Personally, I use the Ultracortex Mark III “Supernova”. You can read more information in this post.


Electrodes position

Electrodes are placed over the motor and somatosensory cortices. Reference and ground electrodes are at the left and right ear lobes, respectively.

Figure X. “Supernova” Electrode configuration based on the 10-20 system.

Two external buttons

Breadboards Connection

Sometimes, when studying EEG or other biopotential signals, you will want to have precise timing between external events or stimulus and the data stream. Indeed, motor imagery based brain-computer interface (BCI) translates the subject’s motor intention into a control signal through real-time detection of characteristic EEG spatial distributions corresponding to the motor imagination of different body parts. In this case, it is necessary to know the exact time that an external input has been presented to the subject to look for the tell-tale brain wave that happens about 400ms after the stimulus. Moreover, if you want to distinguish between right and left movements while you are studying motor imagery or motor execution, you better pay attention to the following steps.

Figure 6. The connection of the wires in the two buttons.

Connection (OpenBCI 32bit Board)

Another post from this blog explains how to implement and add two external buttons to the OpenBCI 32bit Board, and how to connect the two external buttons to the correct pins in the OpenBCI 32bit board.

Figure 7. The connection of the wires in the OpenBCI 32bit Board.


Edit OpenBCI GUI

On the top-right of the image, the Playground tab appears showing the time of each trial, the number of trial you are, and all the commands related with start/stop experiment.

Figure 8. Screenshot of the OpenBCI GUI while the experiment is taking place.

In the figure above you can see with more detail, the methodology showed in Playground tab in OpenBCI GUI.

Upload new code to OpenBCI board

You need to upload the new code to the OpenBCI 32bit board in order to get the information of each trial, and everytime the two buttons are pressed.

Figure 9. Screenshot of the OpenBCI 32bit board code in Arduino.


[1] “Evaluation of EEG Oscillatory Patterns and Cognitive Process during Simple and Compound Limb Motor Imagery”, Weibo Yi , Shuang Qiu , Kun Wang, Hongzhi Qi  Lixin Zhang, Peng Zhou, Feng He, and Dong Ming. Published: December 9, 2014. http://dx.doi.org/10.1371/journal.pone.0114853

[2] “EEG feature comparison and classification of simple and compound limb motor imagery”, Weibo YiShuang QiuHongzhi Q, Lixin ZhangBaikun Wan and Dong Ming. Journal of NeuroEngineering and Rehabilitation 2013 10:106, DOI: 10.1186/1743-0003-10-106, ©  Yi et al.; licensee BioMed Central Ltd. 2013.

[3] “The Study of Object-Oriented Motor Imagery Based on EEG Suppression”, Lili Li, Jing Wang, Guanghua Xu, Min Li, and Jun Xie. Published: December 7, 2015.  http://dx.doi.org/10.1371/journal.pone.0144256

[4] Thesis: “EEG-based Brain Computer Interfaces (BCIs): An investigation of motor imagery for assistive devices” by Hina Mistry.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s