Open source multi-channel EEG/ECG/EMG
Electrodes on the skin can be used to measure muscle (electromyography, EMG) brain (electroencephalography, EEG) and heart (electrocardiogram, ECG/EKG) activity. These electrophysiological measures are popular for clinical, research and hobbyist applications (such as brain computer interfaces). Most commercial systems are “medical grade” – these expensive systems offer high precision (16-24 bits), participant electrical isolation as well as support. On the other hand, there are numerous “hobby grade” solutions that are very inexpensive but do provide fewer features. Here we describe a “research grade” solution offering the same precision and safety of the medical systems, with the ability to add time stamps (for averaging data across trials) at a much lower cost (though without the FDA approval or support, so use these designs at your own risk).
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.
This code works with an Arduino Due as well, though in my experience the BlueTooth modules are limited to around 115200 bps speeds, so it is less well suited for wireless communication. However, it is important to note that the upcoming EEG Mouse design will have the same microprocessor as the Due, so software should be optimal for that application. The essential wiring for connecting a Due to the ads1298 or ads1299 front end kits is shown on the left. Note that this figure shows the BOTTOM of the front end board (so that the header pins are accessible) and the top of the Due (so its pins are also accessible). The J4 jumper gets the 5v, 3.3v and 0v (ground) power. The J3 jumper has the signal pins – the required pins are pins are the SPI clock (SCK), Data Out (DOUT), Data In (DIN), chip select (CS), Data Ready (DRDY) and Start (START). Again, note that the Arduino and ads129n cross their DIN/DOUT – in the figure I use ‘->DIN’ to show that this Due (DOUT) pin connects to the ads129n DIN pin. You must also connect the ground to of the Due to the analog ground of the ads129n – this should be done with a zero ohm 1/10 watt resistor (that acts as a fuse for protecting the participant). The diagram also shows the pins for connecting a blue tooth module (TX1, RX1) – remember the bluetooth module also requires power. Please note that for wired communications my software assumes you will connect your Due to your computer’s USB port with the Due’s fast “Native” port rather than the slow “Programmer” port (the Due has two USB sockets).
In theory, you could use other Arduino compatible devices for connecting to the ads129n devices. However, the Arduino would need to support SPI and would need to have a high speed serial port (older designs like the Uno have very slow serial connections). Two possible candidates are the Teensy 2.0 and Arduino Leonardo. However, be warned that these devices use 5 volt signals that may not work with and could even damage the ads129n (which can only handle signals up to ~3.4 volts). Therefore, you would need to add voltage dividers to each signal line. Therefore, the T3 and Due (that natively operate at 3.3v) are simpler for this application, and generally provide better performance.
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 (see Nick 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.
For more detail: Open source multi-channel EEG/ECG/EMG
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w
This Post / Project can also be found using search terms:
- ads1299 kit
- usb cable to eeg channel
- arduino due rtos spi ads1298
- code test EKG shield for arduino