Here's a quick and easy example of how to use the current SDK. This page assumes you have already downloaded and installed the SDK and had a look at the SDK Overview. To get familiar with the Muse hardware, button, and LEDs, check out the consumer quick start guide as well as the Muse Hardware page. The Muse Calm app (it's free!) for Android and iOS also provides a very thorough interactive introduction to Muse. At this time, LibMuse is only available for Android and iOS. Versions of LibMuse for desktop platforms are currently being written. To develop for desktop platforms right now we provide MuseIO (as well as the other Muse SDK Tools: MuseLab and MusePlayer) to connect to Muse and stream data over OSC to another program running an OSC server. In this section we will describe this process and provide some simple examples of how to build such a server. Let's get started! 1. Pair with MuseMake sure Muse is sufficiently charged before pairing and streaming data. If you are having difficulties initially connecting, charge Muse for 20-30 minutes and then try again. Switch Muse into Pairing Mode by holding the button down for ~5 seconds. The rest of this process depends on the operating system that you are using, so just follow the standard Bluetooth pairing instructions for your specific operating system. If you are asked to enter a passcode, enter "1234". For more info on using the Muse hardware, the different button presses, LED patterns, etc. see the consumer quick start guide and the Muse Hardware page. 2. Start MuseIOOpen a terminal or command prompt and type:
For a full explanation of all of MuseIO's options, see here. What kind of data can I get from MuseIO?A full list of all the data that MuseIO provides (including background information and explanations) is available here. 3. Run MuseLabTake a look at the MuseLab tutorial and be sure to point it at port 5002 with UDP selected. Using MuseLab in this way, while you're building your own OSC server and application for Muse, you can double check the data that MuseIO is sending out by observing it as real-time plots. 4. Set up an OSC serverNow that OSC messages containing Muse data are being sent to port 5001 and 5002 from Muse-IO, we just need to set up an OSC server in our language of choice. Once you can receive OSC messages, you can start doing fun things with the data from Muse. There are OSC libraries available for most major programming languages. Let's start by looking at a simple example in Python. Python OSC ServerFirst, make sure you have installed pyliblo which provides Python bindings to liblo. Note: this example borrows heavily from pyliblo's own documentation, which is very helpful and includes some interesting alternative methods for sending and receiving OSC messages. WARNING: Windows users, pyliblo is not well supported on your OS. Please see the Processing example in the next section to continue. The following example sets up and starts an OSC server listening for messages on port 5001. There are callbacks defined for /muse/eeg and /muse/acc (EEG and accelerometer data, respectively), and a generic callback to handle all other messages. All it does is print out the content of whatever message it receives. Grab the code here.
Processing OSC ServerThis example shows how to create a very simple OSC server in Processing. This is only the code for receiving OSC messages, all the visualization code is left as simple as possible in this example, so the applet simply appears as a blank square. The rest is up to your imagination! Download and install Processing from processing.org. Make sure the oscP5 library is installed by going to Sketch -> Import Library -> Add Library and selecting oscP5. // //MUSE OSC SERVER EXAMPLE //Copyright Interaxon 2015 // import oscP5.*; boolean debug = false; //OSC PARAMETERS & PORTS-------------------------------------- int recvPort = 5001; OscP5 oscP5; //DISPLAY PARAMETERS------------------------------------------ int WIDTH = 100; int HEIGHT = 100; //SETUP------------------------------------------------------- void setup() { size(WIDTH,HEIGHT); frameRate(60); /* start oscP5, listening for incoming messages at recvPort */ oscP5 = new OscP5(this, recvPort); background(0); } //DRAW LOOP ------------------------------------------------- void draw() { background(0); } //OSC HANDLER------------------------------------------------ void oscEvent(OscMessage msg) { /* print the address path and the type string of the received OscMessage */ if (debug) { print("---OSC Message Received---"); print(" Address Path: ", msg.addrPattern()); println(" Types: ", msg.typetag()); } if (msg.checkAddrPattern("/muse/eeg")==true) { for(int i = 0; i < 4; i++) { print("EEG on channel ", i, ": ", msg.get(i).floatValue(), "\n"); } } } |