-
Notifications
You must be signed in to change notification settings - Fork 23
Data Format for OpenBCI V1 and V2
This discussion of the OpenBCI data format only applies to OpenBCI V1 or V2, which require connecting the OpenBCI board to a 3rd party microcontroller, such as an Arduino. The format of the data being streamed to the PC is entirely defined by the software on the microcontroller, not by the OpenBCI board itself. So, if you don't like the data format defined in our code, feel free to change it!
This discussion of the OpenBCI data format is based on the software that we have written for the Arduino. Our Arduino code can be found here. The Arduino sketch calls a routine in our Arduino library (ADS1299Manager) that pushes out binary data to the serial stream to the PC.
Currently (2014-02-06), the data is being transmitted from the Arduino at a rate of 115200 baud using 8-N-1 format. For the 16-channel setup, the 115200 speed is too slow, so we double it to 2*115200. Therefore, if you are writing client software to receive data from OpenBCI, it would be nice to have selectable transfer speeds.
When you first connect to an Arduino (such as an Uno), the Arduino often restarts. Currently (2014-02-06) the Arduino sketch issues a bunch of lines of ASCII text to describe how OpenBCI and the Arduino have been configured. If you are writing client software, your software must tolerate an unpredictable amount of this initial text.
Once the Arduino has completed its setup, it sends no data. To begin data transfer, transmit a single ASCII 'b' (no quotes) to the Arduino from the PC. Once the 'b' is received by the Arduino, it issues the text string 'Arduino: Starting binary…' (without quotes) and then begins the continuous transfer of OpenBCI data in binary format.
The data is sent in packets (or frames, depending upon your preferred word). Each packet contains a header followed by one sample from each of the 8 channels, followed by a footer. Here are details on the format
Header
Byte 0: 0xA0
Byte 1: length of data payload in bytes. Currently, it is
Payload Length in Bytes = (1+Nchan)*4= 8*4+4 = 36 bytes
Data Payload (all 32-bit signed integers…byte order set by the Atmel micro in the Arduino)
Bytes 2-5: Reserved for future use. Packet counter? Currently just a value of one.
Bytes 6-9: Data value for channel 0 (32 bit signed int)
Bytes 10-13: Data value for channel 1 (32 bit signed int)
Bytes 14-17: Data value for channel 2 (32 bit signed int)
Bytes 18-21: Data value for channel 3 (32 bit signed int)
Bytes 22-25: Data value for channel 4 (32 bit signed int)
Bytes 26-29: Data value for channel 5 (32 bit signed int)
Bytes 30-33: Data value for channel 6 (32 bit signed int)
Bytes 34-37: Data value for channel 7 (32 bit signed int)
Footer
Byte 37: 0xC0
Note that this packet format describes an 8-channel setup using a single OpenBCI board. OpenBCI also supports daisy-chaining of two boards to enable 16 channels of EEG data. In that case, the data values for the added channels are appended to the payload (ie, after Byte 37) and the value in “Byte 1” changes from 36 to 68. The end of the data packet is still 0xC0.
Once you receive and parse the data packets, it is important to know how to interpret the data so that the values are useful in a quantitative way. The two critical pieces of information are (1) the sample rate and (2) the scale factor. Both can be set by the user by modifying the Arduino sketch, so some flexibility in one's client software may be necessary.
For the sample rate, we set the default rate to 250 Hz. Likely other choices might be 500 Hz and 1000 Hz. The ADS1299 chip at the heart of OpenBCI supports up to 16000 Hz, but I don’t know how one would transfer that much data to the PC from an Arduino.
For the scale factor, this is the multiplier that you use to convert from “counts” (the int32 number that you parse from the binary stream) into “volts”. By default, our Arduino sketch sets teh ADS1299 chip to its maximum gain (24x), which results in a scale factor of 0.02235 microVolts per count. Because the gain is user-configurable (24x, 12x, 8x, 6x, 4x, 2x, 1x), the scale factor could be different if one makes the correct alteration to the Arduino sketch. If the gain is changed, the equation for determining the scale factor is:
Scale Factor (Volts/count) = 4.5 Volts / gain / 2^24 * 2.0;
(Note that the last multiplication by 2.0 was determined empirically by testing our OpenBCI units against known calibration signals applied externally. It is unclear why this factor is necessary).