Close
0%
0%

Hacking a $35 ECG nRF52 Fitness Tracker into EEG

nRF52832 ECG fitness tracker hacked into EEG glasses using Arduino code + detect concentration/relaxation with neural network web app

Similar projects worth following
The B20 Fitness Tracker contains an ADS1292 bioimpedance sensor which can be used for simple ECG, EMG and EEG sensing. It also contains a nRF52832 ARM Cortex M4 processor which can easily be programmed with Arduino. With Bluetooth, OLED display, accelerometer, optical HR sensor and vibration motor - all for $35 in a miniaturized form factor - it is a pretty extraordinary prototyping platform for simple ECG/EMG/EEG projects.

A few months ago I ran a workshop on hacking the Neurosky/Mattel Mindflex EEG headset. Despite being a super famous hack, the core "concentration" detection feature is still a black box after all these years! I decided to replicate this functionality with the B20. I built some EEG glasses and a Web Bluetooth application which can visualize data from the device and train exportable standalone neural networks for detecting brain states Mindflex style and general human-computer interfacing.

[full walk through video coming soon]

HACKING THE B20 FITNESS TRACKER'S nRF52832 ARM CORTEX MCU AND ACCESSING ADS1292 BIOIMPEDENCE DATA

Hacking the fitness tracker is very simple, all you have to do is solder wires to four (V+, GND, clock, data) big test pads on the PCB and connect it to an SWD programmer. The process of setting the device up for programming is explained in detail in one of my past projects and also the README for the project GitHub repository. I have provided a variant file for using Sandeep's Arduino Core which automatically sets up the SPI connection for the ADS1292 ECG chip. The impetus for doing this whole project was requests for help hacking nRF52 Fitness Trackers with ECG (like the B20) from visitors to my "Hacking Wearables For Mental Health and More" project.

B20 ECG Fitness Tracker Disassembly & Programmer Wiring Video

The ADS1292 is part of a family of bioimpedence sensors from Texas Instruments built for a variety of applications including ECG, EMG and EEG. This series of chips includes the ADS1299 which has been used by OpenBCI, a well regarded open source EEG device platform. Although ADS1292 is designed for ECG, there is no particular reason it can't be used for playing with EEG or EMG. The amount of noise generated by the ADS1292 means picture perfect EEG wave visualizations are not on the menu, but differentiation between brain states (EEG) or muscle contractions (EMG) can be accomplished by applying even very messy data to a neural network.


I ran a workshop on hacking NeuroSky/Mattel EEG headsets at the 2018 NYC BrainHack hackathon. Mindlex is probably the most popular and well known (and old) straight up hardware hacking project in existence. Mindflex is human-computer interface hardware hacking 101. Isn't it ironic then that the core functionality of the Mindflex, the concentration/relaxation output actually used in the game, remains a black box? And that no one has bothered trying to replicate it in both form and function a la open source?

THE MISSION: Replicate the functionality of the NeuroSky module and Mindflex headset in open source style for less than the original Mindflex price (about $60).

CODE 

The emphasis of this project is code, both on the firmware end of things with Arduino code for processing ADS1292 data and the live web interface with data visualization and machine learning. You can try out all the features of the live web interface right now using the test data. There are several existing ADS1292 Arduino based projects that pipe raw data over a serial/USB connection into a desktop application for analysis: Protocentral's ECG Processing desktop application (I provide code for using their software) and  Bois083's EEG Lucid Dreaming Project which pipes data into BrainBay. Performance of the EEG glasses is a little better than NeuroSky's classic "Mind Flex" EEG headsets that have been a hacker favorite for years.

CODE FOR THE DEVICE

At a recent Hackathon (CMI's BrainHack) I lead a workshop on hacking the Mindflex toy EEG headset (NeuroSky EEG front end and processing unity). Neurosky provides intriguing "concentration" and "relaxation" values from its EEG module - essentially black box on-device brain state detection. So, I wanted to see if I could do the same thing myself with an ARM Cortex processor and the ADS1292 ECG front end. And I did! It took a lot of work, trial and error + magic numbers in my code. The essential components are FIR (Finite Impulse Response) filters which I use to isolate specific frequency bands (like EEG waves) and a standalone MLP (Multi Layer Perceptron) neural network which is trained on an external web application but...

Read more »

Bosch__BMA253_datasheet.pdf

Adobe Portable Document Format - 1.69 MB - 08/22/2018 at 23:04

Preview

SSD1306_datasheet.pdf

Adobe Portable Document Format - 1.79 MB - 08/22/2018 at 23:03

Preview

GD25Q16C_Gigadevice_Flash_Datasheet.pdf

Adobe Portable Document Format - 1.36 MB - 08/22/2018 at 23:02

Preview

ads1292_datasheet.pdf

Adobe Portable Document Format - 2.02 MB - 08/21/2018 at 06:33

Preview

View all 9 components

  • Finite Impulse Response (FIR) Filter Generation

    Curt White08/21/2018 at 06:53 0 comments

    I used Peter Isza's online FIR filter generation tool to generate all my filter coefficients. You can find the tool here: http://t-filter.engineerjs.com/

    The filter coefficient arrays generated by the tool can be directly pasted into the Arduino FIR filter code. You can find the Arduino FIR filter library here: https://github.com/LeemanGeophysicalLLC/FIR_Filter_Arduino_Library


    Building filters with the tool is super simple. Essentially, the more taps (coefficients) you produce the more accurate your filter will be BUT more taps also makes it slower. Since I'm running a bunch of filters at once while also either sending data over Bluetooth or activating a neural network I have to keep my filter coefficient arrays pretty small. 

    I generated two FIR filters for each EEG wave band: one for low resolution filtering (15-25 taps) and one for higher resolution filtering (45-65 taps)

    Here are screenshots of the FIR filters currently used by the EEG glasses as they were being generated in the online tool:

    Delta (low resolution)

    Delta (high resolution)

    Theta (low resolution)

    Theta (high resolution)

    Alpha (low resolution)

    Alpha (high resolution)

    Beta (low resolution)

    Beta (high resolution)

    EMG (low resolution)

    EMG (high resolution)

View project log

View all 16 instructions

Enjoy this project?

Share

Discussions

fibof98288 wrote 06/05/2021 at 06:15 point

I am also working on thecoecollection project and this post is really helpful to me to explore new ideas thanks for sharing these details.

  Are you sure? yes | no

Luke Mahan wrote 12/29/2020 at 08:10 point

Any update on devices we can currently purchase? Slack channel? I'm very interested in this project

  Are you sure? yes | no

fabianpie wrote 09/17/2018 at 05:39 point

Great job Curt !!! By the way did you find out what HR sensor has the B20 ?

  Are you sure? yes | no

Curt White wrote 08/31/2018 at 04:14 point

Thanks Goran! 

  Are you sure? yes | no

Goran Mahovlic wrote 08/30/2018 at 19:08 point

Another great project, tnx Curt !!!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates