Basic serial-debug demo of reading and parsing data from Neurosky's Mindwave Mobile EEG headset via BlueSMIRF Silver bluetooth modem.

Dependencies:   mbed

Basic demo of reading data packets from Neurosky's Mindwave Mobile headset via BlueSMIRF Silver bluetooth modem. Adapted from http://developer.neurosky.com/docs/doku.php?id=mindwave_mobile_and_arduino

Connect pin9 to BlueSMIRF's RX and pin10 to BlueSMIRF's TX, also hook up GND to GND and VCC to the mbed's 3V3 supply.

To prepare the BlueSMIRF to auto-connect to the Mindwave Mobile:

First wire it up and power it using the mbed's power pins. Once it's powered, pair your computer to the Mindwave Mobile headset to you can find out its MAC address. Write that down as you will need it.

Next pair your computer to the BlueSMIRF so we can configure it. It will appear as RN-42-5922 or similar (it's a Roving Networks RN-42 unit).

Now we can use a terminal program to connect to the serial modem created on your computer that connects wirelessly to the BlueSMIRF - by default it's at 115200 baud, 8 N 1 - when you're connected the light will go green.

If you've got a successful serial connection, put it into command mode by typing three dollar signs $$$ - if successful you should see a prompt saying 'CMD'. If not, power it down and try again till you get a CMD prompt.

At that prompt we need to change some defaults so that the BlueSMIRF is set to master mode, 57600 baud and sends a pincode of '0000', and seeks to connect to the headset's MAC address. To do this, type:

SP,0000
SM,3
SR,<the 12 digit MAC address of the headset written down earlier>
SU,57.6
D

You should see AOK after each line, and after the D it will print out its settings so you can check it's now AUTO, 57600, using 0000 and the right MAC address. All being well, type three minuses '---' to exit command mode.

To check it's working, close the terminal you've been using, reboot the BlueSMIRF (flashing red light) and switch on the Mindwave Mobile headset - the light on the BlueSMIRF should go green when it connects and the flashing blue light on the Mindwave Mobile headset should go steady blue.

Files at this revision

API Documentation at this revision

Comitter:
RorschachUK
Date:
Tue Jun 04 17:53:54 2013 +0000
Parent:
0:7a3f4ba1851c
Commit message:
EEG data is big-endian not little-endian

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jun 02 16:04:19 2013 +0000
+++ b/main.cpp	Tue Jun 04 17:53:54 2013 +0000
@@ -48,17 +48,20 @@
 //User routines to process data
 //*****************************
 
-//This will be called if you blink.
+/** This will be called if you blink.
+ */
 void blinked(void)
 {
     printf("\nBlink!\n\n");
 }
 
-//This will be called when processed eSense data comes in, about once a second.  If the
-//connection's good, poorQuality will be zero, if the connection's useless (e.g. ear clip
-//or forehead electrode not connected)it will be 200, and it can be somewhere in between 
-//for varying degrees of confidence in the data.  Values for attention and meditation are 
-//0-100, and the time since last packet is in milliseconds.
+/** This will be called when processed eSense data comes in, about once a second.
+ *
+ * @param poorQuality will be 0 if connections are good, 200 if connections are useless, and somewhere in between if connection dodgy.
+ * @param attention processed percentage denoting focus and attention.  0 to 100
+ * @param meditation processed percentage denoting calmness and serenity.  0 to 100
+ * @param timeSinceLastPacket time since last packet processed, in milliseconds.
+ */
 void eSenseData(int poorQuality, int attention, int meditation, int timeSinceLastPacket)
 {
     if (poorQuality < 200) {
@@ -74,16 +77,19 @@
     printf("\n");
 }
 
-//This will be called when processed meter reading data arrives, about once a second.
-//This is a breakdown of frequencies in the wave data into 8 named bands, these are:
-//  0: Delta        (0.5-2.75 Hz)
-//  1: Theta        (3.5-6.75 Hz)
-//  2: Low-Alpha    (7.5-9.25 Hz)
-//  3: High-Alpha   (10-11.75 Hz)
-//  4: Low-Beta     (13-16.75 Hz)
-//  5: High-Beta    (18-29.75 Hz)
-//  6: Low-Gamma    (31-39.75 Hz)
-//  7: High-Gamma   (41-49.75 Hz)
+/** This will be called when processed meter reading data arrives, about once a second.
+ * This is a breakdown of frequencies in the wave data into 8 named bands, these are:
+ *   0: Delta        (0.5-2.75 Hz)
+ *   1: Theta        (3.5-6.75 Hz)
+ *   2: Low-Alpha    (7.5-9.25 Hz)
+ *   3: High-Alpha   (10-11.75 Hz)
+ *   4: Low-Beta     (13-16.75 Hz)
+ *   5: High-Beta    (18-29.75 Hz)
+ *   6: Low-Gamma    (31-39.75 Hz)
+ *   7: High-Gamma   (41-49.75 Hz)
+ * 
+ * @param meters array of meter data for different frequency bands
+ */
 void meterData(int meter[8])
 {
     printf("Meters: ");
@@ -93,9 +99,12 @@
     printf("\n");
 }
 
-//This will be called when wave data arrives.  There will be a lot of these,
-//512 a second, so if you're planning to do anything here, don't let it take long.
-//Best not to printf this out as it will just choke.
+/** This will be called when wave data arrives.
+ * There will be a lot of these, 512 a second, so if you're planning to do anything 
+ * here, don't let it take long.  Best not to printf this out as it will just choke.
+ *
+ * param wave Raw wave data point
+ */
 void waveData(int wave)
 {
 }
@@ -105,7 +114,9 @@
 //*****************
 
 //System routines to obtain and parse data
-//Simplify serial comms
+
+/** Simplify serial comms
+ */
 unsigned char ReadOneByte()
 {
     int ByteRead;
@@ -115,7 +126,9 @@
 
     return ByteRead;
 }
-//Main loop, sets up and keeps listening for serial
+
+/** Main loop, sets up and keeps listening for serial
+ */
 int main()
 {
     Timer t; //packet timer
@@ -202,7 +215,9 @@
                                 break;
                             case 0x83: //meter readings for different frequency bands
                                 for (int j=0; j<8; j++) {
-                                    meter[j] = payloadData[i+j*3+2] + payloadData[i+j*3+3]*256 + payloadData[i+j*3+4]*65536;
+                                    //documentation is inconsistent about whether these values are big-endian or little-endian,
+                                    //and claims both in different places.  But wave data is big-endian so assuming that here.
+                                    meter[j] = payloadData[i+j*3+2]*65536 + payloadData[i+j*3+3]*256 + payloadData[i+j*3+4];
                                 }
                                 meterPacket = true;
                                 i = i + 25;