Friday, September 11, 2015

Logbook 9/11

This week I worked on attempting to graph the incoming data from the TGAM brain chip over Bluetooth. The data comes in as a string in the specified format below with values being from 0 to 131072 (I think)

freqs = [single strength, attn, relax, delta, theta, alphaL, alphaH, betaL, betaH, gammaL, gammaH]

The signal strength should be low to indicate a good connection, 200 means there is brain waves getting picked up. I wrote a python script to capture the data (Bluetooth serial connected on COM8 on my computer). The script breaks down the data into an array and the plots the values.






Attention and relaxation values I believe are the most important. These are computed within the chip itself from the values of the following frequency bands. For a more accurate or fine-tuned approach, we could monitor the frequency bins as well. The values of attn. and relaxation have a smaller range, 256 being the max, therefore the other values are plotted off the visible area.

For some reason, at times when a certain frequency value goes to high, python prints “ERROR: packet too long” rather than the actual data. To get rid of this messing things up, the script looks to see if the letter ‘E’ is in the incoming data string first. If it is, it just ignores it. No good data should ever have the letter E in it since the TGAM chip only sends a string of numbers and commas.





#Python Analyzing Program
import serial
import numpy as np
import time
from matplotlib import pyplot as plt
ser = serial.Serial('COM8', 9600)

plt.ion() # set plot to animated

line = [None] * 10
ydata = [0] * 50
attn = [0] * 50
relax = [0] * 50
delta = [0] * 50
theta = [0] * 50
alphaL = [0] * 50
alphaH = [0] * 50
betaL = [0] * 50
betaH = [0] * 50
gammaL = [0] * 50
gammaH = [0] * 50

freqs = [attn, relax, delta, theta, alphaL, alphaH, betaL, betaH, gammaL, gammaH]
shades = ["#800000", "#000066","#66FFFF", "#66CCFF", "#99CCFF", "#9999FF", "#CC66FF" , "#FF66FF", "#FF3399", "#FF0066"]
ax1=plt.axes()

# make plot
i=0;
for x in freqs:
    line[i], = plt.plot(x)
    plt.ylim([10,40])
    i+=1;

# start data collection
while True:
    data = ser.readline(); # read data from serial
                                   # port and strip line endings

    if(data.find('E')==-1):
        print data
        data = data.split(",");
        if data[0] != 200:
            ymin = 10;
            ymax = 200
            plt.ylim([ymin,ymax])
            j = 0;
            for f in freqs:
                if(j==0 or j==1):
                    line[j].linestyle='-';
                f.append(data[j+1])
                del f[0]
                line[j].c = shades[j]
                line[j].set_xdata(np.arange(len(f)))
                line[j].set_ydata(f)  # update the data
                j+=1;
            plt.draw() # update the plot

            print "receieved"
            time.sleep(.5) 





Friday, September 4, 2015

Logbook 9/4

We have split up into sections; Mustafa and Mario are working on getting the TGAM chip which we harvested out of the MindFlex toy to work. It seems like the chip is very sensitive to voltage differences and bad ground.

http://store.neurosky.com/products/mindflex












We know the chip is good because we previously tested it using the toy. There is a ‘game board’ with a fan which runs at a variable speed based on your brain patterns, when you take the headset off or don’t connect it on your head right, the panel voices outloud “CHECK HEADSET”

Mario and Mustafa are trying to get the game to work using our electrodes. Since we disassembled it, using the original electrodes doesn’t even seem to work anymore. When monitoring the serial output from the chip, it reads  “200, 0, 0”. From the TGAM datasheet we know that the 200 indicates a too weak EEG signal.


Luckily, I ordered two of these Mindflex games so I am using the spare one to work on the code that will analyze the brainwaves. With the second game, I did not disassembl the headset, but just soldered in two wires for Tx and Gnd as to get the serial brainwave data. Originally I connected these to an Arduino and attempted to echo the data to the usb serial interface that comes with all Arduinos. Oddly enough…….. as soon as you connect the Arduino the “CHECK HEADSET” error reappears. I tried powering the Arduino with a 9V battery rather than the usb port, and the headset made the connection to the game board okay. When I connected the usb cable to capture the data…… the connection dropped and the game board once again went into “CHECK HEADSET” mode. I tested plugging and unplugging the Arduino to see the results, and it seemed that the brain connection would be lost everytime I plugged it in, but the connection was re-established when I disconnected the cable. My conclusion was that there must be some uncommon ground error between the TGAM chip and the laptop, perhaps we can fix Mario and Mustafa’s problem by checking their ground lines and powering their Arduino from a battery as well.

Our final product does not need to be connected to a computer, all brainwave processing will be done onboard with the Arduino. However, for testing we need to know what the thresholds of sleep brainwaves are, so I used a Bluetooth module to send the data out over wirelessly. It worked!



/* Echo Serial data to bluetooth */ 
#include <"softwareserial.h"> 

 SoftwareSerial mySerial(6, 7); 
 // RX, TX to TGAM 
//dedicated Tx and Rx to bluetooth 
 void setup() 

 // Open serial communications and wait for port to open: 
 Serial.begin(9600); // set the data rate for the SoftwareSerial port 
 mySerial.begin(9600); 


 void loop() 

// run over and over 
 while(mySerial.available()) 
 { 
 Serial.write(mySerial.read(); 
 Serial.println(); 
 } 
}

Friday, August 14, 2015

BiWeekly/Logbook 8/14

Hello! So we’ve come to a unanimous decision that we will try to purchase a premade amplifier/filter if we can find one under $30 at all costs. In the case that we can’t obtain this, we plan to re-evaluate the approach we are using and use a sensitive motion sensor to track blinks rather than look for brainwaves.


I found an integrated chip called the TGAM (it I more than just an IC, it’s a actually a small pcb) that
is sold by the company Neurosky. This chip takes V+-, reference ground, and 1 electrode input. The electrode is meant to go on the forhead while the reference can go somewhere else on the body, although the manufacturer recommends the ear lobe. The chip processes the input on board and outputs. The Neurosky website lists the following specs on the chip

  • Raw sampled wave values (128Hz or 512Hz, depending on hardware)
  • Signal poor quality metrics
  • eSense Attention and Meditation meter values
  • EEG band power values for delta, theta, alpha, beta, and gamma

The chip comes programmed with NeuroSky eSense, A/D, amplification off head detection, and noise filtering for EMG and 50/60Hz AC powerline interference

The following sites have more information

All these things, especially the filtering, were things we failed to get working in out homemade design. It is our hope that this chip will solve our immediate issues and get us back on track. The output goes out as uart at 1200, 9600, or  57600 output baud rate, so easy for the Arduino to handle! The website did not have a list price, only prices for the full headsets that Neurosky develops. I sent them an ‘inquiry’ but they ignored me; instead I ordered a toy off of amazon that uses the TGAM chip, this toy is commonly used for diy bloggers and interfacing it with other things is well documented on many websites. (The MindFlex Toy)

On another note: did you know EEG actually stands for Electroencephalogram? I learned this from the neurosky website.

We’re meeting up on Monday (hopefully) to go over our presentation, we can’t be sure if we’ll have much to show off, but we’re going to film a short clip explaining our project and then itegrate into videos of the working machine (like an advertisement) later down the road. 

Friday, August 7, 2015

Logbook 8/7

We actually began using the 'electrodes'that we etched onto a pcb board. My group seems to have made no progress on any filtering, so I figured it would be best to see at least if the electrodes picked up any signal at all. Surprisingly, they did. Mustafa and I met in the lab downstairs and actually connected them up to my head, bringing each node down to a instrumental amplifier (in difference amp configuration). We actually saw results on the scope (didnt take pictures, we will next time)


Unfortunatly the signal is swamped by noise, we could not use autoscale but had to adjust the settings manually. We also tested the probes using a 100mV test signal, even this could not be found with autoscale. After this, we wanted to see if there were any spikes caused by blinking, we set the scope to track min and max of the signal, but somehow the data got corrupt and scope the claimned the max was 160V or something ridiculously high. There is only +-5V being supplied to the amp so obviously that was ridiculous. We need to adjust the output to be from 0-5V.

Friday, July 31, 2015

Logbook 7/31


 On Monday Mario and I met at his gym and he gave me the breadboard with the amp circuit built on it. He didn’t have a potentiometer so just included the last two needed resistors on the side so I could put them once I got a potentiometer. On Tuesday in Addison I went down to the lab and ran some tests.


I inputted a 100mV sinewave signal to the side where the electrodes would attach, and attached a scope probe to the output. The circuit requires +9v, -9V, and ground, luckily they do have a power supply in Addison capable of such.   I was sad to find out that the output was VERY fuzzy, and only around 100uV amplitude. I tried first at frequency of 10hz, then at larger frequencies, and the amplitude increased to 1mV as the frequency rose.

This indicates our filter is backwards, being a highpass instead of lowpass, but I don’t understand why this would be the case. I put the scope probe at different spots on the chain of amplifiers (ordered as follows: 60hz, lowpass, highpass, high gain amp). The signal became weaker after every section! There was no signal at all after the high gain amp, something was simply killing it.
I triple checked the circuit with the schematic and could findno problems.


I am going to try to get a high gain amplifier working and disregarding the filters for now. Amplification in the most import part. Hopefully Mustafa will be able to meet with me this week.


Friday, July 24, 2015

Logbook 7/24

We met on friday to begin buildling the filtering circuit for the brainwaves. This circuit has been a bottleneck in our progress because it is behind schedule, and nothing else can be done until we have it at least half-working! We met in Mario's lab and brought out the schematics, Mario has many resistors and it was a pain digging to find the right one.
Mario plans on finishing it monday afternoon and handing it over to me by the evening. On tuesday I want to run some tests on it.

We did order a new opamp chip more similar to the one they use on instructables, where we got our schematic. This one is dual supply, so we should be able to get the negative swing of the signal.  Because we have to use the instrumental amplifier first, which MUST be done using negative and positive voltage, we figure itd be best to just make the second opamp be the same. Otherwise, with biasing and all, it may be a mess. 
http://www.instructables.com/id/DIY-EEG-and-ECG-Circuit/



Friday, July 17, 2015

Logbook 7/17

We got in our lithium battery 'charger' that we ordered this week. Although we dont plan to implement this piece til the end, we though ahead and realized that most users of our device may not have an easy wasy to charge their product unless we provide them with a hookup. The module we purchased connects via usb and regulates current to the the lithium battery (we assume all consumers will have access to a 5V usb jack). Tte device is the size of a small cracker.  Furthermore, we still havent gotten our filter put together, but Mustafa has been doing simulations on different filter designs. Hopefully we get something working by next week.
After we get the filter/amplifier working, we can examine the signals that we get and possibly use a frequency to voltage IC chip to detect frequencies rather than our complex sampling code. Unfortunatly, the oscilliscopes in the Elab do not have spectrum analyzers built into them (or at least nobody knows how to find the spectrum analyer function) so we will still need to use the existing arduino sampling code to at least harvest some data to graph and examine.

 double pole (more components, better rolloff)

single pole, inverting and non inverting
**since our signal is bipolar, whether we invert or not doesnt matter much unless we use a DC bias.

schematic for DC offset to an op amp




Friday, July 3, 2015

Logbook 7/12

This week I did further research about our preamplifier circuit. After discussing things with Professor Krauss, I have determined that we probably will have to use at least some negative voltage. Brain waves are bipolar, and although we could use a DC offset, i feel like if we use that directly from the scalp we risk swamping the already faint signal with noise. I found a IC chip, the  ICL7660 that will easily just convert the +5v that we have to a -5 V.  It cannot provide high current, but we'd barely need any to power the op amp chips. I purchased 10 of these chips for 1.76 from china. We do not need this chips to construct the filter, we can just use a DC power supply, we'll only need the chips when we build the final prototype.

We'll add a DC offset right before the signal gets sampled by the microcontroller.
Hopefully we can construct this circuit ASAP using the schematic from instructables as is, we will have to include credit to the author of that article.



datasheet above.