OpenBCI

image_pdfimage_print

A sleep lab for less than $1000 with OpenBCI

DISCLAIMER: Use these instructions on your own risk, it is critical to understand that the devices and methods presented here are in no means a safe and tested Device and they do not adhere to medical standards!

Keep all devices only running on batteries and NEVER attach them to living things like humans without making sure they are disconnected completely from the power grid/plug/line etc!

On multiple request I want to introduce OpenBCI as a cheap alternative to record standard polysomnography. With this and SpiSOP you could in principle built your own private sleep research lab now for under $1000 now, everyting included:

  • mobile EEG and all neccessary materials $650-700
  • PC and monitor $100 (rasperry pi 3, and old Monitor from ebay etc.)
  • Bed and sheets etc. $199
  • Software $0 (e.g. using SpiSOP)
  • Room, there is always “free” room somewhere you can sleep, especially overnight.

I recommend the OpenBCI Cyton (previously known as 32bit Board Kit) as a mobile EEG for polysomnography:

Cyton Biosensing Board (8-channels)

or alternatively from:

http://pirate.info/producten/open-source-hardware/openBCI (also for self assembly, it is about $250 if you assemble the 16-channel version (with daisy module) yourself with all parts included, most expensive part is the ADS1299 chip each around $50-60).

UPDATE: There is a similar project just dedicated to sleep called OpenLD including similar to OpenBCI but developing an own open-source and open-hardware platform just dedicated to sleep, in particular REM sleep (and lucid dreaming) https://hackaday.io/project/13285-openld-lucid-dreaming-research-platform

Here my highlights in brief for the OpenBCI Cyton EEG device:

pro:
  • + cheap: ~$500 each (the new 4 channel “Ganglion” devices are out soon for $100, however not usable for complete standard polysomnography), invest a little more and you get electrodes with it and stuff, or assemble yourself if you have the time and know how to deal with PCB plates (it is open hardware after all)
  • + 8 channel recording (extendable to 16 channel, using an extra module (daisy module), 8 is fine though)
  • + all channels can be bipolar (e.g. for EMG, and EOG, then two electordes give one channel)
  • + sample rate is 250 Hz (seems it can vary depending +-0.4 Hz, I guess depending on room temperature, not enough to impair precision of sleep scoring, a sample rate of 250.4 Hz seems more accurate for a tested device at ~21°C )
  • + recoredding is with 24 bit signal precision. In reality the signal resolution is 0.02235 microVolts at 24x gain (default, see Table 1 below). They are stored as 6 hex values (= 24 bit) on the SD card and. Usually 0.1 microVolts is more than enough for EEG and ECG and EMG etc. and noise is anyway about (0.16 microVolts root-mean-squared, recording the same channel deviation C3:A2 directly or rereferenced gave a noise of about +-0.6µV, that is awesome!). The signal range is more than sufficient at any gain value.
  • + can be initialized (and sampled) over the air (via bluetooth)
  • + runs on battery and is mobile (e.g. with a little soldering runs on on a power pack like this for days without recharge! http://www.ravpower.de/16750mah-portable-charger-black.html but caution with the voltage range of the different borad types, I uses the 32bit Cyton version). Input to the OpenBCI 32bit Board/Cyton is 3V to 6V (so very flexible indeed, runs on 5V USB and 3.7 V LiPo batteries, or 3 to 4 of 1.5 V Mignon Battery coupled in series)
  • + recordings are on micro SD card (needs to be bought separately)
cons:
  • – no trigger out of the box (so no lights-off moment) – however will be possible with newer Firmware soon, and you can use a channel to take a kind of trigger signal (no problem with rasperry pi hardware et al. running on batteries, or your laptop running on batteries and not being pluged in for charging). However see simple Trigger builtbelow.
  • – no easy and reliable live monitoring of the recording (sometimes interrupted if not carfully handled, bluetooth connection is not that reliable)
  • – does not run out of the box, and no sleep scoring software (there is however plenty of freeware on that… and you can use SpiSOP for that of course)
  • – data format needs to be converted to brainvision or EDF format, but conversion is in fact very easy (http://www.spisop.org/downloads/ see conversion utilities)
  • – needs to be packed in a box for protection of the circuits (if you want to be on the safe side)

 

Table 1: Signal resolution and range

Signal resolution [microVolts] Gain [amplifier] Signal range [microVolts]
0.02235 24 -187500 to 187500
0.04470 12 -281250 to 281250
0.06706 8 -375000 to 375000
0.08941 6 -562500 to 562500
0.13411 4 -1125000 to 1125000
0.26822 2 -2250000 to 2250000
0.53644 1 -4500000 to 4500000

 

Here an example of all the materials you might need:
openbci_sleep_recording_material

 

Trivial pro advice: get familiar by the terminology, that is get to know what the dongle is, what the device is. Look at the OpenBCI website for news and updates and general info before you start: www.openbci.com

Hardware Setup

Here is a setup example for a sleep recording for the pins on the OpenBCI device.
The setup is a standard sleep polysomnography setup usable for sleep scoring based on Rechtschaffen and Kales (1968).
It includes and EOG (two bipolar electrodes around the eyes) and EMG (two bipolar electrodes on the chin, musculus mentalis) and two EEG Deviations at C3 and C4 according to the international 10-20 Electrode placement system (that is C3:A2, C4:A1). The setup records C3, C3, A1 (left mastoid) and A2 (right mastoid) signals separatly referenced to a placed reference electrode at Cz and uses as a bias Bias/Ground electrode at Fpz (placed at the center of the forehead).
Other than in the original description the A1 and A1 should not be placed on the ear lobues,  but on the Mastoids (the “bony”, part behind each ear).
This way, one can later also deal with lost mastoid electrodes (e.g. in case A2 is lost one can still use C3:A1 as a backup) and this setup is in general more flexible, thus preferred here.
Setup the OpenBCI device and connect the electrodes:
On the OpenBCI device, the Bottom pins are N pins, Top pins are P pins, so connect them in this way:

 

Channel # Electrodes Pins to use Electrode label (cable color) Type/Function Location Comment
SRB 1 N(bottom) alias SRB2 Ref (white) Reference vertex (~center of head viewed from top) (Cz)
BIAS(2) 1 (2 is the bottom pin) Ground Ground/Bias forehead (Fpz)
N1P 2 N(bottom), P(top) EMG1,
EMG2
EMG left chin,
Right chin
EMG =
EMG1-EMG2
N2P 2 N(bottom), P(top) EOG1,
EOG2
EOG 1 cm left of left eye cantus,
1cm above right eye center
EOG =
EOG1-EOG2
N3P* 1 N(bottom) A1 EEG A1 (bony part behind left ear)
N4P* 1 N(bottom) A2 EEG A2 (bony part behind right ear)
N5P* 1 N(bottom) C3 EEG C3 (6-8 cm left of vertex towards left ear)
N6P* 1 N(bottom) C4 EEG C4 (6-8 cm left of vertex towards right ear)
N7P [not plugged] – (unused) e.g. Fz or bipolar ECG, trigger signal (red/positive in top P pin)
N8P [not plugged] – (unused) e.g. Pz or bipolar ECG, feedback channel from stimulation
In total 10 electrodes are used, two channels are still free to be recorded (e.g. occipital of frontal channels, or second EOG etc.), however would require additional electrode pins that do not come with the kit (but can be bought additionally).
* Importantly, in this configuration all the (non-biploar) channels that are referenced to the SRB2 (N, bottom) pin (that is the EEG channels like A1, A2, C3, C4) are REVERSED in their polarity. This can only be corrected later on after the converstion (non-“.csv” files like edf or brainvision files).
This is not avoidable, otherwise one needs to reference against the SRB1 pin (P, TOP), which however will FORCE all channels to be referenced to this channels, thus not allowing for bipolar channels like EMG and EOG. So this setup is clearly preferred. The polaritiy of the bipolar channels are not impaired by this.
Any standard EEG electrodes will do, however best are Silver/SilcerChloride electrodes for such sleep recordings, but any other will do fine.
For electrode paste, I have good experience with “Grass EC2 Electrode Cream” which is a commercially available paste that keeps the electrodes fixed to the head, and the impendances low over the whole night, also it washes off quite well with just warm water.
In brief, to place an electrode, use a Q-tip and some abbrasive (peeling) cream (< $2 in store) to scratch of your skin a little in an 1cm² region, wipe of with skin desinfectant (to get rid of any residues on skin) and aply the heavily creamed electrode to the site, fix with two finger-long medical bandage stripes of tape in a criss-crossed way (do not use medical tape that is hard to remove from hair or skin, and that does soften on warm water).
Check your impendances (using a standard Voltmeter/Impendance measure device from the hardware store for < $10) between any two EEG eletrode pairs are < 5 kOhm (e.g. measuring ground electrode vs reference electrode, then reference against all the others) EMG and EOG electrodes < 10 kOhm is OK.
After use, carefully clean your electrodes and head with water, a very wet and warm towel on your head in the morning for 3-5 min will help you remove the electrodes in no time without any hair loss.
A Trigger / Indicator can simply be constructed by the circuit below, attaching it like a bipolar channel on the N7P pins for example and the use of a 5 V USB plug (INTO THE BATTERY, NOT a power supply). It will provide a steady and fast spiking 1000 µV signal when the switch is turned on (and draws neglegtable power for the battery) or signal is 0 µV when the switch is turned off (no power consumption). The trigger voltage on the device pins can be increased or decreased by varing the resistors. Thus one channel is used per trigger. It can indicate Lights-OFF and Lights-ON, or when a standard procedure is performed etc. With a little of standardization one Trigger and a little annotation is usually enough to identifiy all kinds things to be triggered during the recodring (e.g. ON-OFF-ON-OFF sequences every second can indicate changes in procedure, or a short period with switch turned ON, when usually turned off can indicate testing of the signal with eye-movments, blinks, using of jaw muscle etc.)

 

An alternative setup (that also avoids the polarity switch of the EEG channels that are referenced to the SRB2 pin) is below. Here it is harder to find out if a mastoid electrode (A1 or A2) was messed up or went bad:

 

Channel # Electrodes Pins to use Cable color Label (electrode) Type/Function Location Comment
SRB 2 N(bottom) alias SRB2 white Ref (A1-A2) Reference (linked) (linked A1 and A2 with an electrode bridge)
BIAS 1 2 or N (bottom) black Ground Ground/Bias forehead (Fpz)
N1P 2 N(bottom), P(top) grey, purple EMG1,
EMG2
EMG left chin,
Right chin (musculus mentalis)
EMG =
EMG1-EMG2
N2P 2 N(bottom), P(top) blue, green EOG1,
EOG2
EOG 1 cm left of left eye cantus,
1cm above right eye center
EOG =
EOG1-EOG2
N3P 2 N(bottom), P(top) yellow,orange A2, C3 (C3:A2) EEG A2 (bony part behind right ear),
C3 (6-8 cm left of vertex towards left ear)
N4P 2 N(bottom), P(top) red, brown A1, C4 (C4:A1) EEG A1 (bony part behind left ear),
C4 (6-8 cm left of vertex towards right ear)
N5P [not plugged] – (unused) – (unused) e.g. Fz:A1-A2 or bipolar ECG
N6P [not plugged] – (unused) – (unused) e.g. Pz:A1-A2 or bipolar ECG
N7P [not plugged] – (unused) – (unused) e.g. Cz:A1-A2 or bipolar ECG
N8P [not plugged] – (unused) – (unused) e.g. Oz:A1-A2 or bipolar ECG

Software Setup

How to do the recording with OpenBCI_GUI:
  1. Prepare connections and setup electrodes and OpenBCI device (see section above on Hardware setup for this).
  2. Prepare the microSD card for new recording, this means delete/backup/save previous files on there (if not formated in FAT32 then do so now, see SD card basics, it is important that the SD card is formated correctly, otherwise the data will not write properly, SD cards of “Class 4” seems to be sufficient, it does not seem to matter if other (non-OpenBCI) files are on the card, an microSD to SD adapter for your PC and a SD card reader is required of course for this).
  3. Check if the dongle switch is turned on “GPIO_6” NOT “RESET”.
  4. Put in the microSD card in the OpenBCI device.
  5. If something goes wrong from here on now, start from this step again
  6. Plug in dongle first (until blue light is on), if it is plugged in plug it out and then in again.
  7. Turn on OpenBCI device, that is put the switch on “PC” NOT “BLE” (ideally you should see one or two very short red blinks on the OpenBCI dongle after the OpenBCI device was turned on, this is a good sign, but does not have to occur), if you have a trigger cable also check if it is connected and plugged to the power.
  8. Start the OpenBCI_GUI (prefereably in processing or a new exported version of it, get it here https://github.com/OpenBCI/OpenBCI_Processing or use one of the newer compiled versions http://openbci.com/index.php/downloads windows and mac version work nicely).
  9. Start a “Live Session” or “Live (from Cyton)”  for 8 channels, with SD card recording length of e.g. 12 hours, 8 channels (giving a file name is irrelevant since you record on the SD card)
  10. Edit all your channels (click “Hardware settings” in the top left for this) for the recording to follow (all with gain of 24, this also works fine for the sleep EMG) see Table below.
  11. Press “Start Data Stream” (this is the start when data gets written to the SD card)
  12. wait 2 seconds
  13. pull out the dongle form the USB port on the PC (yes, just pull it, SD recording will continue for the 12 hours you set up, OpenBCI software will loose connection of course)
  14. wait until you have recorded your sleep etc. to be written on a your file (e.g. “OBCI_0C.TXT”) to be written to the SD card.
  15. When finished, just turn the OpenBCI device off,
  16. The SD file was saved on the SD card and you can copy and convert on your PC (see below)

 

Channel setup in OpenBCI_GUI for the preferred setup (things to change from default in bold):

Channel Status Label Gain InputType Bias SRB2 SRB1 Init. Sequence
1 ON EMG x24 Normal Don’t include OFF NO x1060000X
2 ON EOG x24 Normal Don’t include OFF NO x2060000X
3 ON A1 x24 Normal Include ON NO x3060110X
4 ON A2 x24 Normal Include ON NO x4060110X
5 ON C3 x24 Normal Include ON NO x5060110X
6 ON C4 x24 Normal Include ON NO x6060110X
7 OFF(if unused)/ ON (if Trigger cable used) x24 Normal Don’t include OFF NO x7160000X / x7060000X
8 OFF(unused) x24 Normal Don’t include OFF NO x8160000X

For details see (http://docs.openbci.com/OpenBCI%20Software/01-OpenBCI_SDK)

 

For the nerds: Initialization sequence to sent to OpenBCI device for a 12 hour recording on the microSD card (by OpenBCI software, or by OpenVIBE http://openvibe.inria.fr/):
x1060000Xx2060000Xx3060110Xx4060110Xx5060110Xx6060110Xx7160000Xx8160000XK

Conversion of (micro-)SD card File

…to EEG file formats like EDF or Brainvision

There is a conversion script (http://www.spisop.org/downloads/ see conversion utilities) that converts the with the SD card file recording the preferred setup (see above) in usefull other data formats (that is different formats of EDF and Brainvision files, e.g. with 0.1 µV signal accuracy) giving the channels (asterisks mark the preferred channels for sleep scoring):

Channel Label Filter Usage
EOG 0.3-35 Hz scoring eye movements/blinks
C3:A2 0.3-35 Hz scoring EEG
Cz:A1A2 0.3-35 Hz additional EEG deviation
C4:A1 0.3-35 Hz scoring EEG backup channel
C3:Cz 0.3-35 Hz original EEG deviation
C4:Cz 0.3-35 Hz original EEG deviation
A1:Cz 0.3-35 Hz original EEG deviation
A2:Cz 0.3-35 Hz original EEG deviation
EMG 10-125 Hz scoring muscle and artifacts
C3:A2fspind 11.5-15 Hz aid in fast spindles
C3:A2sspind 8.5-11.5 Hz aid in slow spindles/alpha
C3:A2SO 0.5-2 Hz aid in slow oscillations/waves/K-complexes
C3:A2theta 4-8 Hz aid in theta
C3:A2alpha 8-12 Hz aid in alpha detection

For this extract the utility.zip (downloaded from http://www.spisop.org/downloads/ under see conversion utilites) to your SpiSOP folder (e.g. “D:\spisop_toolbox_beta2.3” resulting in a “D:\spisop_toolbox_beta2.3\utility\convert_data” folder\…); if you did not have installed SpiSOP yet, just do it now (it is just extracting it to some location like “D:\spisop_toolbox_beta2.3” by skipping steps 3 and 6 from this Instruction)

Then put the “OBCI_??.TXT” File(s) from your recording in the conversion folder (e.g. D:\spisop_toolbox_beta2.3\utility\convert_data\OpenBCIv3\convert_SD_file\SD_to_ascii_then_to_EEG)

Then edit the “obci_convert_gain24_constant_trigger.bat” in that folder for the SpiSOP toolbox folder and give correct paths to the toolbox, and run it, wait a little and you have your converted files!

e.g. change

...
SET pathPrefix=D:\spisop_toolbox_beta2.3
...

to fit your SpiSOP folder path.

You can use these converted files to do sleep scoring with the SpiSOP browser function, and do other cool stuff with your sleep EEG with other SpiSOP functions.

Now you can feel like a sleep resercher and detect your own sleep!

 

Considerations

Power consumption and how long does it last?:

The power consumption of the 32bit/Cyton 8 channel device is (as measured by my standard Voltmeter) about ~50 mA in idle mode, ~65 mA in connected mode, and ~75 mA while streaming and recording on SD card. So a 16000 mA 5 V USB power pack can last fully charged (in principle) for up to 8 days through.

To prevent (yourself and) others to charge the power pack while connected with your OpenBCI: TAPE THE PLUG AS TO NOT MAKE YOUR POWER PACK CHARGEABLE WHILE USING IT AS A POWER SOURCE FOR A DEVICE CONNECTED TO YOUR HEAD!

Many power packs however shut down after a few seconds if the current is below a certain threshold (the ealier version of the Ravpower with 14000 mAh, Model RP-PB13, requires >95 mA current draw). The above mentioned Ravpower pack with 16000 mAh with iSmart output maybe does not have this limitation. This threshold is obviously to high since the OpenBCI device needs less than 95 mA. So if it is just connected the Power pack cuts the power after a few seconds again. However this can be solved:

Solution 1 (Quick): Turn on the LED flashlight while powering the OpenBCI device (and cover the flashlight with some opaque tape to make it not shine all night). This draws a lot of power though.

Solution2 (better): bridge the power source with a 100 Ohm resistor. USE A RESISTOR THAT CAN WITHSTAND 1 W OF POWER (most resistors are not built for this I would recommend using metal film resistors, NOT carbon film resistors), otherwise the resistor (and things near it) will get very hot (or burned)! This resistor will pull ~50 mA from the 5 V battery pack when turned on. This is enough to keep your device running (ONLY) if your OpenBCI device is powered. If the device is not turned on, then (magically) the power pack shuts down automatically after a few seconds. The resulting power consumption is 72 mA + 50 mA = 122 mA (still not much as you can power your device about 5 days straight with one charge of the recommended power pack).

Solution3 (best): get a power pack that does not power down on low power draws. e.g. https://www.ravpower.de/12000mah-portable-charger-black.html or the 22000 mAh version, Model RP-PB052, from https://www.ravpower.com/portable-charger.html which I tested to not shut down on low power draw and idle OpenBCI device, it thus will theoretically last to power the device for 12 days!

True sample rate and variation in time data:

A short test on an 8-hour recording at usual Central European room temperatures (22° C) lead to the conclusion that the sample rate was overall (on average) faster than the 250 Hz (that is about 250.4 Hz) leading to approximately a 1 minute  extra of displayed recording time in an 8 h of recording when it was in fact shorter. In conclusion the sampling rate varies over the recording, It is unclear how much it varies within this time frame and how stable the sampling rate is over longer terms (that is, is it 250.4 Hz all the time or not? This needs still to be determined). It is also unclear how this changes from device to device. This altering sampling rate makes sense when one consideres that there was no external oscillator (clock) used on the board.

high density EEG? Well yes why not, should work in principle (with limitations)!:

You can record with several devices at the same time. Each device than has to share the same bias and reference electrodes via a bridged, and also share one additional channel (e.g. EEG) via a bridge. Later the signals from the many devices can be concatenated using signal coherence of the shared EEG channel (via cross-correlation with the lag of the peak in correlation value as an adjustment). Feasible are at least 4 devices each with 16 channels, that is including EMG, ECG and EOG (3 channels) in one device and one shared channel for the others = (16-3) + (16-1) + (16-1) + (16-1) = 58 EEG at 125 Hz (and potentially more when the Wifi shield is out)…. for a device around $4000. You just start recording of those devices one after the other on SD card… later concatenate the signals after the recording is finished. This makes it unfeasible now to monitor all channels live on the same PC (however could be achieved by running several instaces of the OpenBCI GUI, and plugging in all the dongles at the same time). Imporantly, if you merge the data later you need to consider that the sampling rates of each device was not synched! This leads to time uncertainty in each channel and limits the use of the concatenated data, that is you cannot use it for timelocked analysis accross channels of different devices (e.g. slow waves in channel 1 recorded with device 1 timelocked to spindles in channel 11 recorded with device 2. However it should be fine for counting spindles or spindle density/slow wave density, or do channel-wise analyses.

A casing for OpenBCI:

Any (non-metal inside) box will do that can hold battery and device at the same time and maybe can be carried around. You can shield it further with Aluminum around the case. And nothing keeps you from stuffing it in a nice teddy bear to go to sleep or send others to sleep with. It is however highly recommended to isolate the device first in some thicker plastic before rapping it in something conductive (e.g. non-conductive tape) and keeping it away from sharp things that could demage the contacts or the board circuits (e.g. a dry kitchen sponge)!

Troubleshooting

  1. Connection of dongle and device cannot be established and the dongle LED is blinking red shortly a few time but then breaks off. If in this case it works (after shutting down the device, reconnect the dongle, turn on device again) to connect WITHOUT SD card (and initialization of it) then your SD card is probably formatted wrong or full or not compbatible. Follow the instructions at the OpenBCI website here.

Related projects