Using Muse with Python on Windows


#1

Hi there,

I know that this question has probably been asked so many times but is there any way to set up the Muse to work with Python on windows. I have to use Python because of the research suite that i use.

If there is a step by step guide that someone knows of that would be great.

Thanks in advance
Keith


#2

Hey kenolan,

What version of Python are you using? If it’s 3.x you should try python-osc (the server example that comes with it is pretty straightforward). I believe there is another osc library for Python 3 called pyOSC, you might give that a shot as well, although I can’t vouch for it at the moment.

Here’s what you could do if you used python-osc (this is their standard example modified to print out Muse EEG packets):

import argparse
import math

from pythonosc import dispatcher
from pythonosc import osc_server

def eeg_handler(unused_addr, args, ch1, ch2, ch3, ch4):
      print("EEG (uV) per channel: ", ch1, ch2, ch3, ch4)

if __name__ == "__main__":
  parser = argparse.ArgumentParser()
  parser.add_argument("--ip",
      default="127.0.0.1", help="The ip to listen on")
  parser.add_argument("--port",
      type=int, default=5005, help="The port to listen on")
  args = parser.parse_args()

  dispatcher = dispatcher.Dispatcher()
  dispatcher.map("/debug", print)
  dispatcher.map("/muse/eeg", eeg_handler, "EEG")

  server = osc_server.ThreadingOSCUDPServer(
      (args.ip, args.port), dispatcher)
  print("Serving on {}".format(server.server_address))
  server.serve_forever()

The example on our old developer website used pyliblo but is only recommended for Mac and Linux. It is very difficult to get pyliblo to work on Windows, because it relies on POSIX threads.

Alternatively, there might be ways around using Python altogether. If you’re doing your analysis offline in Python for instance, you don’t need to also capture the data with Python. But that may or may not be the case here.

Also, I’m going to be posting a tutorial on the new developer.choosemuse.com fairly soon about how to create simple OSC servers in a few different languages.


#3

Hi Tom,

Thank you for that. I have got it up and running for Python 3.4 but I am restricted to use Python 2.7 as the psychological testing suite PsychoPy uses Python 2.7. I am trying to use pyOSC at the moment but am having no luck.

Thanks for your help and looking forward all the new tutorials

Keith


#4

Hi Keith,

Last year I got to install pyliblo-0.9.2 (need to install liblo-0.28 first) and make it work with Python 2.7 on my Windows 7.
But, as said by Tom, it was a nightmare !
Take a look at the thread bellow and see if it can be of any help.

http://forum.choosemuse.com/forum/developer-forum/5222-osc-server-with-c-and-visual-studio-2010

Eduardo


#5

Hi Tom,

In case you’re still interested in this, I got pyOSC working fine with PsychoPy Builder

from pyOSC import *

client = OSC.OSCClient()
client.connect(( ‘127.0.0.1’, 5000 ))
msg = OSC.OSCMessage()
msg.setAddress( ‘/Marker/1’ )
client.send( msg )

NB pyOSC uses UDP (not TCP)


List of MuseLab message command structures/formats?