Per previous posts, I am making some free software available here (although it’s somewhat niche): A Mac OS X Distributed Objects server for the Neurosky brain wave reading Mindset and a Quartz Composer plug-in client for the server. (If you have neither OS X nor the Mindset, you might want to wait for a future post where I talk more about how the brain wave art project is coming.)
This post will also serve as a brief introduction to what it would take for you to write your own Cocoa client for the server. But, If you just want the software, you can get it here:
- Server Application (and source code / Xcode Project)
- Quartz Composer Plug-In Client (and source code / Xcode Project)
Notes:
- To install the client for Quartz Composer, close QC and copy the .plugin file to: “/Library/Graphics/Quartz Composer Plugins”. When you next open QC, you should find it in your Patch Library listed as “MindSetQCClient”. Usage of the patch should be obvious,
- The server shouldn’t need to start first as long as the client periodically checks for a vended object, but when troubleshooting it’s probably a good idea to start the server, then the client.
- The server needs the Thinkgear bundle in same directory as the server app. (I’m not including the Thinkgear bundle, it’s available from the Neurosky website for free as part of their developer stuff.
- Neurosky documentation has instructions for how to figure out what serial port your mindset is on, iirc. The default for the server is the one I use.
- I’ve borrowed so heavily from a hodge-podge of tutorials and examples, that I’m not going to include a license for the code. Use it as you will.
.
So, onward to the tutorial/implementation details:
.
Distributed Object Mindset Server and Client
This server is intended to be a little easier to use than some of the connection methods Neurosky provides (at least in my mind). It grabs data from the Mindset and provides it to Cocoa client applications (such as my Quartz Composer plug-in) by using Objective-C / Cocoa’s Distributed Objects interprocess messaging capability.
To access the Mindset data, the client must create an NSConnection to “JacksMindsetServer”. This gives it access to a vended object which supports the following very simple protocol (this protocol will have to be included in your client header file):
@protocol PassingMindData
-(int) getDataCount;
-(NSArray *)getOldestData;
-(void)removeOldestData;
@end
Creating the connection to the vended object which uses that protocol is simple and requires only a short bit of code:
if (!sharedObject)
{
NSString *_host = nil;
sharedObject = (id <PassingMindData>)[[NSConnection rootProxyForConnectionWithRegisteredName:@"JacksMindsetServer" host:_host] retain];
}
You should now have an object called “sharedObject” which allows all of the methods specified by the “PassingMindData” protocol created above and which will pass the data from the mindset server to your code. To do so, the primary method is “getOldestData”. Calling this method will return an array of the oldest line of values from the Mindset and getDataCount returns the number of lines currently queued.
The returned array contains ordered NSNumbers representing each type of value available from the mindset. The array elements can always be accessed in the following order:
- Attention (0)
- Meditation (1)
- Raw (2)
- Delta (3)
- Theta (4)
- Alpha1 (5)
- Alpha2 (6)
- Beta1 (7)
- Beta2 (8)
- Gamma (9)
- Gamma2 (10)
- SignalQuality (11)
The client is left to access these elements as it pleases from the NSArray object returned by getOldestData. The server also relies on the client to remove the original data from the server as soon as it grabs it by calling “removeOldestData” on “sharedObject”. (If the client does not call this, there is no auto-cleanup by the server until it’s stopped or exits and the client will not be able to access new data.)
If multiple lines of data are queued, getOldestData and removeOldestData should be executed repeatedly. A simple example would be:
if ([sharedObject getDataCount] > 0)
{
mindDataLine = [NSArray arrayWithArray:[sharedObject getOldestData]];
[self setOutputAttention:[[mindDataLine objectAtIndex:0] doubleValue]];
[sharedObject removeOldestData];
}
That’s really it. How to write a server is out of the scope of this post, but Neurosky has some great documentation and have provided examples from which I have –heavily– borrowed.
Let me know if you have questions or need further explanation. I’m going to continue to work on the art project with this stuff and will post more about that later.






15 comments
Comments feed for this article
July 28, 2010 at 4:44 am
Universal Mediaman
Which version of osx is needed for the server?
July 28, 2010 at 8:50 am
Jack Whitsitt
I know it runs on 10.6/Intel. It SHOULD run on any recent 10.x on Intel (compiled 32bit, not 64). Let me know if youre having problems on a particular version.
August 3, 2010 at 10:03 am
Universal Mediaman
Hello Jack,
Sorry for the late reaction. I can’t seem to open your server app on osx 10.5.8. I get an error message that the app is not compatible with my version of osx.
December 18, 2010 at 5:52 pm
Paul
Jack – I am confused. I have put MindsetServer in an apps directory, together with Neurosky’s ThinkGear.bundle. Console reports:
[0x0-0x42042].com.yourcompany.MindsetServer[414] Error: Could not find ThinkGear.bundle. Does it exist in the current directory?
Thanks for any pointers. – Paul
January 6, 2011 at 11:31 am
Jesus
Hi, I have the same problem as you. Did you finally solve it?
January 30, 2011 at 2:37 am
Samynosor
I got the server running if thinkgear.bundle is inside the Mindserver Directory :
Open package/Contents/macos/
And launched in terminal in same directory by ./Mindsetserver
Hope this helps
March 21, 2011 at 11:30 am
Ceci
Hi Samynoser,
I understand putting ThinkGear.bundle inside the macos, but what do you mean by ” launch in terminal in same directory by ./Mindsetserver” because I tried running the Mindserver inside macos but still getting the same result…
Thanks in advance!!
March 22, 2011 at 2:14 am
Ceci
I finally got it work inside xcode using the source code, but no luck running the build outside xcode… any help would be much appreciated! Thanks!!
March 26, 2011 at 8:57 am
Installation Studio | Blog | Assignment #4: Brainwave Art with Quartz Composer
[...] http://sintixerr.wordpress.com/2010/07/26/open-source-neurosky-mindset-server-quartz-composer-client… [...]
February 21, 2012 at 1:42 pm
txo!?
Hi there
this looks great but the linked archives are not there anymore. Is there a way to have those Neurosky mindset Quartz composer server/client? it would be so nice. Thanks in advance.
April 28, 2012 at 8:17 am
Ben Acland
In a somewhat related project… after sitting on it for a while, I just exposed the repo holding a collection of objective-c classes I’ve written under the name ThinkGearCocoa. They make it pretty durned easy to start developing cocoa apps for NeuroSky products. Or… they’re supposed to. Check them out and let me know! https://github.com/beOn/ThinkGearCocoa
May 3, 2013 at 1:12 am
Nicolas de Cosson
Hey Ben,
I have been trying to get your demo up and running, everything seems to compile fine, the window pops up, the device on my head is on and paired with my computer, I press connect on your demo and it goes through the authorization process, says it’s connected, but has a “poor signal” meanwhile, the ThinkGear Connector App is always in the hour glass mode and never seems to connect. Not sure what i am doing wrong…i have tried adjusting the head piece, cleaning the node….I have a feeling that I am doing something wrong when it comes to importing coreplot…as easy as it may seem ;) I probably am doing something wrong, but I have no idea as it seems to compile fine…any ideas?
December 26, 2012 at 7:29 am
nfl wholesale jerseys
Hi! I’ve been reading your site for some time now and finally got the courage to go ahead and give you a shout out from Huffman Tx! Just wanted to tell you keep up the good job!
December 30, 2012 at 1:40 pm
casagiuliani.com
I for all time emailed this web site post page to all my friends, because if like
to read it next my contacts will too.
January 4, 2013 at 1:16 pm
http://krooribbin.com
I am sure this article has touched all the internet visitors, its really really fastidious paragraph on building
up new web site.