Open source EEG/ECG/EMG
This is an open source project for recording high quality electrophysiological data using an ADS129n compatible front-end. These chips support 4 (ADS1294), 6 (ADS1296) and 8 (ADS1298, ADS1299) channels for measurement with 24-bit precision (and if you need even more channels, you can daisy-chain multiple chips). The ADS communicates using a serial peripheral interface (SPI) link. In this design, an Arduino-compatible microcontroller translates between SPI and a Bluetooth or USB Serial Port Connection. Software in the Matlab and Processing languages allows a computer to record these serial port signals. The connection between the computer and the Arduino should be electrically isolated – either via a wireless bluetooth module (the JY-MCU sells for $8) or an electrically isolated USB connection (e.g. using an ADUM4160, $11).
One nice feature of the ADS129n is that they provide 24-bit precision. This allows a single hardware design to be used for very different applications (spanning EEG to ECG and EMG). In contrast, a 16-bit design needs to be tuned for the small and slow signals of scalp recorded EEG or the quick and relatively huge signals generated by superficial muscles in EMG. The chip also contains a number of sophisticated options for filtering data and acquiring ECG. The newer ADS1299 is pin-compatible with the ADS1298 providing a bit better precision but requiring more current.
The host computer can send signals to control the amplifier (e.g. specify the number of channels to send, the amplifier gain, sample rate, etc). The software and datasheets describe how to do this. Once the computer has specified the desired settings, a RDATAC (read data continuously) causes the amplifier to begin streaming data back until a SDATAC (stop continuous data) command is sent. In my code, the Arduino converts serial port signals directly to SPI signals, so the host software has complete control of the ads129n setup, and the code is identical for SPI or serial port communication. However, my Arduino code does alter the format for RDATAC data when transferring data from the SPI to serial port. The reason for this is that the SPI interface has a tremendous amount of bandwidth (e.g. the Teensy 3 can in theory support 21 Mbs), whereas Bluetooth connections are much more limited (e.g. inexpensive Bluetooth modules max out at about .4 Mbs). For every sample, the ADS129x SPI link will send 3+3*n bytes of data per channel, where n is 4 (ADS1294), 6 (ADS1296) and 8 (ADS1298, ADS1299). Therefore, even when you record a single channel (3 bytes), the ADS1298 sends 27 bytes of data per sample. To conserve bandwidth, this project sends 1+3*n where n is the number of ACTIVE channels. Therefore, if you set a channel to be disabled (“input shorted”) it will not require bandwidth. The first sample transmitted via the serial port is the same header byte reported by the SPI data format – this includes a signature (to help detect the first byte in each sample) and 4 bits that report the status of the 4 GPIO (general purpose inputs/outputs) that allow you to record time stamps. This sounds complicated, but the example Matlab and Processing software demonstrate how to implement these communications.
I prefer to use a Teensy 3.0 (T3) for this application. It is inexpensive, natively supports 3.3v signals, and can support high speed (460800 bps in my experience) BlueTooth communications. The T3 has a hardware SPI port (pins 10-13) and an additional hardware serial port (pins 0 and 1) which can be used for a bluetooth module. The image shows the connections. Pins 0 and 1 are connected to the Bluetooth module. Pin 4 is connected to the ADS “START”. Pin 5 is connected to the ADS “DRDY” (data ready). Pin 10 is connected to CS (Chip Select). Pin 10 (DOUT) is connected to the ADS “DIN” (Data In) while Pin 11 (DIN) is connected to the ADS “DOUT” (Data out). Pin 13 is connected to the ADS “CLK” (clock). Optionally, connect pin 2 to PWDN (power down), pin 3 to RESET (reset) and pin 6 to CLKSEL (clock source). To omit these connections, PWDN, RESET and CLKSEL should in theory be pulled high (to 3.3v, DVDD), though with the demonstration boards they float high so can be left unconnected. Note you can always send the RESET command as an op-code from software. The T3 will also supply power to ads129n front end board – you will want to provide 5v, 3.3v and 0v (ground) in addition to linking the ads129n analog ground (AGND) to the T3 0v with a 0 Ohm 1/10 Watt resistor (which acts like a fuse to protect the participant). The Due image below shows the location of these pins on the ads129n front end boards.
You can purchase the ADS1298 (ideal for ECG) or ADS1299 (ideal for EEG) Performance Demonstration Kits for about $200. The ADS1298 kit can connect to a standard EMG connector (about $40). For EMG or EEG you will probably be better served with the ADS1299 kit connected to some DIN 42-802 sockets (seeNick Johnston’s schematic and photo). In the near future expect to see a less expensive, smaller open source design that can be used instead of the demonstration kit (e.g. the EEG Mouse team’s REV1 board will integrate an Arduino compatible microcontroller on the same board as an ADS1299, the previous REV0 design can be fabricated and used instead of the demonstration kit).
Testing your wiring
The first program to run on your Arduino/T3 is the “adsArd_hello_world” – this just makes sure that your Arduino is wired correctly to your ads129n. Load this software onto your Arduino/T3 using a USB cable (make sure to connect the cable to the ‘Native’ rather than ‘Programmer’ port if you use a Due) and then select Tools/SerialMonitor. You should see a message like “Device Type (ID Control Register): 62 Channels: 8” repeated regularly. If this works, you have wired everything correctly. If you are told the “Channels: 0” then there is a problem.
Upgrading a Bluetooth Module
Most commercial Bluetooth modules are initially programmed to only communicate at 9600bps. The included Arduino sketch “Bluetooth_Programmer_Ard” allows you to reset your module for higher speeds – in my experience inexpensive modules run at 460800bps with the Teensy 3 (and 115200 bps with the Due). You only have to run this script once – check the Arduino Serial Monitor to follow the progress. Once your module is reprogrammed it will use the new speed whenever it is restarted. Once you have reprogrammed your module, remember to put a more useful sketch onto your Arduino (for example, the adsArd sketch described below).
Arduino SoftwareTeensy 2 uses pins 1,2,3 for SPI communications). Once your Arduino has been re-programmed, it will act as a SPI-serial interposer whenever it is restarted. For the Teensy 3, the light on the device will be off when the ADS129n is resting, dimly lit when the ADS129n is streaming data, and will blink slowly if the Teensy is unable to detect a ADS129x (check the connections between the Teensy and the ADS129x).
The Matlab software lets the user specify the sampling rate, number of channels, and whether or not you wish to save the data. If requested, the data will be saved in BrainVision analyzer format, which you can view with the free ELEcro or EEGlab software.
By editing the first few lines of the Processing script you can specify the sampling rate, number of channels, and whether or not you wish to save the data. If requested, the data will be saved as tab-delimited text. You can view these files with your favorite spreadsheet.
- Chipstein describes probably the best hobby grade EMG (16-bit) and EEG (10-bit) around. The section on electrodes and skin preparation is vital for any electrophysiological recording.
- Here is a link to an open source EU-certified 12-lead PC-based ECG.
- The EEG Mouse team are developing a complete open source ADS129n hardware project with an Arduino-compatible processor built onto the board. Our intention is that the software we describe on this page can be used on this hardware to record data.
- The ADS1298ECG Front End Performance Demonstration Kit includes a ADS1298 module that can be directly plugged into a Teensy 3 or other Arduino compatible device. Note that the configuration of the input channels is really optimized for ECG rather than EMG or EEG. The ads129n can do some sophisticated preprocessing of ECG data. EMG and EEG are simpler, but if you wish to use this demonstration kit for those applications you will need to use the jumpers appropriately.
- Raul Aguaviva describes a simple ECG system that can input into his XOscillo software.
- Scott Harden describes the an elegantly simple hobby-grade ECG and optical pulse measurement system.
- We are also developing a single channel research grade EMG system (16-bit). It is a great alternative when a single channel is sufficient.
- Josh Wojnas provides plans for a simple ADS1298 hardware board.
- Nick Johnston describes a similar Arduino-ADS1298 combination (back then, he had to use a Arduino Uno that has a very slow serial interface).
- Our BlueTooth re-programmer extends work by Ryan Hunt.
- StarCat provides the HackEEG shield
- OpenBCI provides impressive products.
- The work described here has been extended by Adam Feuer.