Introduction
For this project, I wanted to work on creating a device and a GUI that are fairly cheap and easy to use to conduct neuroscience projects. When I was working for my bachelor's senior design project, I was using a BCI from the lab that cost more than 1000 dollars, the set up time required few minutes, we had to put gel to increase quality of the signal on the electrodes, and it has been really hard to install a GUI (OpenVibe) on the Raspberry Pi4 to collect data and perform Machine Learning.
This projects uses ESP32 to transmit data in real-time from a micro-controller (Huzzah32 feather board) to a Raspberry Pi4. The Huzzah32 has an ADC of 12bit resolution so it is NOT (sorry for the typo, it is actually needed a 24-bit resolution) suitable for advanced neuroscience projects. I wanted to use the ADS1299 which has a 24bit resolution and it is very popular among commercialize portable BCI especially because it has features like a low-noise PGA, integrated bias voltage generation, and lead-off detection circuits, which help in achieving low-noise performance in biomedical signal acquisition. The shipment time on Digikey was 26 weeks so not enough time for this competition. I decided to use the Huzzah32 since I had already had at home and I could start testing the GUI, transmission of data, and electrodes.
Furthermore, I decided to build my own electrodes since the gold standard silver electrodes are really expensive. I replicated the hydrogel electrode formula I found on a scientific paper. I decided to make hydrogel electrodes since I can make them really cheap, they have an higher signal-to-noise ration compared to the gold standard, and they fitted in my neuroergonomic design. Something that I like is that there is no limit of the size. I want to test how small I can make the hydrogel electrodes and see if the signal-to-noise ratio changes. If not, then I can make them really small and so to create an array of electrodes with an high spatial resolution similar to the g.PANGOLIN (which costs hundreds of thousands of euros) for only few euros.
This is the link for the Github for PiBCI if anybody is interested in contributing: https://github.com/mattin89/PiBCI/tree/main
Below you can find further information about the developing of the project.
Previous Posts
I discuss more in depth about the project, the goals, and the timeline.
PiBCI - Post #2 - Current Technologies and New Approach
Nice blog to learn about current available portable BCI for your neuroscience projects. I discuss about the advantages and disadvantages of each design and common features. You can learn about what to look in a BCI and what makes them powerful. Then, I explain what I need for my project design.
PiBCI - Post #3 - Streaming Data from Huzzah32 Feather to a Raspberry Pi4
First attempt to connect the Huzzah32 to the Raspberry Pi4. I couldn't connect via Bluetooth so I connected it via UDP. Although UDP seems interesting because I can stream data via WiFi, I don't like the set up. You need to manually write in the Arduino code the WiFi name and Password and the Raspberry Pi's IP address was changing all the times it was connecting to the WiFi so I had to change that every time. You can see also my attempt to use ChatGPT to write code in case you have no idea of what you are doing like me.
PiBCI - Post #4 - Making Soft Hydrogel Electrodes and Starting GUI
First attempt to make my own hydrogel electrodes. I purchased the ingredients for the formula and made my own stamps with a laser cutter but I didn't have glass for the stamps. Somebody gave me two sheets of plastics but they ended up burning under the UV light. So I ended up changing strategy and using small glasses for a microscopes. I had to cut again the stamps to fit into the small glasses but I recreated the same condition as in the paper (just a little bit smaller). Also, I started writing the GUI with some basic functions like plotting data in real-time and saving data while doing an experiment. I decided to break down the work and to focus only on the GUI and not on the connection with the Huzzah32 for the next blog. I wanted to make first the GUI to work and then pass again with the Bluetooth.
PiBCI - Post #5 - Finished GUI and (almost) electrodes
Here I finished the GUI by plotting and saving random generated values to simulate the activity of a neuron. The main functions are three:
- Plotting values in real-time with a moving graph
- Conduct a basic motor imagery experiment (I talked more in depth about motor imagery on Post #4) and save labeled data into a .csv file
- Perform data cleaning, feature extraction, and machine learning on a selected .csv file.
I am pretty happy with the results since these three functions are what you need to start conducting basic BCI projects. I am still working to install tensorflow on the Raspberry Pi4 so that I can CNN layers.
I made more hydrogel electrodes and tested their impedance and it was roughly the same so this means their structure was a very stable one and I can make more. I just need to find a solution to spilling to get the shapes I want. I ordered magnets to create stamps that would just clamp to each others but they will arrive next week.
PiBCI - Post #6 - Connecting Huzzah32 board to Raspberry Pi4 and Plotting on GUI
On my last post, I talk about the finished GUI and streaming of data in real-time. The data is being sent from 8 GPIO pins connected to the ADC of the Huzzah32 via Bluetooth to the Raspberry Pi4. The GUI will have the three functions as listed before. I tried transmitting data at high frequencies like 16kHz but I was having issues in unpacking all the values. But it is possible to stream values at that high frequencies. Also, I explain why this time the Bluetooth connection was successful and why last time I was confused. Finally, I calculated the price for a single hydrogel electrode and it is around 8 cents for the materials making this device really economic.
Next steps
- Make the GUI work also for high sampling rate
- Make the hydrogel electrodes with the desirable shapes and test them
- Include more machine learning algorithms and more choices for the data cleaning and feature extraction
- Include more neuroscience experiments such as P300 and SSVEP
- Build a circuit with the ADS1299 (when it gets shipped) and ESP32 and transmit data
- Get more people involved with PiBCI so to create a community of builders
What I learned
- I did study previously WiFi protocols like UD and TCP but never actually worked with them
- Transmitting data with different wireless protocols and process it on the Raspberry Pi4
- Started using ChatGPT to assist writing code and realizing how much we can't still rely on it
- Making soft hydrogel electrodes
- Saving data during an experiment in a readable format to process it later on
What YOU can learn
- Available portable BCI and the best design for your next neuroscience project
- Available resources for BCI and what you need to look into
- Basic neuroscience experiments
- How to set up connectivity between an ESP32 board and the Raspberry Pi4 (and the issues that can happen)
- Write code for ESP32 and Raspberry Pi4 to transmit data and GUI
- How you can use PiBCI to develop your own board and start doing neuroscience projects.
Before starting this project, I already had experience with BCIs and communicating via a GUI from an Arduino to a PC via cable in order to read some sensors and activate DC motors. This time I stepped the game and decided to transmit data via Bluetooth and to a Raspberry Pi4 to conduct experiments. I really had fun doing this and I will keep it going to push it further. Everybody can just take my codes and flash them on their boards. Maybe you will have boards with higher ADC resolution. Thanks to this project you can avoid relying on commercial available platforms and their products.
The available portable BCI devices can be expensive and hard to use especially for people with no experience and training. More advanced electroencephalography can even cost tens or hundreds of thousands of dollars. This project shows it is possible to conduct neuroscience experiments and to build modern portable BCI devices while still having high performances and make it accessible to everybody.
Thank you for reading this post. Enjoy this video of me recording EMG on my left arm using some pieces of the hydrogel electrode that survived. This is the beginning of something!