kitschpatrol / Brain

Arduino library for reading Neurosky EEG brainwave data. (Tested with the MindFlex and Force Trainer toys.)
http://frontiernerds.com/brain-hack
GNU Lesser General Public License v3.0
745 stars 151 forks source link

Raw values #7

Closed steeph-k closed 10 months ago

steeph-k commented 10 years ago

Hi!

Has any work already been done regarding raw EEG values from the ThinkGear module? Switching the mode works, so I do get values that look like ThinkGear packets at 57.6k. But the routine provided by the library is not able to parse them. I'm not sure where to start to adapt it to work with the different packages. I'm still trying to understand how the code exactly does what it does.

If anybody could give me a hint, that would be awesome! Thanks!

kitschpatrol commented 10 years ago

Hi @steeph-k , can you explain how you switched the mode to deliver raw data? I remember looking into this ages ago but lost steam. If I can get the mode to switch I'll see about updating the library. Thanks!

steeph-k commented 10 years ago

That would be really great!

The output modes are briefly described in the TGAM spec sheet[1].

I first tried to solder the bridge as described in the spec sheet. But, you know, the pads and the resistor are tiny, I couldn't do it. To switch the output mode in software, you just have to read one or a few of the packages at 9600 baud and then send the code of the output mode you want to switch to[2]. Nothing else should be sent to the module or it will stop working (until it's switched off and on again). After that, you'll receive data at 57600 baud. If it doesn't work, see which firmware version your ThinkGear module has. There are different commands for older modules[3].

I've planned to look into this again because I hope I'd figure out how to change your code so it parses also raw data. But currently I have a different EEG to play with, so it could take some time.

[1] http://wearcam.org/ece516/neurosky_eeg_brainwave_chip_and_board_tgam1.pdf [2] Serial.println(0x02); [3] http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#thinkgear_command_bytes

gpascualg commented 10 years ago

Has any progress been done with this? I will soon receive my mindflex and would happily collaborate and help.

I personally find this way: http://morloklabs.blogspot.com.es/2011/12/mindflex-duel-hacking-conversion-50hz-y.html?m=1 Pretty neat. Not only it's persistent but allows to easily switch modes.

I have also taken look at that documentation [3], but I can not figure anything clear out of it.

Thank you for your great work and effort! I will post if I find anything at all, thought it may take some time, as I am planing to use HC-05 to transmit over BT!

steeph-k commented 10 years ago

There is an Android app that lets you display and record the raw value (and the other values). If you are using bluetooth anyway, this may be a way to test whether everything is right on the hardware side. https://play.google.com/store/apps/details?id=com.isomerprogramming.application.eegID

My problem was that I didn't manage to set the correct baud rate of the HC-05. So it seemed to work with a cable, but I had no software to parse the data. I had to return my loaned other EEG. So I might look into this again soon. But I'm not sure whether I can help, since I really don't know what I'm doing there ;)

gpascualg commented 10 years ago

I still don't have the mindflex, nor the arduinos, nor the HC, but whatever, I have programmed a little bit at that's what I got: https://github.com/blipi/TGAM1-EEGReader

If someone can try it an tell, it might work with raw data too. At this moment it only works (should work) with HC-05 and TGAM 1.7 firmware version (TGAM board rev 2.8, Mindflex duel). It requires both T and R pins of the TGAM to be soldered to an arduino, as to be able to serialy send configuration commmands.

Tomorrow I'll add some schematics to the git README.

kitschpatrol commented 10 years ago

Sounds great @blipi, thanks for the update.

ThomasDotCodes commented 10 years ago

I'm thrilled that this thread has some more activity. I successfully modified a MindFlex headset using this as a guide: http://darrenmothersele.com/blog/2013/10/07/mindflex-raw-eeg-data/

After a few small changes, I was able to get the standard "BrainSoftSerialTest" running, although it's obviously not parsing the data correctly. Not sure exactly where to start, although I have a feeling it's closely related to lines 166-171 of Brain.cpp (parsePacket function) and then the corresponding readCSV function.

Is there more to it than this? Happy to provide any sort of test data or etc. that might help. I'm connected directly to an arduino, no bluetooth or anything.

gpascualg commented 10 years ago

My mindflex is still in shipping process, so I can't really be of much help, but if you can, add some more debug messages. Raw value should be in 0x80, and theorically in the following format: <0x80> <length (2)> <MSB> <LSB> However, as reported here: http://morloklabs.blogspot.com.es/2011/12/mindflex-duel-hacking-conversion-50hz-y.html?m=1 The following is received: <0x80> <length> <0xfd> <0xFF> <MSB> <LSB> Which is not the expected value. I have no clue on what that 0xFD 0xFF is.

Try and change line 169 (++i) to, somehow, record the value. You could try something like: sprintf(latestError, "Length: %d", packetData[++i]) Comment other latestErrors so that it doesn't get overwritten.

I've done something similar here: https://github.com/blipi/TGAM1-EEGReader/blob/master/EEGReader/Brain.cpp#L174 (Note that brain class is not exactly the same, but based on this one)

According to documentation, it should say "Length: 2", but as morloklabs say, it will report 4. Printing the length (2, 4, w/e) following bytes would be useful too.

I don't really understand however how the raw value is output by the TGAM1. Here: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#raw_wave_value_16-bit Is told that it is a 16 bits value, however on the configuration section: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#firmware_16_command_byte_table The RAW value can only be configured to be either 8 bits or 10.

EDIT: You could also try: https://github.com/labe-me/ofxThinkgear/tree/master/src Which seems to be more flexible than Brain, as you must implement you own "code handling method", as it's done here in the example: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#thinkgearstreamparser_c_api

ThomasDotCodes commented 10 years ago

Thanks, this gives me plenty of ideas to keep me busy. I'll try to look deeper into the 0x80 raw response and see what's going on.

gpascualg commented 10 years ago

In case you need it, I implemented that ThinkGearStreamParser on my git, you can check it in this commit: https://github.com/blipi/TGAM1-EEGReader/commit/167c8119367513981e9b1d549f08c8e5c56188c1

Good luck ;) I'll test it as soon as I recive mine!

gpascualg commented 10 years ago

Well, good news, it's working: https://github.com/blipi/TGAM1-EEGReader

I'm using two arduinos with bluetooth, but it should work just fine with one.

zombodotcom commented 9 years ago

Hey, I got a mindflex duel, so 2 headsets, I'm only testing one headset so far, I turn the headset on and I can get data for a few seconds on the braingrapher with an arduino, then I'm getting 200,0,0 some other guy had the same question and I asked him on twitter with one question and he blocked me for some reason? I get a few seconds of data every time I turn it on and off again then it cuts out to 200,0,0

Any ideas ? I'll try the other headset when I have time

steeph-k commented 9 years ago

How is the headset connected? Is it using a common ground with the Arduino? Just an idea.

sicklebrick commented 9 years ago

Too much noise that way, use an optoisolator/optocoupler to connect the mindflex to the arduino and you'll get an awesome signal.

On Fri, Jul 24, 2015 at 5:53 AM, steeph-k notifications@github.com wrote:

How is the headset connected? Is it using a common ground with the Arduino? Just an idea.

— Reply to this email directly or view it on GitHub https://github.com/kitschpatrol/Brain/issues/7#issuecomment-124328005.

gpascualg commented 9 years ago

I am using common ground, but of course as @sicklebrick says an optoisolator between both would be the ideal way to avoid having noise.

zombodotcom commented 9 years ago

Yes it is on the ground pin of the arduino , the funny thing is that when I unpower the arduino it still has lights blinking while is connected to rx and gnd !

zombodotcom commented 9 years ago

Anyone know why I'm gettinga few seconds of data then it cuts out to 200, 0,0 using rx pin and gnd

Riteshlogin commented 8 years ago

@zombodotcom I know this is a bit late, but it will only give you 200 if the TGAM feels that the electrode is not contacting any skin.

I have my own question. So I managed to get my hands on some standalone TGAM modules that were already hardware-configured at the 57.6k baud mode. I am giving the TGAM a proper amount of power, I have ear clips attached as reference electrodes and another electrode for my forehead. I then uploaded the sample code to an Arduino and started reading the data.

However, though I am constantly getting meditation and attention values, I never seem to be able to get alpha, beta, and gamma values. They only really come once in a blue moon. Has anyone else had this problem before?

gpascualg commented 8 years ago

@zombodotcom As far as I remember (not much really...) there are 2 ways of setting the mode (aside of the baudrate):

  1. By soldering a contact on the board, in which case you will have to research which and unsolder/solder it.
  2. If not manually overriden by 1), you can tell the TGAM module to give you the values, see:

Basically, it has the RAW output disabled, which are those alpha/beta/gamma values

Riteshlogin commented 8 years ago

But I do receive alpha, beta, gamma, etc. values. But only very rarely, whereas I have read that it is typical to get them at least once every second.

I'm definitely going to look through your code, though. Thank you for posting that.

gpascualg commented 8 years ago

Oh, I though you did not receive them at all. That's strange, it might be related to the signal strength, have you checked it? I believe it will only send those values if it is confident the signal received is strong enough.

On #12 some methods to improve the signal are discussed, try them too just in case.

Riteshlogin commented 8 years ago

And is a signal quality value of 48-52 normal? That's what its been fluctuating around for me.

I'll let you know if anything on that thread you posted works.

steeph-k commented 8 years ago

I've linked the spec sheet with descriptions on how to change the mode in the beginning of this issue: https://github.com/kitschpatrol/Brain/issues/7#issuecomment-37422069

Alpha, beta, gamma etc. values are not raw data. Raw output means actual raw values, not FFTed values.

Riteshlogin commented 8 years ago

Again, I actually do manage to receive alpha, beta, and gamma values, so I don't need to change the mode. It's not that I cant receive them, it's that they don't come as nearly as often as the documentation says they should (about once per second).

steeph-k commented 8 years ago

I understand. Sorry, I've never had this problem. My comment was more meant for gpascualg because it sounded like he confused those with raw data.

gpascualg commented 8 years ago

@steeph-k True, it's been a while since I last played with the TGAM =P. Still, the links on https://github.com/kitschpatrol/Brain/issues/7#issuecomment-228798284 also contain code to change to FFT mode instead of RAW.

gpascualg commented 8 years ago

@Riteshlogin According to http://developer.neurosky.com/docs/doku.php?id=helloeeg_adobe_flash_tutorial signal strength goes from 0 (perfect) to 200 (bad).

You should, theorically, be reading 0. Any other value should indicate the signal is not as strong as required: http://www.darrenmothersele.com/blog/2013/09/21/brain-wave-visualisation/

That said, you can try using opto-isolators, grounding it somewhere else (I, for example, did not ground it to the arduino itself but to the battery pack, so both the arduino and TGAM where directly grounded to the battery).

Riteshlogin commented 8 years ago

@steeph-k My apologies for misunderstanding you!

Riteshlogin commented 8 years ago

Welp, I just gave the TGAM datasheet another read and discovered that I had been speed reading over the part where it says that shielded wire is necessary for the electrodes. I'm fairly certain now that that was my problem.

penco193 commented 7 years ago

Hi!, i have a mindflex game with ThinkGear module rev 2.7. any of you can tell me if the firmware version is 1.6 or 1.7 for this board?, or where could i find it?. any help will be appreciated

TimoteoMendes commented 6 years ago

Hello,

I am trying to use a simple tester just to see the raw data, but most of the time the values have error in crc or long. The @gpascualg has way to much code for what i need. Is it possible to find out the firmware version? I have the rev2.9 board. Thanks

kitschpatrol commented 10 months ago

Thanks for the conversation. Closing this as it's quite old.