How to import Neurosky Mindset Data into Unity?

Hello Unity Community,

I've been trying all night and morning on how to import & connect my Neurosky Mindset into Unity Pro.

Ive read through the documentation provided by Neurosky (but didnt help me yet): http://developer.neurosky.com/docs/lib/exe/fetch.php?media=app_notes:using_thinkgear_with_unity.pdf

I have made a map called Plugins and renamed the files in it like the document described but the coding I have not been able to make.

Possible to get some assistance / feedback what to do specifically ?

Thanks in advance

Update: Neurosky has a blog post (from 2008) in the Unity Developers Blog: Neurosky and Unity


Where do you put the code that uses the Neurosky DLL? The short answer is, in whatever object you want it. :) The slightly longer answer is below:

To give you a simple example:

  • Create a blank project, save it and a test Scene.
  • Copy the .dll and .cs files to Assets/Plugins.
  • Using Asset->Create Other, create a GUIText Object.
  • Under Projects, create a C# script called s_ ReadNeuro. cs
  • Cut/paste the code below into that script.
  • Drag/drop the script to the GUIText Object, making it a Component.

```

using UnityEngine;
using System.Collections;</p>
`public class s_ReadNeuro : MonoBehaviour {
    int tgHandleId;
    int tgConnectionStatus;
    int tgPacketCount;

    void Start () {
        setupNeuro();
    }
    void Update () {
        readNeuro();
    }
    void setupNeuro() {
        tgHandleId = 123;
        // tgHandleId = ThinkGear.TG_GetNewConnectionId();
        tgConnectionStatus = 456;
        // tgConnectionStatus = ThinkGear.TG_Connect(tgHandleId...);
        // check for good connection, print error message if bad.
    }
    void readNeuro() {
        tgPacketCount = Random.Range(1, 100);
        // tgPacketCount = ThinkGear.TG_ReadPackets(tgHandleId, -1);
        this.gameObject.guiText.text = "packets = " + tgPacketCount;
    }
}

```

`

When you run the project, you'll see a GUIText object in the center of the screen, with the message *packets = xxx" constantly updating.

Now, to connect it with your Neurosky object, you need to add in the code from the .pdf file. I've put a few sample lines in the script above, but this is not complete code (or very good code), just samples to give you an idea where code can go.

Although there is some boilerplate code required to use a DLL, Neurosky has provided it for you in the script ThinkGear.cs, so to call their code, you just need to prefix a function with ThinkGear.

Long-term, you'd want to create some other Object that displays the data you obtain from the Neurosky. For instance, you could create a bouncing ball, whose height is determined by the data. You would do it with a script similar to this one, only attached to a Sphere object, for example.

So you can put the code anywhere (as a script), and attach it to any kind of displayable Object, and use the data to manipulate that Object. The script is responsible for reading the Neurosky, interpreting the input data, and modifying the Object to display something to the user. I hope that clarifies how your Neurosky code is related to Unity code, if not let me know.

Can you help me?
this is my code, why can’t I connect it?
they also show -1 in GUIText and I don’t know how to use MindSet to set it.

using UnityEngine;
using System.Collections;
using System;
public class Form1 : MonoBehaviour
{  int handleID,connectStatus,packetCount;
	float attention;
     void Start () {
		
    }
     void Update () {
		  handleID = ThinkGear.TG_GetNewConnectionId();
		  connectStatus = ThinkGear.TG_Connect(handleID,"\\\\.\\COM40",ThinkGear.BAUD_9600,ThinkGear.STREAM_PACKETS);
		if(connectStatus >= 0){
		
		  packetCount = ThinkGear.TG_ReadPackets(handleID,-1);
		
			if(packetCount > 0){
			InvokeRepeating("OnGUI", 0.0f, 1.0f);
			}
			else 
				return;
			}
		else 
			return;
				
	}
		
		void OnGUI()
		{
			  packetCount = ThinkGear.TG_ReadPackets(handleID,1);
			if(packetCount > 0){
		   if (ThinkGear.TG_GetValueStatus(handleID, ThinkGear.DATA_ATTENTION) != 0)
              {
                attention = ThinkGear.TG_GetValueStatus(handleID, ThinkGear.DATA_ATTENTION);
                 GUILayout.Label("A"+attention);
               }
		//	GUILayout.Label("A"+attention+" "+handleID+" "+packetCount+" "+connectStatus);
		}else
		GUILayout.Label("A"+attention+" "+handleID+" "+packetCount+" "+connectStatus);
		}
}