[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).
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 runs entirely on the microcontroller one it is trained. Their is a cost to doing processing on the microcontroller: the signals are not nearly as clean or pretty as what you might see on an external application. However, they are clean enough to detect changes in mental concentration or muscle flexing which is pretty cool!
- FIR Filter Example (primary)
- FFT Example (Adafruit recently released at FFT library that is optimized for ARM Cortex math!)
- Ported code for Protocentral's ADS1292 ECG visualization tool
CODE FOR THE VISUALIZATION & MACHINE LEARNING WEB APP
- MODULAR DESIGN: Modular electrode connectors means the device can be used with alternate electrodes for EMG, ECG or other variations of EEG electrodes.
- CLIPS ONTO GLASSES: For people who wear glasses this is one less thing to strap on your face. I also made the plastic boom transparent for a lower profile.
- CLIP-ON REFERENCE ELECTRODE EARRING: Reference electrode is built from a sturdy clip-on earring that won't slip off. I incorporated medical grade EEG dry electrodes into both reference and sensing electrode designs.
- EXPANDABILITY: OLED display, accelerometer, HR sensor, button and flash memory IC are all accessible and programmable from the MCU - all you have to do is figure our the code. So far I've only been using the ADS1292 ECG and the vibration motor. Everything is also miniaturized with mostly 201 CMD components and a highly compressed design.
- MIND CONTROLLED PLASMA BALLS: Two GPIO from the EEG Glasses nRF52832 MCU are exposed through the programming connector (from the HR sensor SDA and SCL connections). I conveniently have a pair of should mounted plasma balls with an inbuilt relay. Since I obviously need some kind of cool test when I'm finished, I'm going to run a wire from the EEG Glasses connector to the shoulder mounted plasma globes relay. Viola, mind controlled shoulder mounted plasma balls.
B20 ECG Fitness Tracker Specs:
- Texas Instruments ADS1292 two channel (only one is used) ECG front end
- Nordic nRF52832 ARM Cortex M4 SoC/MCU
- Bosch BMA253 Accelerometer
- Gigadevice GD25Q16C 16MB Flash Memory IC
- PPG Heart Rate Sensor
- 0.95" 64*128 pixel monochrome SD1306 OLED display
- Vibration motor
- 80mAh LiPo battery and battery charger
B20 nRF52832 MCU Pinout
- P19: Button
- P3: Vibration Motor
- P5: SSD1306 OLED Display
- P6: SSD1306 OLED Display
- P7: SSD1306 OLED Display
- P11: GD25Q16C 16MB Gigadevice Flash Memory
- P12: GD25Q16C 16MB Gigadevice Flash Memory
- P13: GD25Q16C 16MB Gigadevice Flash Memory
- P14: GD25Q16C 16MB Gigadevice Flash Memory
- P15: ADS1292 CS
- P16: ADS1292 DIN
- P17: ADS1292 SCK
- P20: ADS1292 START
- P22: ADS1292 RESET
- P23: ADS1292 DOUT
- P25: HR I2C SDA
- P26: HR I2C SCL
- P28: BMA253 Accelerometer CS
- P29: BMA253 Accelerometer SDI
- P30: BMA253 Accelerometer SDO
- P31: BMA253 Accelerometer SCL