Brain Bug
Video demo:
Note that only forward/reverse is demoed; turning would require practice I don’t feel like doing. To clarify: out of all the MindFlex serial data, the data that are actually stable enough to be useful are: Attention & Meditation. So I use attention as the fw/rv switch, and meditation as the right/left switch. Trying to control attention is hard enough, so trying to actually navigate the toy would require practice (that I find too silly to be worth-it). So rather than demoing both (2D) and looking like a tool, I opted to go 1D.
Quick Links:
General Serial Repeater Arduino Code
(repeat serial @ 9600 @ INT0/DPin2)
MindFlex Serial Repeater Arduino Code
(repeat MindFlex Serial Data Frames)
BrainBug Arduino Code
To make this, all you need is the following:
- Arduino UNO (preferably R3)
- You can buy one here: http://www.robotshop.com/ca/arduino-uno-usb-microcontroller-rev-3-3.html
- 4 IR LEDs (or 3 IR + 1 Other)
- I use these ones: http://www.digikey.com/product-detail/en/TSAL6400/751-1205-ND/1681340
- An Inchworm that you will control
- A MindFlex Game (I guess you don’t need the whole game, just the headset)
- Wire+connectors
Tapping into the MindFlex:
This part may seem scary if you are not used to soldering, but if you can handle an iron this is easy.
Here are two high-res pics (click for high-res) to show you where to solder the GND reference (that goes to DigitalPin4) and the TX out (that goes to DigitalPin2):
And here are some pics of the bigger picture.
And here is a pic of the hook-up to the UNO (note that blue->blue, white->white):
Understanding the serial stream out of the MindFlex (General Approach):
(you can skip to the next section if you don’t care how the data is sent, I ‘wrap’ all that stuff in the code, so you can just plug-n-chug)
So now you have the MindFlex plugged into the UNO (note that you don’t need the LEDs yet).
Let us start with the Arduino Sketch: General Serial Repeater. If you program the UNO with that and then open up the Serial Monitor (Shift+Ctrl+M), after you turn on the MindFlex headset (you don’t have to wear it) you should see bursts of numbers appear roughly every second (there’s added space to make each # 3digits, and _’s to separate #’s).
Here is a sample output (after 5 bursts, and removing the trailing null character [the last 0]):
170_170_ 32_ 2_ 80_131_ 24_ 14_127_253_ 5_103_163_ 0_129_178_ 0_227_101_ 0_145_225_ 4_143_145_ 5_127_ 6_ 0_202_246_ 4_ 0_ 5_ 0_ 21_170_170_ 32_ 2_ 80_131_ 24_ 21_141_210_ 2_ 51_146_ 0_217_222_ 0_125_235_ 0_ 61_ 62_ 0_ 94_227_ 0_ 45_ 10_ 0_113_ 28_ 4_ 0_ 5_ 0_ 47_170_170_ 32_ 2_ 29_131_ 24_ 0_ 0_ 81_ 0_ 0_ 50_ 0_ 0_ 34_ 0_ 0_ 29_ 0_ 0_ 44_ 0_ 0_ 48_ 0_ 0_ 41_ 0_ 0_ 39_ 4_ 0_ 5_ 0_206_170_170_ 32_ 2_ 29_131_ 24_ 0_ 0_244_ 0_ 2_196_ 0_ 1_ 87_ 0_ 1_ 81_ 0_ 0_187_ 0_ 0_225_ 0_ 0_134_ 0_ 2_187_ 4_ 0_ 5_ 0_249_170_170_ 32_ 2_200_131_ 24_ 0_ 89_152_ 0_173_ 48_ 0_148_ 3_ 0_ 79_179_ 0_ 32_225_ 0_ 1_206_ 0_ 3_ 18_ 0_ 2_114_ 4_ 0_ 5_ 0_209_
Now if you look closely, you can see the frame header (the special sequence that indicates a new bunch of data), it’s 170 170 32 2 (or maybe that’s header, 32bytes, ID2). So if I use the ‘header’ I can write:
170_170_ 32_ 2_ 80_131_ 24_ 14_127_253_ 5_103_163_ 0_129_178_ 0_227_101_ 0_145_225_ 4_143_145_ 5_127_ 6_ 0_202_246_ 4_ 0_ 5_ 0_ 21_ 170_170_ 32_ 2_ 80_131_ 24_ 21_141_210_ 2_ 51_146_ 0_217_222_ 0_125_235_ 0_ 61_ 62_ 0_ 94_227_ 0_ 45_ 10_ 0_113_ 28_ 4_ 0_ 5_ 0_ 47_ 170_170_ 32_ 2_ 29_131_ 24_ 0_ 0_ 81_ 0_ 0_ 50_ 0_ 0_ 34_ 0_ 0_ 29_ 0_ 0_ 44_ 0_ 0_ 48_ 0_ 0_ 41_ 0_ 0_ 39_ 4_ 0_ 5_ 0_206_ 170_170_ 32_ 2_ 29_131_ 24_ 0_ 0_244_ 0_ 2_196_ 0_ 1_ 87_ 0_ 1_ 81_ 0_ 0_187_ 0_ 0_225_ 0_ 0_134_ 0_ 2_187_ 4_ 0_ 5_ 0_249_ 170_170_ 32_ 2_200_131_ 24_ 0_ 89_152_ 0_173_ 48_ 0_148_ 3_ 0_ 79_179_ 0_ 32_225_ 0_ 1_206_ 0_ 3_ 18_ 0_ 2_114_ 4_ 0_ 5_ 0_209_
Now we can see that there are headers, IDs (other values that don’t change, header is normally longer) and some data fields that change. Here is the breakdown that I came up with (after recording much more than just 5 bursts, I played the game to kinda-know what I was recording; the EEG values were especially hard).
Header_32Bytes_2_Quality(200->worst, 0->best)_131_24(bit-data)_8x24 bits of info_4_Attention_5_Meditation_Checksum (very normally the last one, if any).
Figuring out what those 8 numbers in the middle were took a lot of time. If you look at the changes across lines, and know about serial transmission of numbers larger than 1byte, you can see that each of the 8 numbers is sent as bits (out of the 24): [23:16] [15:8] [7:0].
Now if you buffer the data, sum up the number components, and only spit out info when framed, the info will make a lot more sense. I did this for you in the Arduino Sketch MindFlex Serial Repeater. If you program the UNO with that and open the serial monitor again you should see something like:
72_0_0_26621_15348_15441_4171_21507_-23923_3435_-4190 72_0_0_29130_5553_10588_-28290_-19892_27131_-26438_32131 72_0_0_-12091_-25334_13067_26995_2853_-15962_1920_1703 72_0_0_-20029_5770_-24496_-20292_4191_29146_8210_7081 0_0_0_-17869_12679_12118_22158_14761_-28944_-10218_25171 0_0_0_30239_-7110_8198_20080_1258_-12942_-14191_-19068 0_0_0_15310_-10170_12229_-1139_-32562_5733_2378_20160
Now you are at the point where you can use the MindFlex as a controller for whatever single thing you want. Be warned that only the Signal Quality, Attention, and Meditation are useful (maybe I am still wrong about the 8 numbers in the middle).
Moving the Inchworm with your mind:
All you have to do is:
- Program the Arduino UNO with the Arduino Sketch BrainBug.
- Plug in the LEDs (shown in picture earlier in post) to DigitalPins 8->11 (their GNDs->GND).
- Plug in the MindFlex (if not already so).
- Startup the serial monitor (so you can get feedback), and GO.
- Attention Up -> FW
- Attention Dn -> RV
- Serial: _t_ will toggle turning enabled
- Meditation Up -> Right
- Meditation Dn -> Left