Maker Pro

Hacking a Mattel Mindflex Headset for Brainwave Control

The basic idea, initially at least, is to take the data stream from the Mattel Mindflex game headset directly from the headset chip, then use the "Attention" value to control the speed and or direction of a small continuous rotation servo.

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
Hmmm. I thought the description would be visible with the pics.
This is it:-
The basic idea, initially at least, is to take the data stream from the Mattel Mindflex game headset directly from the headset chip, then use the "Attention" value to control the speed and or direction of a small continuous rotation servo.

The first pic is just a 'before' shot of the Mindflex headset:-

a. The headset.JPG


Second pic is a shot of the inside - the untouched board assembly:-

b. The boards.JPG


Third shows the wire attached to the headset's TGAM1 chip 'TX' pin, for extracting the data. Data is sent by the headset once per second, at 9600 baud.
I also attached a black wire to the headset's 0V battery connection, and a red wire to the centre pin of the switch, so that I get power only when the headset is switched on:-

c. Wires attached & Board Replaced.JPG


The fourth photo shows the re-assembled headset, with the wires sticking out:-

d. Headset reassembled.JPG


Number five shows my PIC16F84A-based test setup, used to ensure that comms is working OK.
The first thing in the headset's data stream is a pair of sync bytes, both 0xAA, so the test circuit simply tests for them and lights a LED if they're received OK:-

e. Testing Communications.JPG


I connected it up, powered up the headset, held my breath and..........the LED started blinking once per second. All good so far. :cool:

The full data stream that's available to play with is:-
'Poor Signal', (inverse of signal strength), 'Attention', 'Meditation', 'Delta', 'Theta', 'Low Alpha', 'High Alpha', 'Low Beta', 'High Beta', 'Low Gamma' and 'Mid Gamma'.

I plan to attach an APC220 433MHz RF module to the headset to send the serial data to an Arduino UNO, to avoid a cumbersome cable.

For parsing the data stream and extracting the values, I'll be using the Arduino Brain Library, by Kitschpatrol, available here:-
https://github.com/kitschpatrol/Brain

For a graphic display of the data, there's also a 'Brain Grapher' available, in 'Processing' language, but I can't get it to work due to library issues, so I've written my own little 'Brainwave Grapher' sketch in 'Processing', an 11-channel bargraph, for diagnostics and to help train my brain to concentrate and relax, for control over the "Attention" and "Meditation" outputs.

I've done all I can for now, until my Arduino UNO arrives in the mail. I'll update when I get the next stage working.
 
Last edited:

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
This is a screenshot of my 'Processing' brain wave grapher.
I forgot to include it.
In this shot, I was just sending simulated data from a PIC microcontroller:-

BrainWaveGrapher Screenshot.JPG
 
Last edited:

chopnhack

Apr 28, 2014
1,576
Joined
Apr 28, 2014
Messages
1,576
Looks good Steve! Nice graphical representation as well.
What happened to your avatar? Walkers get you?! :eek::p:D
 

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
Looks good Steve! Nice graphical representation as well.
What happened to your avatar? Walkers get you?! :eek::p:D
Thanks mate. I struck a little set-back, so have to sit on my hands for a couple of weeks and can't do anything - the headset is sending data OK, and I can parse and decode the whole stream without any problems, (it's only 32 bytes as I found), but it was only sending '0' for "Attention" and '0' for "Meditation". I noticed the zeros while bench-testing, but put it down to the fact that the headset wasn't on my head. When the output didn't change while I was wearing it, I knew it was a dud. All of the codes like payload length and the checksum were correct, so it was definitely the headset and not my firmware. The seller gave me an instant refund without any questions.
It seemed obvious that he knew it didn't work. :mad:

I ordered another from the US, from a seller who promised he's tested it with a game baseboard, so I just have to wait. It's given me a chance to brush up on my C programming skills and learn the ins and outs of AVR micros. I'd prefer to use pure C for most things in Arduino, while also taking advantage of all of the great libraries that are available. For instance, Arduino language doesn't give access to the chips internal timers etc. C is much faster when it comes to setting the data direction register or setting pins high/low and so on, too. All AVR C code that I've tested has been fine in Arduino, especially direct register access.
I installed AVR Studio and have been playing with it a fair bit, so I'll be 'well-armed' by the time the new headset arrives. :)
Edit: And in the end, I didn't need the Arduino Brain Library after all. I managed to decode the data stream with a PIC using PICBasic Pro. The 3-byte ASIC_EEG_POWER values were a little tricky with only 16-bit support, but I only need the high byte anyway, for a graphical representation of Alpha, Beta waves etc. There aren't enough pixels in the graph for the original high resolution. My graph bars are 255 pixels high.

Regarding the avatar, I figured it was time for a change of pace face. :D
 
Last edited:

chopnhack

Apr 28, 2014
1,576
Joined
Apr 28, 2014
Messages
1,576
The seller gave me an instant refund without any questions.
It seemed obvious that he knew it didn't work. :mad:
Shameful, but many vendors bank on non technical folks to buy things cheaply and not complain....

I'd prefer to use pure C for most things in Arduino, while also taking advantage of all of the great libraries that are available.
Agreed, from my limited experience, it seems easier to go this route for even the simplest things like timing and delays instead of coding them in ASM.

Regarding the avatar, I figured it was time for a change of pace face. :D
LOL @Old Steve - Halloween is coming ;-)
 

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
Halloween is coming ;-)
Ha ha.
And actually, we don't have Halloween here - it's an American thing.

Agreed, from my limited experience, it seems easier to go this route for even the simplest things like timing and delays instead of coding them in ASM.
There's very little need to do anything in asm. On rare occasion, a tiny bit of inline assembly in a C program is helpful, but otherwise I avoid it like the plague. :D

With regard to Arduino, there are benefits to writing in C where delays are concerned. An Arduino delay() freezes program execution until the period elapses. In C/C++, since registers can be accessed, a timer can be set then the program can continue execution until the timer overflows.
 

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
I got the new headset a couple of days ago. It works fine, but initially I had some problems with the signal. As I've now discovered, on the TGAM1 board theres a very tiny little jumper for setting a filter's mains rejection frequency to either 60Hz or 50Hz.

Since I bought an American headset, it was set to 60Hz, and the signal-to-noise ratio was very poor. The jumper was originally set with a low-value SMD resistor. @#$%, I can barely see things that size. I had to swap my reading glasses for high-magnification ones, then use a small magnifying glass as well to see what I was doing, but eventually managed to remove the link and replace it with one for 50Hz.
Bingo, if I get the forehead sensor positioned just right, I get a perfect signal now. :cool:

I used the 'Arduino Brain Library' for testing, with the parsed data stream returning to the Arduino serial monitor on the PC.

In the following, the first value is "Poor Signal", with 200 meaning no signal, and 0 meaning perfect signal. The second value is "Attention" and the third is "Meditation". The other 8 values are Alpha, Beta, Gamma etc waves. I don't need them right now. Just the "Attention" value.
Code:
0,    57,    38,    320951,54145,15337,11104,6471,3899,1753,18864
0,    54,    24,    539311,127431,3240,12891,33169,5205,1069,20539
0,    51,    51,    328670,21655,21318,8572,1012,671,488,6717
0,    48,    60,    203342,38314,12105,6901,1482,3111,568,6731
0,    41,    54,    1411918,578756,48854,106012,17346,11902,7988,69134
26,   41,    54,    269723,15807,15789,9218,3977,1269,1459,3199
0,    37,    61,    318648,239997,34410,14640,7444,4440,1023,13698
0,    40,    43,    184733,54446,12795,2399,1547,1366,509,5217
0,    37,    56,    108746,10177,17796,4038,3232,1108,260,3631
0,    37,    44,    550138,206536,12470,7269,8338,3719,1843,12957
0,    44,    54,    255843,10043,3544,2089,1834,1012,358,3631
0,    48,    69,    1824327,162300,159873,22179,21242,11533,2459,55362
0,    50,    63,    661340,65293,53679,5886,4894,6295,1821,15771

So I'm in business. :)
I had a short cable from the headset to the Arduino today, and it was pretty annoying, so next up I'll set up an APC220 433MHz RF transceiver module on the headset, to send the data wirelessly. I've made a tiny little LP2951-based regulator board to provide 3.5V to the RF module, with power taken from the headset's batteries.
I have to mount the RF module on the outside of the headset case, so it won't look real pretty, but that's not important.

Stay tuned for further updates......
 

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
I got the little LP2951 3.5V regulator nicely mounted. I hot-melt glued it to the underside of the RF module, which I'll mount upside-down. The whole thing is only a little over an inch long, so it won't be too intrusive attached to the outside of one side of the headset. I'll use Blu-Tak initially, and then if all is well I might even make a small plastic box.

The regulator side:-
RF Module with Regulator 1.JPG


The RF module side:-
RF Module with Regulator 2.JPG

I could have used a cheaper RF module, but I like these because I can set the frequency within a wide range to create different channels. I have a couple of these around the place performing different tasks, so that way they won't interfere with one another. (I have them on my workshop alarm system and my self-updating alarm clock, which is connected wirelessly to the PC. I never have to adjust it's time, not even for daylight saving. It has an RTC for when the PC is off, and an on-board micro automatically does the daylight saving thing)

These RF modules have good 'punch-through' and a great range, too. 50 metres guaranteed, and up to 1000 metres if line-of-sight can be achieved.The regulator is low-dropout, so it can provide 3.5V right down to a little below 4.0V input from the batteries. (3 x AAA alkaline)

It's all slowly coming together. I'll finish setting this up tonight, then quickly put together a matching RF module and TTL to USB converter on a breadboard, then I can test it with the PC.

If that all goes well, I'll start on the Arduino-based receiver for parsing the data and controlling a motor. I can use my PC-based receiver at the same time, with my 'Processing' bargraph, to monitor signal strength and "Attention" value.

Edit: To help improve signal strength and make sensor position a little less critical, I ordered some EEG conductive gel last night. It should be here in a few days. Hopefully it will improve things.

Stay tuned........
 
Last edited:

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
I tested the regulator and get 3.48V - it's good-to-go, so I mounted the assembly on the headset.
I did away with the SMA 'Rubber Ducky' antenna. It's too heavy, so instead I wound a 173mm 1/4 wave coil. It'll be more than enough for the range I need.

h. RF Module & Regulator Mounted.JPG

Incidentally, I haven't mentioned it before, but the two dangling clips go on my earlobes. They provide a reference or baseline for the EEG measurements. The main sensor is located in the front of the headband, positioned over the left eye.

Next it's on to the Arduino receiver program. I went back to Arduino from the PIC because it has built-in 32-bit handling for the Alpha, Beta etc values, plus it's easier to implement background servo control for my continuous-rotation servos. I've already written a small Arduino dual continuous-rotation servo library, wrapping the existing standard servo library, to synchronise two continuous-rotation servos while turning them in opposite directions for either side of a robot car.

My servos came with a wheel already attached to each, so they're really easy to set up. I also have some small swivel castors and will use one or two to support the other end of the 'car'.
for the chassis, I bought a couple of sheets of 3mm clear acrylic.

One of the servos:-
Continuous Rotation Servo with Wheel 2.JPG

And the castors:-
25mm Castor Wheels.JPG

I wasn't really setting out to build a robot car, but thought I might as well if I'm going to all of this trouble.

For power, I'll use a 7.2V 4600mAh NiMh battery:-
7.2V 4600mAh NiMH Battery.JPG

I need to modify my bargraph 'sketch', too. I wrote it for values from 0 to 255, but I've since learned that the 'Poor Signal' value is 0 to 200, which I'll invert for 'Signal Strength' and scale to 0 to 255, and the 'Attention' and 'Meditation' values are 0 to 100, so I'll also scale them to 0 to 255 to suit my 255 pixel bargraph.

Next update in a few days.....
 

Old Steve

Jul 23, 2015
734
Joined
Jul 23, 2015
Messages
734
I couldn't leave it alone without a quick test, so I set up a receiver and serial monitor on the PC and gave the headset a burst. This data is unparsed, so means little, except for the 0xAA 0xAA sync bytes at the beginning of each packet, and they're being received without a problem, so it's working fine:-
Code:
<AA><AA><02>P<83><18><00><F2><CA><01><A8><C1><00>=<CE><00>9<C6><00>0?<00>="<00>Q_<00><A8><84><04><00><05><00>/

<AA><AA><02>6<83><18><09><B7><D1><00>M<FD><00><13>k<00><04><D1><00><13>U<00><06>h<00><00><83><00><00><B4><04><00><05><00><E8>

<AA><AA><02>P<83><18><04>x<E6><00>Tu<00><97><CE><00><AE><00>k<98><00>o<00>'\<00><1A>]<04><00><05><00>E

<AA><AA><02>P<83><18><9B><DA><05>cX<04><BD><84><04><BA>9<02>(<C2><04>6@<06><0C><F9><01><15>:<04><00><05><00><CD>

<AA><AA><02><C8><83><18><09><BD>4<04><E2><91><03><FE><F6><03><C3><98><02>=<B5><03>vL<05><BF><00>T<A8><04><00><05><00>H

<AA><AA><02><C8><83><18<86><EC><06>~5<04>X<8D><02><DB><91><02><F9>q<03><B6><C9><05><E5><04><00>?O<04><00><05><00><9D>

<AA><AA> <02><C8><83><18><84>Q<04>3e<03><F0>%<04>;<06><02>T<C8><03><F4>1<05><81><9B><00>Z<B4><04><00><05><00>D

<AA><AA> <02><C8><83><18<F3>C<06><00>%<04>0<02><F9><E4><02><C2><CE><03><C6>,<05><D1>W<00>;<B3><04><00><05><00>i

<AA><AA> <02><C8><83><18><D0><DF><13><A3><B6><D3>r<10>h<92><02>d~<07><8F>><AE><03><C5>t<04><00><05><00><16>
 
Last edited:

Prashan Fernando

Dec 2, 2015
1
Joined
Dec 2, 2015
Messages
1
Seems like a great project. Could you explain to me in detail how you changed the frequency of the notch filter from 60Hz to 50Hz. Actually in Sri Lanka the mains frequency is 50Hz and I have purchased a mindflex eeg headset from the US. Pictures would also help understand. Thanks
 
Top