This post is the second in a series aimed at documenting the process behind making a functional BCI at low-cost and with minimal experience. If you haven’t done so, I’d recommend first reading my introductory post about this series that details the materials and costs for the project and my first post that details the hacking process of the Mindflex headset that used as the EEG device.
The Agenda
- Build the Hardware interface for Data Collection
- What you need:
- Breadboard ( I use the mini 170 tie-points breadboard)
- Passive Buzzer
- Tactile Button
- 100 ohm resistor
- Wires
- 2 Crocodile clips / Long wires
- Hacked Mindflex Headset
- What you need:
- Program the Hardware Interface to collect data
- What you need:
- Arduino IDE
- What you need:
- Build the Software required to collect data
- What you need:
- Python and an appropriate IDE (I use Visual Studio Code)
- What you need:
Step 1: The Prep
Assuming you’ve read the previous post, you should be all prepped up with the necessary hardware, software, and installations for this phase of building our BCI. If not, navigate back to that post to install the Arduino IDE, Python, a suitable IDE for Python, necessary Arduino libraries, and make a suitably hacked Mindflex headset.
Step 2: Define Data Collection Methodology
To start data collection, even before we set up our hardware interface, we need to define the scope of the data we need to collect and that means knowing what the data will be used for. In our case, the data is going to be used to train a Neural Network classifier through backward propagation. As such, what we need is EEG data which is either labelled ‘Not Mind Wandering’ or ‘Mind Wandering’. What should be considered Mind Wandering? What task should we choose to monitor mind wandering from? How can we, in the future, label collected data as Mind Wandering or not? These are the questions we need to answer while framing our experimental set-up.
I started by reviewing some research papers that attempt to quantify/qualify Mind Wandering from EEG signals. These three in particular offered the greatest inspiration in framing my methodology:
- Baldwin, C. L., Roberts, D. M., Barragan, D., Lee, J. D., Lerner, N., & Higgins, J. S. (2017). Detecting and Quantifying Mind Wandering during Simulated Driving. Frontiers in Human Neuroscience, 11. https://doi.org/10.3389/fnhum.2017.00406
- Rodriguez‐Larios, J., & Alaerts, K. (2020). EEG alpha–theta dynamics during mind wandering in the context of breath focus meditation: An experience sampling approach with novice meditation practitioners. European Journal of Neuroscience, 53(6), 1855–1868. https://doi.org/10.1111/ejn.15073
- Braboszcz, C., & Delorme, A. (2011). Lost in thoughts: Neural markers of low alertness during mind wandering. NeuroImage, 54(4), 3040–3047. https://doi.org/10.1016/j.neuroimage.2010.10.008
Final Methodology
The overall task I used was a simulated driving environment (i.e. watch a youtube highway dashboard video: https://www.youtube.com/watch?v=eoXguTDnnHM ). I defined, inspired by other empirical papers, mind wandering episodes as being events where I thought about something not directly related to the task (i.e. thinking about what I ate for lunch while ‘driving’). When I would catch myself wandering, I pressed a button on the Data Collection Module that would indicate in the data collected that I’d been Mind Wandering before. To catch Mind Wandering episodes that could go unnoticed by me, I programmed a buzzer on the Data Collection Module to buzz at random intervals (between 60 and 120 seconds) that would probe me to check if I was Mind Wandering. I collected data for 15 minutes at a time: i.e. each data collection duration was 15 minutes (but were concatenated together to make one whole data set for training the neural network).
This is the overall general set up:
Side Note: I found that the signal strength can be improved quite tremendously with some DIY Electrode gel (basically salt + any form of gel/liquid like water or aloevera gel – I used aloe vera gel). Just apply a little onto the electrodes and you should be able to get 0 or near 0 signal strength (200 being the worst and 0 being the best)
Step 3: Building the Hardware Interface
Now that we know what to do, we’ve got to figure out how to do it. As far as the hardware interface of the Data Collection Module goes, it is pretty simple: the main parts required are just a buzzer, button, and the Mindflex headset. Here’s how I put it all together:
- Attach crocodile clips(or any long enough wire that can reach from your head to a table) to the wires soldered onto the Mindflex. Attach the other end of the crocodile clips to another set of jumper wires and plug them into the GRN and RX(0) terminals of the Arduino.
2. Place a buzzer, a 100 ohm resistor, a tactile button, and three wires (preferably color coded) in the following format on the breadboard.
Note that all the columns of the breadboard are soldered together (i.e. they are electrically connected). So, one end of the resistor is connected by to the positive terminal of the buzzer. The negative terminal of the buzzer is connected to one end of the button. There are three wires connecting the breadboard to the Arduino. The orange one connects the buzzer to the Arduino, the red does so for the button, and the black connects the negative terminals of both components to the ground terminal of the Arduino.
Tips:
- I trimmed the ends of the resistor by a bit using a common kitchen knife to lie the resistor flush on the surface of teh breadboard.
3. Connect the Buzzer wire (orange) to terminal 10 of the Arduino, Button wire (red) to terminal 9 and the ground wire (black) to the ground terminal. Now we can send and receive electrical signals between the Arduino and the breadboard components.
Step 4: Programming the hardware
Now we can start programming the hardware using the Arduino IDE (language based on C++). For those unfamiliar with Arduino programming the following videos should give you a good enough intuition to understand at least this project:
The SUPER Basics:
The best series on youtube to learn using an Arduino (and how I learnt to work with Arduinos):
You can find and download my Data Collection Module Arduino code here: https://github.com/JoshetaSrinivasan/DistractedDrivingDetect/blob/main/MindWanderDataCollect.ino. I’ve tried to make it well documented enough with plenty of comments so you know what code is doing but here is a video walkthrough neverthless:
When you run this code, you should be able to see the serial monitor spit out the EEG data or EEG data + ‘*’ if the button is not pressed or pressed respectively.
Step 5: Finding a way to store the data
Now that we have the required data being spit out from the serial monitor, we need to store this somehow to be able analyze it in the future. I did this by running a python script that converts the Serial Monitor output to a CSV(comma-seperated values) file where each line contains a series of data separated by commas (note that this is exactly the format that our Serial monitor output is in – and by no coincidence).
You can find that python script here: https://github.com/JoshetaSrinivasan/DistractedDrivingDetect/blob/main/EEGdata_mindWander.py. As before, I’ve documented as much as possible and I’ve also made a video walkthrough:
Step 6: Have fun collecting Data!
Now it’s time to collect data. Set-up your data collection space, run the python script, and collect data!
Here’s a demonstration of how exactly you can go about collecting data with the codes that I have created:
AND
Here’s a sample time-lapse of me collecting data:
What next?
Next up is processing the data we collect and training a Neural Network to classify Mind Wandering. See you there!
Comments are closed