Introduction: Mindflex EEG With Raw Data Over Bluetooth
The Mindflex (and Mindflex Duel--the relevant hardware is supposed to be the same) toy lets you control the height of a ball with mental concentration. I will explain how to attach a $3 Bluetooth module to make this into a full-functioned Bluetooth EEG headset with raw data output that should be usable with most apps that supports the Mindwave Mobile EEG headset (the Mindflex uses basically the same ThinkGear chip that the Mindwave Mobile does). Since you can get Mindflex headsets on ebay for $15 or less, that means the cost of the project can be as low as $18.
With the raw data, you can also capture ECG images of heart activity, though you need to be particularly careful, especially being careful that the device not be connected to the mains, as the heart is very sensitive to small electrical currents.
- No Arduino, just a simple Bluetooth module (cheaper, simpler). (Full disclosure: You will need a second TTL serial link to set the baud rate on the HC-06, and you can use an Arduino for that, but you can also use a second HC-06 module, a Brainlink device, a USB-to-TTL-serial link, etc.)
- Powered from the headset's own batteries.
- No need for SMD soldering to enable raw output mode, and the modified device should still work as the toy.
- Compatible with Mindwave Mobile apps (with simple initialization app).
Disclaimer: Anything electrical hooked up to your head (or heart--you can use this for heart monitoring) is potentially risky. Don't use it if you have cuts where the electrodes go as that can decrease skin resistance. USE AT YOUR OWN RISK. That said, the project is only powered by three AA batteries. This is not a medical diagnostic or treatment device.
What you need?
- Mindflex headset, either from the original toy or from the Mindflex Duel (doesn't matter which one).
- Bluetooth-to-TTL-serial module. My instructions will assume that this is an HC-06 module. Plenty of those on Amazon. Get one with cables to save some work. Make sure your module can be powered by the 4.5V DC input that powers the Mindflex.
- A device that can do 9600 baud TTL serial output. This can be a second HC-06 module, a USB-to-TTL-serial link, an Arduino or a Brainlink (I used a Brainlink). This is not a part of the finished project but is needed once to set the baud rate on the HC-06 module. (If you use a more expensive RN-42, you may be able to configure it via Bluetooth.)
- Soldering iron, solder, miscellaneous wires, electrical tape.
Acknowledgments: I got the idea for stuffing the BT module inside the Mindflex headset from this Instructable. I then edited the Instructable to reflect this, since it was a great idea.
Step 1: Some Background
Feel free to skip this background, but it explains why some things are done as they are. For safety, EEG headsets need to be isolated from anything plugged into mains. The Mindflex, Mindwave Mobile and a number of other EEG headsets use a ThinkGear ASIC chip. This chip communicates over TTL serial with a radio, and the radio in turn communicates with other devices, like the Mindflex toy base station. This isolates the headset electrically.
Unfortunately, while the Mindwave Mobile's radio is Bluetooth, the Mindflex toy uses some other kind of radio. To use the Mindflex EEG with other devices, we will simply connect the ThinkGear chip's receive and transmit lines to an HC-06 Bluetooth radio (about $10 with cables).
Well, maybe not quite so simple. While that's all that's needed in terms of hardware, there is a software challenge. The ThingGear ASIC has several modes of operation. As embedded in the Mindflex toy, an SMD resistor sets it to mode 0x01 by default. In mode 0x01, the chip transmits at 9600 baud, and sends processed data every second: Meditation, Concentration and values for various parts of the power spectrum, presumably derived by an FFT. But we want to have access to the raw EEG data. This requires switching the Mindflex headset to mode 0x02. In mode 0x02, the chip transmits at 57600 baud, and in addition to the same once-per-second update that it does in mode 0x01, it sends raw differentially amplified EEG sensor data 512 times per second. This is the mode in which the Mindwave Mobile headset functions by default, so if you can switch the headset to this mode, not only do you get raw data, but you should be able to use it with all Mindwave Mobile compatible apps.
One can switch the Mindflex to mode 0x02 with some SMD soldering work, but I am terrible at soldering (as you'll see in later pictures), so that's not an option for me. Also, that solution makes the headset no longer work with the rest of the toy, and I don't like breaking things.
Fortunately, the communications protocol for the ThinkGear chip allows you to switch to mode 0x02 very simply by sending 0x02 to its serial receive line. While this doesn't survive powercycling, nonetheless it should make things simpler: just make sure the receive line of the chip is connected to the Bluetooth radio's transmit line, and send 0x02. But there is a hitch. The 0x02 has to be sent at 9600 baud, while the subsequent data will be at 57600 baud. And unfortunately there is no way to control the HC-06 Bluetooth radio's baud rate dynamically in use.
But there is a solution that surprisingly works. 9600 = 57600 / 6. If you could just send a bit six times at 57600 baud, that would be the same as sending it once at 9600 baud. The only hitch is that when sending things via RS232 serial or its TTL variant, you don't get to control each bit. Instead, assuming the usual 8N1 communications setting, the bits are packaged into bytes, with each byte starting with an extra 0 "mark" but and ending with an extra 1 "stop" bit. The mark and stop bits are out of our control. But we can work around this. It turns out that if we send the hex string 0x00, 0xF8, 0x00, 0x00, 0x00, 0xE0 at 57600 baud and then pause for at least the length of a 9600 baud bit (a millisecond will be more than enough; idling is the same as sending 1's in the RS232 protocol), that's like sending 0x02, with four glitches (and some extra zeroes up front), each glitch being 1/6 of a bit in length. If we're lucky, the 9600 baud receiver will ignore the short glitches. And somewhat surprisingly it works! The chip switches to mode 0x02, starts transmitting at 57600 baud, and all is well. In fact, with the HC-06 as the transmitter it works 100% of the time (using a Brainlink, it sometimes requires a retry).
So there are three components to the project:
I. Set the HC-06 Bluetooth radio to 57600 baud. This setting survives powercycling. This is cumbersome but needs to be done only once.
II. Solder connections to the headset to connect it to the HC-06 radio.
III. Make sure that the headset goes to mode 0x02 by sending the magic hex string (or some variant on it) at 57600 baud. This could be done by building the magic string into EEG software, or by writing a simple program that sends the magic hex string to the device, and then the device can be used with any software compatible with the Mindwave Mobile. I did both: I wrote some EEG software in Java that can be run on a PC (probably also Mac and Linux but I haven't tested it there) and that sends the magic string before display the raw and processed data, and I made a simple Android app that simply sends the magic string (or a variant on it) at 57600 baud and activates the Mindwave Mobile compatible mode. Both programs are open source.
Step 2: Part I: Set Bluetooth Module to 57600 Baud
You need to configure your Bluetooth module to 57600 baud. The instructions below are for the HC-06. If you have an HC-05 or RN-42, you can find instructions elsewhere online.
To set the HC-06 Bluetooth module's baud rate to 57600, you just need to send AT+BAUD7 (without anything else--no CR, no LF) to the module over the serial link, when the module is in command mode. It's very easy to put the HC-06 in command mode: just power it up, and make sure nothing is connected to it via Bluetooth. In command mode, the HC-06's LED is flashing.
So to change the baud rate from the default of 9600 baud, you need to power up the module, connect it to some other device that can send serial data at 9600 baud, and send the AT+BAUD7 command.
You can power the module by connecting it to the Mindflex's battery pack. Just squeeze jumpers between the battery and the terminal at the two ends of the three AAA sequence in the pack, connect the minus end to the GND terminal marked on the Bluetooth module and the plus end to the VCC terminal on it. (Make sure you don't reverse it.) The female terminals on the cable that you can get with the module will help. If all works well, the LED on the module will flash.
After having checked that you can power up the module, disconnect it from power.
You now need a computer and another device that can allow the computer to transmit TTL-level serial data at 9600 baud. A second HC-06 should do the job, but the simplest is probably a USB-to-TTL-serial adapter. I used a Brainlink device myself, which has a built-in battery that I also used to supply power to the HC-06. Make sure that whatever device you use runs at TTL levels, rather than at the higher voltage of RS232 serial.
You can also use an Arduino with a simple sketch that sends the AT+BAUD7 command (cf. the sketch here).
Connect the transmit line on your second serial device to the RXD line on the HC-06 you are configuring. Connect the ground line on that device to the HC-06 GND and the negative end of the power supply. To verify that the change has taken place, connect the receive line on your serial device to the TXD line on the HC-06. Power up both devices as needed.
Now connect your computer to your second serial sevice, but NOT your HC-06, and connect to the second serial device with a terminal emulator at 9600 baud (PuTTY and RealTerm work well on Windows). Type AT very quickly, but do not press return. If all is well, you will see an OK within a second or two. Otherwise, the connection isn't working.
Then you need to send AT+BAUD7 probably faster than you can type. To do that, type it in another window, and then copy and paste into the terminal (make sure you do not copy and paste any space or end-of-line character at the end of it). Or, if you're using RealTerm, you can just just go to the Send tab, type it in the blank, and press "Send ASCII."
You may want to rename the module to "Mindflex" if you like by sending AT+NAMEMindflex (again without any end of line characters), again faster than you can type.
The exact way you do the above depends on just what second serial device you have. Here are precise directions for the Brainlink device I used. First, upgrade the Brainlink device to my custom firmware which makes serial connections easier and better. The easiest way to do this is to use this Android app and connect to the Brainlink via Bluetooth. The app contains full instructions. Alternately, you can follow the instructions here and download my custom firmware from here (where you'll also find the source code for the Android app and the firmware). Then make the following connections (oddly the Brainlink ports seem to be numbered right-to-left) with the Brainlink turned off:
- Brainlink 10-pin port, pin 3 (blue, +5V) to VCC on HC-06
- Brainlink 8-pin port, pin 8 (black, ground) to GND on HC-06
- Brainlink 8-pin port, pin 7 (yellow, serial TX) to RXD on HC-06
- Brainlink 8-pin port, pin 6 (green, serial RX) to TXD on HC-06.
Ensure other exposed wires don't touch.
Connect the Brainlink to a terminal emulator on your computer via Bluetooth. You should see a sequence of "BL" characters. Type an asterisk (*). The BL's should stop going. Then quickly type u96Z to switch to 9600 baud serial bridge mode. (If you type the u96 part too slowly, you'll get an error.) Now, you can do the AT and AT+BAUD7 commands.
Step 3: Part IIa: Solder Wires to Mindflex Circuit Board
Remove the batteries from the Mindflex.
Open the Mindflex circuit box. This is the white unit with the power switch, not the one with the batteries. There are four screws. Then remove the two screws from the circuitboard inside. Make sure you don't lose the white power switch cover.
There is a main circuitboard and two daughterboards inside. I believe the smaller one is the non-Bluetooth radio. I've read online that you can save some battery life by removing it, but of course then you can't use the toy anymore. The bigger daughterboard contains the ThinkGear EEG ASIC.
Find four jumper wires that aren't so thin they're fragile but are thin enough that you can solder them where space is tight. Ideally, all four should be different colors. Otherwise, you might mark patterns on them with a marker so you don't get them confused.
Solder two of to the marked R(eceive) and T(ransmit) pins on the ThinkGear daughterboard. See the photo of the daughterboard. In my project, the yellow wire goes to Transmit and the orange to Receive.
I am poor at soldering. When I was soldering the R pin, I shorted it to another and had to cut through the solder. You will see other artifacts of my poor technique in the photos. Do a better job, but what I did works.
The third wire (brownish-purple in my photo) will need to go to the ground connection on the underside of the main board, and the fourth (light gray) will need to go to a switched +4.5V pin under the switch (the middle of the three switch pins).
Write down which colors you used for Receive, Transmit, Ground and switched +4.5V.
Tuck the two underside wires into the hole near the ground wire so you can pull them up. Screw the circuitboard back in place.
Knot all four wires together for pressure relieve, and enlarge the hole that the ear clip wire went through (a hot soldering iron will do that really well). Then put all the five wires--ear clip and the four new ones--out the hole, keeping the knot inside (in the photo, the ear clip knot is outside), and screw on the cover.
Step 4: Part IIb: Connect Wires to Bluetooth Module
The cable my HC-06 module came with had a single four-pin female connector on one end and four separate one-pin female connectors on the other end. I cut off the four one-pin connectors with about an inch of wire, and soldered the wires to the four new wires sticking out of the Mindflex circuit box. I insulated the connections with electrical tape and heat shrink tubing.
The wires need to be connected as follows:
- Mindflex T pin - Bluetooth RXD
- Mindflex R pin - Bluetooth TXD
- Mindflex ground - Bluetooth GND
- Mindflex switched +4.5V - Bluetooth VCC.
I taped the T, R and ground female connectors together to form a single three pin connector, so I could more easily turn off the radio by just pulling the VCC connector for when I want to use the headset as part of the toy.
In my initial build, I taped the Bluetooth module to the outside of the case.
Step 5: Part IIIa: Software (Android)
I've found connecting Bluetooth devices to my phone (Galaxy S3) to be more straightforward than connecting them to my PC. My Bluetooth module took a couple of attempts to pair (PIN 1234), but once paired works great with my phone.
You can now install my free Mindflex to Mindwave Mobile app, turn on the Bluetooth on the phone, turn on the Mindflex headset together with its Bluetooth module, and press "Activate" in the app. This sends the magic hex sequence that puts the Mindflex in raw mode compatible with Mindwave Mobile software. If it fails the first time, try again. Once you've activated it, the mode should keep on running until the device is turned off.
The headset's main electrode goes on the forehead, and the clips go on earlobes. Kind of like the horse is doing, except it doesn't have earlobes. My kids have earlobes, but I don't want to post their pictures. Avoid using it over cuts (the resistance will go down and any electrical danger level will go up).
It shouldn't be hard to make an iOS app equivalent to my Mindflex to Mindwave Mobile app.
Step 6: Part IIIb: Desktop Software
I am mainly a mobile developer, and this was my first time doing GUI stuff with Java, but I wrote Brainflex, a simple visualizer for both the power spectrum analysis and the raw data. It's rather rough around the edges, and you need to know which serial (COM on Windows) port number your Bluetooth module connects to. (On Windows 8, you can open Devices and Printers, right click on on the Bluetooth module after pairing, and look at Services. If more than one port is listed, you want the outgoing one).
Install java. Install the jar file from the above link. Launch the jar file. Choose "57600 baud Bluetooth-serial bridge + Mindflex" as the mode. Fill in the serial port and press Go. If it exits immediately, it failed to connect. Try again. Three windows (raw, processed and log) will open. You can pause and scroll and resume.
Once you start the raw mode display, you can exit Brainflex, and the headset will stay in raw mode, and you should be able to use it with any Mindwave Mobile compatible software until it's turned off.
You can troubleshoot by connecting to the port via RealTerm and putting RealTerm's display in hex mode. If all is well, you will see plenty of scrolling of (512 per second) records starting with AA AA 04 FF 80.
Step 7: Optional: Stuffing Bluetooth Module Inside
In my initial Instructable, the Bluetooth module was on the outside. Then I saw this great Instructable where they stuff the module inside, so I did that, too. :-) The down side of this is that I can't unplug the power from the module when the headset is being used as a toy. This doesn't interfere with the toy, but it does use up more battery life.
When stuffing, make sure you cover all contacts with electrical tape to avoid shorts, though I did keep the antenna on the module exposed, and made sure to place it facing the outside, where there were no other electrical parts.
I am somewhat worried about heat issues with extended use. If it feels too warm, I guess I can move it back out.
Step 8: Alternative: Using Brainlink in Place of HC-06
If you're one of the lucky few people to have a Brainlink device (hardware information here; SurplusShed sells them for $39, but has periodic 30-50% off on everything sales), you can use it entirely in place of the HC-06. Just connect the Brainlink's serial receive line to the Mindflex T pin, the serial transmit line to the Mindflex R pin, and ground to ground. The Brainlink has its own power supply. If you install my custom backwards compatible firmware (see the end of the Part I step above) on the Brainlink, then it will automatically switch to 57600 baud serial when the magic hex string is being sent through. You can also use the specialized Brainlink mode in Brainflex.
Using the Brainlink is probably slightly more dangerous as instead of just ~5V volts to play with, you now have two ~5V sources. I guess you could try to power the Mindflex from the Brainlink. I am not sure the Brainlink can handle the current, though.
Step 9: Sample Data
There has been some discussion on the Internet whether the Mindflex EEG unit is a fake. So here is some data to validate things.
Image 1: Raw data from the unit mounted correctly on the forehead, with me blinking my eyes and wiggling my ears.
Image 2: Raw data from the unit touching the chest around the heart. (Using aluminum foil attached to the ear clips as an electrode. I think I had both clips connected to the same piece of foil, which isn't ideal. You need to be particularly careful, especially being careful that the device not be connected to the mains, as the heart is very sensitive to small electrical currents.)
Image 3: Raw data from the unit connected to my knee. (This is in response to a comment responding to another Instructable and claiming that the unit is fake because it gets signal from the knee.) The big waves are due to my straightening the knee, and show a nice capture of the electrical potentials from muscle movement.
Image 4: Processed power spectrum data taken while I was writing a chapter of a technical philosophy book in LaTeX on my laptop.
Image 5: Processed power spectrum data taken while I was taking care of a toddler.
While I don't know exactly what to make of Images 4 and 5, there are clear differences between them. Unfortunately, Image 4 suffers from EM noise due to the fact that I was typing on my laptop.
7 People Made This Project!
We have a be nice policy.
Please be positive and constructive.