Showing posts with label Adafruit. Show all posts
Showing posts with label Adafruit. Show all posts

Saturday, January 3, 2015

Soldering 16-chan OpenBCI

For a while now, I've been using the 8-channel version of OpenBCI.  You can see some of my EEG data here and some of my accelerometer data here.  Recently, I've been interested in getting more EEG channels, which means that I have turned my attention to the 16-channel version of OpenBCI.  The 16-channel version consists of a single 8-channel OpenBCI board with a additional "Daisy Module" to provide the additional 8-channels.  Today, I'm going to show a few pictures of the soldering necessary to assemble these two boards into a working unit.

OpenBCI Daisy Module (Left) with OpenBCI 32-Bit Board (Right) along
with their male and female headers (bottom).

I started the assembly process by reading through the assembly instructions (with its pictures) as provided on the OpenBCI website.  Those instructions were good, though I thought that some additional illustration would be helpful to others.  Hence, the reason for today's post.

Parts and Components:  As you can see in the picture above, the OpenBCI boards themselves are fully assembled.  But, like many Arduino-style kits, you do need to solder on some pin headers in order to connect the boards together.  To make this easy, I found that the OpenBCI kit comes with the correct male pin header for the Daisy module as well as the correct collection of female headers for the base OpenBCI board.  Great!

A Trick for Soldering Headers:  I started by looking to solder the female headers to the base OpenBCI board.  Based on my experience soldering headers to various Arduino kits, I know that soldering the female headers can be annoying because it is hard to hold the header in place while your two hands are already busy holding the soldering iron and the solder.  To overcome this problem, I used a trick that I saw a while ago where you use a solderless breadboard to hold your female headers vertically in place, hands-free.  It's pretty sweet trick.  In addition to a solderless breadboard, you need some cheap double-ended pins (see below left).  I got mine from Adafruit, but they are standard items available from a number of vendors.  I only ever this pins for this soldering trick, so I bought them once and they've lived in my toolbox ever since.

Use double-ended extra-long pin headers along with a solderless breadboard as a trick to hold
the female headers in place.  The long pins will go into the bread board.  The short stubs off
the top of the female header get soldered into the OpenBCI board.

As seen in the picture on the right, above, you stick the extra-long headers into the female header that you are looking to solder to the OpenBCI board.  Then, as shown in the picture below, left, you stick the extra-long headers into the solderless breadboard, which leaves the short pins (which are the solderable part of the female header) sticking up in the air.

Use the extra-long pin header to hold the female header onto the solderless breadboard.
Then flip the OpenBCI board upside-down and place the OpenBCI board onto the
solder pins of the female header.  You're ready to solder those pins!

Soldering the Female Headers:  Now, you can place the OpenBCI board over those solder pins (see the right picture, above).  Note that the OpenBCI board has been flipped over so that it is face-down.  It's important that you solder the header onto the correct side of the board!  Once you have confirmed that everything is sitting correctly, you can start soldering.

Soldering each one of the pins in this header.
Then repeat for all of the other headers.

After repeating this process for all of the other female headers, the base OpenBCI board is fully prepared.

The base OpenBCI 32-bit board is finished.

Preparing the Daisy Module:  With the base OpenBCI board finished, I turned to the Daisy module.  Here, you start but using your pliers to snap apart the single, long, male pin header into the smaller pieces needed to fit into the different spots of the Daisy module.

Prepare the male pin headers for the Daisy board.  Snap the long pin header
into the correct number of pieces.

Use the Base Board as Your Fixture:  Then, as before, it can be tricky to solder these headers when your hands are full with the soldering iron and solder.  The tick this time, is to use the base OpenBCI board itself as your fixture.  This is a classic trick for soldering Arduino shields.  As shown in the picture below, left, insert the male pin headers into the base board's female headers.  Do this for all of the male headers that you will solder to the Daisy module.   Once they're in place, you can simply place the Daisy module onto the pins (see below, right) and everything will be nicely aligned and ready to solder.
(Left) Insert the male pin headers into the female headers that were just soldered into
the base OpenBCI board.  This holds them in the right place.  Then, place the Daisy board
on top so that you can solder the pins into the Daisy board.

Solder the Daisy Module:  With the pins all in place, solder the headers into place.  With everything so nicely held, this part is fast!  For me, it went so quickly that I forgot to solder one of the headers into place.  Ooops!  So, I went back and soldered the remaining pins.  No problem.

Soldering the pins to the Daisy board.  Be sure to solder all of the pins on all
of the new headers (I forgot one header when I did it)

Ready for EEG:  With the last soldering complete, the two boards are mated and I'm ready to collect 16-channels of EEG.  This is gonna be fun!

I'm finished!

Follow-Up:  I measured the power draw of the system here.

Wednesday, May 7, 2014

Measuring Video Blink Rate with an Arduino

In my previous post, I used blinking videos on my computer to entrain my brain waves.  A key question, though, was whether my computer could play those blinking videos steadily.  If the blinking isn't steady, it won't entrain brainwaves that are easily detected.  So, in this new post, I show how I hacked a photocell and my Arduino to measure the blink rate that my computer is actually producing.  It's a pretty simple (and cheap!) setup and, as you'll see below, its data explains some of the important findings in my EEG data!

Measuring the Blink Rate From the Movies Played Back by my Computer

Using a Photocell:  My approach to measuring the video blink rate is to quickly and continuously measure the light produced by my computer screen.  I chose to use a photocell, mostly because I had one that came with my very first Arduino.  To learn how to use a photocell, I followed the tutorial at Adafruit.  It explains what a photocell is and it explains exactly how to hook it up to an Arduino.  The key is that you connect a photocell and a 10K resistor in series.  Together, they form a voltage divider.  Then, you connect one end to +5V and the other end to ground.  In the middle, at the junction between the photocell and the 10K resistor, you connect that point to the Arduino's analog input pin.  Pretty easy!

Wiring It Up:  To connect all of the bits together, I needed to solder a few things.  First, I gathered my components -- the photocell, some wire, and some shrink tube (to keep the soldered wires from shorting to each other).

The Components: A Super-Cheap Photocell, some Wire,
and some Shrink Tube.  The 10K resistor is not shown.

Then, I soldered the wires to the legs of the photocell and insulated them with the shink tube.  The photo below shows the components after this assembly.  Looks decent enough.

Fully Assembled.  This is the first version that I tried.  Notice that the back
and sides of the photocell are exposed.  This turned out to be bad.

Unfortunately, when I hooked it up to my Arduino, I found that I was not seeing any change in the light level from my computer screen.  After some playing around, I found that the photocell is sensitive to light from the back and sides, in addition to being sensitive to light from the front.  So, as seen in the photo below, I added another layer of shrink tube to block out the light entering from the back and sides.

Modified Assembly.  I added more shrink tube to wrap around the sides
back of the photocell.  You have to keep out that light!

Mounting Everything:  Once I had my photocell on those long(ish) lead wires, I connected it to the Arduino as discussed on the Adafruit site.  I then needed a way to hold the photocell close to the computer screen so that I could measure its blink rate.  As shown in the photo below, I found that my adjustable soldering fixture (sometimes called a "3rd Hand" fixture) works really well.  It works best if you position the photocell to be VERY close to the computer screen.

I held the photocell to the computer screen using a"3rd Hand" soldering fixture.
To record the photocell signal, I used one of the Analog Inputs available on the
Arduino that is the host for m OpenBCI shield.

Position the photocell to be VERY close to the screen.

Arduino Software:  If I'm going to use my Arduino to read the photocell, I need to some software for the Arduino.  My first step was to use the built-in Arduino example called "AnalogInOutSerial".  I then extended this program to report the actual resistance of the photocell under different lighting conditions ("ReadPhotocellResistance").  While either of these programs works fine to read the photocell, neither is clocked to read the values a steady pace.  If the sampling isn't steady, there's no way to know if the video blinking istelf is steady.  To fix this, you need to setup an Arduino timer.  Or, you could...

Integrate with OpenBCI:  The OpenBCI shield generates data packets at a very precise rate (I usually configure mine to sample at 250 Hz).  It could act as the clock to drive the Arduino to sample the photocell steadily.  So, I modified the OpenBCI Arduino sketch to read one of the analog input pins every time that it receives data from the OpenBCI shield.  It then appends this extra data value to the OpenBCI data packet and sends it to the PC.  Finally, I modified my OpenBCI GUI to receive the extra data and to include it in its log file.

Results:  I used this system to record the blinking produced by the blinking movies from my previous post.  Each movie was about 20 seconds long and each movie blinked at a different rate.  The digitized Photocell values are shown in the figure below as raw counts from the Arduino.  Clearly, this graph is a bit too zoomed out to see much of interest (though you can see the non-steady amplitude when at the fastest speed on the right).  We need to zoom in to see more detail...

Sample values recorded from the photocell by the Arduino's analog input pin. I played
my 10 whole-screen-blinking movies.  Each movie is about 20 seconds long.  Each movie
has a different blink rate -- from a 1 Hz white-to-white blink rate up to a 10 Hz w-w rate.

Zooming-In:  Excerpts from three of the movies are shown below.  In these plots, you can see that the light pulses recorded during the  3 Hz and 10 Hz movies look to be steadily paced, whereas the pulses in the 7 Hz movie looks much more irregular.  Based on this qualitative view, I'd say that the irregularity of the 7Hz movie might cause complications when used for EEG experiments.

Zoomed-In waveforms recorded from the photocell during my blinking movies.  Excerpts at three
different blink rates are shown.  The red and blue dots show features that I used to quantify each
movie's blink rate.  Note that the time scale is different for each of the movies so that you always
see 4 periods, despite their increasing speed.

Measuring the Blink Rate:  To better assess the steadiness of each movie, I setup a routine to quantify the blink rate on a blink-by-blink basis.  I did this by, first, computing the mean sensor value for the whole recording.  This is my threshold for deciding whether the screen is "white" or "black".  This threshold value is shown by the horizontal black line in the excerpts above.  Then, I detected when the signal crossed this threshold.  Each threshold crossing is shown as a blue dot in the figures above.  To compute the blink rate, I compute the difference between the dots.  The "white-to-white" blink rate is the difference between the red dots.  Alternatively, the rate at which the screen merely changed (either from white-to-black or black-to-white), I measured the difference between the blue dots.

Blink Rate Throughout the Test:  The plot below shows the results of quantifying the blink rate throughout the test.  In red, the plot shows the white-to-white blink rate.  In blue, I show the blink rate from both transitions.  As expected, the blink rate counting both transitions is twice as fast as the blink rate when counting just from white-to-white.

Blink Rate Measured for my 10 Movies.  The measured blink rate generally follows the expected blink
rate, though the measured blink rate exhibits unsteadiness at the faster speeds. The blink rate when
counting both transitions (whit-to-black and black-to-white) is especially unsteady at the higher speeds.

Unsteadiness:  As can be seen in the plot above, the blink rate is pretty steady for the first four movies (ie, speeds of 1-4 Hz W-W).  For the 5th movie (5 Hz W-W), the plot above starts to look messier, especially the blue line.  This means that the system is not playing back the blinking movie smoothly.  As we get into the faster movies (6-9) Hz, the blue line gets extremely messy.  Clearly, the system is unable to keep a steady pace of white-to-black and black-to-white transitions (the blue line), though the white-to-white period (the red line) isn't too as bad.  Funnily, at 10 Hz, note that the white-to-white blink rate gets very stable again.  It seems that at 10 Hz, the individual movie frames must be well-aligned with the natural update rate of the video system on my computer.

Relationship to EEG Data:  The whole purpose of this investigation was to see if my EEG results from my previous post (copied again below, for convenience) were reflecting properties of my brain, or if they were reflecting artifacts from imperfections in my computer's movie playback.  My main question with my EEG data is why I exhibited no video-entrained EEG signals above 10 Hz.  Well, looking at the graph of the computer's blink rate (above), we see that the video blink rate becomes extremely unstable for any frequency above 10 Hz.  My computer, in other words, was unable to generate steady visual stimulation above 10 Hz.  Without stable stimulation, my brain had nothing to entrain with.  Therefore, these limitations in my video system mean that I cannot declare either way whether my brain can entrain with visual stimuli at speeds greater than 10 Hz.  With a more stable video system, maybe I could entrain with the faster blinks.

EEG data shown in my previous post.  This is the signal recorded from the back of my head (reference
on left ear) when staring at my blinking movies.  The signals marked by the blue arrows seem to indicate
periods when my brain entrained with the video on every transition of white-to-black and black-to-white.
The periods marked by the red arrows seem to indicate periods when my brain entrained on just the
white-to-white blink rate.

Next Steps:  With this system, I have proven that I can assess the steadiness of my video playback system.  Steady playback is critical to inducing visual entrainment of brainwaves.  So, as I move forward with trying to create a BCI based on visual entrainment, I can use this synchronized photocell recording to confirm that the video stimulation is sufficient to (hopefully) induce EEG responses.  Let the development of the visual BCI begin!

Saturday, January 18, 2014

EEG Electrode Adapter - Version 2

As many people are aware, many commercially-available EEG electrodes use an unusual connector called a "touch-proof" connector.  If your EEG system does not use these connectors, you need to either replace the connectors on the electrodes, or you need to make an adapter.  While it is a sensible choice to cut up your electrodes, I prefer to make an adapter.  My previous version of such an adapter worked really well, but it was a bit fragile.  So, I decided to try again.  I also decided to work with a friend of mine who's a little smarter about these kinds of things.  Here's what we came up with.

My Revised EEG Electrode Adapter ("V2") attached to an OpenBCI Board

Problems with the Previous Version:  The picture below shows my previous version of the adapter.  The good part was that the adapter was really small.  I liked that.  The bad part of this adapter (in addition to the fact that I never finished all of the connections) was that it was quite fragile. Specifically, the soldering of the wire to the female connector had no strain relief, which meant that mating the connector always threatened to break the wiring.  Another problem was that I was always confusing which electrode I had plugged into which input on the OpenBCI board.  I really needed to remake the adapter so that it was easier to see which were the "special" connections (SRB, Bias, and 8P) versus all of the "normal" connections (1N-8N).  These are the deficiencies that I focused on in this revision.

My First Attempt at an EEG Electrode Adapter ("V1")
Revised Approach:  With this iteration, my friend and I decided that it would be best if the female touch-proof connectors were mounted to some sort of rigid frame instead of merely being attached to the ends of the wires.  This would give the strain relief that we needed when mating and de-mating the connectors.  To address my other issue -- getting the connections confused -- I decided to use color-coded connectors, instead of just the black connectors in my first build.  Easy.  Ok, let's go!

Parts:  The parts are all the same as in the first build.  The female touch proof connectors are P/N 36145 from Plastics One.  The ribbon cable is just a set of female-female jumper wires from Adafruit (P/N 266).  This time, we also used a piece of scrap plastic channel that we had lying around, probably originally from McMaster-Carr.  And, as you'll see, I used a thin scrap piece of plastic sheet and a wide piece of shink tube, both from our generally pile of "goodies for a future project".  None of these pieces (except for the female touch-proof connectors) are particularly critical, so use what you have.

Assembly:  My buddy who came up with the idea of using the plastic U-channel as a mounting plate did all of the of the assembly.  He started with drilling a bunch of holes in the U-channel into which he pressed in the female connectors.

Touch-Proof Connectors Mated to the U-Channel -- For Strength!

He then took the purchased wires, pulled off (as a group) the number of wires that we needed and cut the existing connectors off one end.

Inexpensive Jumper Wires Used for My Wire Bundle

To keep the individual wires from splitting themselves off the ribbon, he reinforced the ribbon with a flat piece of plastic and a big piece of shrink tube.  Here's him preparing the items.  The red thing is the big shrink tube and the yellow-ish thing is the scrap bit of flat plastic that he'll use for the reinforcement.


Preparing the Shrink Tube (Red) and Scrap Plastic (Yellow)
to Reinforce the Wire Bundle

With the wire bundle prepared, he soldered the individual wires to the back of the touch proof connectors.  He used some normal size shrink tube to protect the individual solder joints on the back of the connectors.  Very nice.

Connecting the Individual Wires to the Back of the
Touch-Proof Connectors.

And that's all there is to it.  A picture of the completed unit is below.  You can also see it attached to an OpenBCI board at the top.  In the picture below, you can see how reinforcing the ribbon cable was an important feature for keeping the wire bundle from falling apart.

The Finished Adapter.

Pin-Out:  For anyone wondering why I used the unusual color scheme for the connectors, the idea is to clearly indicate that some of the electrodes have different functions.  So, if you use this adapter to connect to the OpenBCI V2 board as shown in the zoom'd picture below, or like the one at the top of this post, the order of the connections is this, from left to right:

   Red: Bias  (aka. driven ground)
   Blue: 8N  (the regular input for channel 8)
   Red: 8P  (the reference input for channel 8, if selected in software)
   Blue: 
       7N  (the regular input for channel 7)
       ...
       1N  (the regular input for channel 1)
   Red: SRB2  (the reference input for all channels)

Further Revisions:  After working with this revised piece for a bit, I found that there is still room for improvement.  For example, in connecting the adapter to the OpenBCI board, it is important to connect the wires in the right order.  The right order is shown below.  At first, I thought it was a good idea that I kept the individual female pin connectors on each wire of the adapter.  I thought that I'd like the freedom and fllexibility that this might provide.  I was wrong.  I should have swapped out the individual female pin connectors for a ganged female connector that would have kept them all in the right order all of the time.  I was wrong.  (So, to the EEG hacker that I'm handing this adapter off to, sorry for the annoyance!).

The Correct Order for the Individual Wires.

So that's the story of the hacking of this electrode adapter.  The real solution, of course, would be to have the connectors on the electrodes and on the EEG system (OpenBCI, in my case) be the same.   The easiest thing would be to put female touch proof connectors on the OpenBCI board.  But, the PCB-mount version are almost $2/each, even in quantity!  This is completely incompatible with the price of the OpenBCI board.  So, the next option would be to buy electrodes with a connector system that we could afford.  That would be a really nice solution to this problem of making kludge-y adapters.

Tuesday, November 12, 2013

Making an EEG Electrode Adapter

My earlier post on making my own EEG electrodes was surprisingly popular.  Thanks, all!  But, for some folks, it might just be easier to purchase EEG electrodes off the shelf.  If you buy your electrodes, they're likely to come with connectors on the ends.  In order to use these electrodes with an OpenBCI board, you'll need to either cut the connectors off, or you'll need to make an adapter cable.  Since I tend to play with a variety of electrodes (both EEG and ECG) and since many types of electrodes use this same connector, I thought that it would be good to make an adapter.  This post is about how I made my adapter cable.  Here's what it looks like when I was done.



Parts

To make the adapter cable, you need the connectors that mate to the EEG electrode, you need some wires, and you need some connectors that mate to the OpenBCI board.

The OpenBCI board simply uses pin headers with a 0.1" spacing.  Therefore, for "connectors", you can use any of the inexpensive jumper wires that are used throughout the hobby world for connecting to Arduino.  For this adapter cable, you need female pin headers.  Adafruit sells a fine pack of 40 female/female jumper wires (P/N 266) for $6.95.  The 40 wires come with the connectors already attached.  The wires also come attached to each other as a ribbon cable, which is very convenient for keeping the cables in order.

Female/Female Jumper Wires from Adafruit
For the EEG electrodes, they usually use "touchproof" connectors.  This are simple singe-conductor connectors where the metal part is completely shrouded in plastic.  They are fairly standardized, though the diameter of the connection can vary between 1mm and 2mm.  All of my electrodes are 1.5mm.  The jacks that mate to these electrodes can be purchased from Plastics One.  Specially, I chose to buy the panel mount, front-loaded, threaded connectors (P/N 36145) shown in the pictures below.  When bought in small numbers, they're $3.14 each.  That's pricey!

Jacks for Touchproof Connectors.  From Plastics One.
Assembly

The OpenBCI board has 11 connections that I might want to use.  So, I took the ribbon of 40 jumper wires and peeled off a single strip that contained 11 wires.  I then cut it in half to that one end had the female pin headers and the other end was just wire.


Then, I peeled apart the ends of the wire and stripped the ends.  As I prepared to solder on the touchproof jack, I slipped a piece of shrink tube over the end of the wire so that I could make it look nice when I was done.  I'm proud of myself for remembering to do the shrink tube.  I nearly always forget.  Not this time!

Preparing to solder the first jack.

After I soldered it on, I pulled the shrink tube up over the joint, applied some heat, and got a nice looking connection.

First jack is attached.  Nice use of shrink tube!
I then repeated the process for all the other wires that I was going to use.  Here's a picture of me soldering on the second jack.

Preparing to solder the second jack.
Completion

For my immediate testing, I did not need all 11 connections...I only needed four.  So, I only soldered on four jacks.  You can see my "completed" adapter cable assembly below.

My adapter cable with 4 connections.  I'll add the others when I need them.
Note that I added a piece of electrical tape around the ribbon cable to help keep it together.  I had overly separated one of the individual wires and it was threatening to come loose.  I little electrical tape saved the day!  And it makes it look fancy.

Using It

As you can tell by the photo at the top of this post, the adapter cable works great for interfacing OpenBCI to off-the-shelf electrodes.  I've used it with my EEG electrodes for follow-on measurements of my Mu-waves and with my ECG electrodes for checking my heart signals.  It's a great adapter cable to have in my EEG Hacker toolbox!