alexandrebarachant / muse-lsl

Python script to stream EEG data from the muse 2016 headset
BSD 3-Clause "New" or "Revised" License
616 stars 182 forks source link

Unable to connect to muse using pygatt #163

Closed sunshineinsandiego closed 3 years ago

sunshineinsandiego commented 3 years ago

Hi - I am trying to connect to my Muse 2 headset but am unable to discover the device using pygatt.

Here is what I have tried:

$ muselsl list
Traceback (most recent call last):
  File "/Users/christopher/Documents/EEGHRV/.venv/bin/muselsl", line 8, in <module>
    sys.exit(main())
...
pygatt.backends.bgapi.exceptions.BGAPIError: Unable to auto-detect BLED112 serial port

I then used a different script to list all BLE devices and successfully discovered the Muse address:

$ python3 discoverBLE.py 
A465554C-826C-4F38-9A77-D9C85DF3EB38: Unknown
...
CCB50D1B-59EC-4675-9297-5D2B797754A2: Muse-995C
...
A55C09A7-0997-46C8-90F7-5206E18914AB: Unknown

I then tried to connect using that specific address:

$ muselsl stream --address CCB50D1B-59EC-4675-9297-5D2B797754A2
Connecting to Muse: CCB50D1B-59EC-4675-9297-5D2B797754A2...
Connection to CCB50D1B-59EC-4675-9297-5D2B797754A2 failed

As well as by name:

$ muselsl stream --name Muse-995C
Traceback (most recent call last):
  File "/Users/christopher/Documents/EEGHRV/.venv/bin/muselsl", line 8, in <module>
    sys.exit(main())
 ...
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/pygatt/backends/bgapi/bgapi.py", line 147, in _detect_device_port
    raise BGAPIError("Unable to auto-detect BLED112 serial port")
pygatt.backends.bgapi.exceptions.BGAPIError: Unable to auto-detect BLED112 serial port

Then, I looked at my specs to address the possible port error in "Common Issues": Specs: Mac OSX 11.4 Python 3.8.2

System Information->Bluetooth Screen Shot 2021-06-03 at 9 08 31 PM

System Information->USB Screen Shot 2021-06-03 at 9 09 08 PM

% ls -al /dev/*
crw-------  1 root         wheel           19,   1 Jun  3 20:43 /dev/afsc_type5
...
crw-rw-rw-  1 root         wheel           22,   1 Jun  3 20:43 /dev/cu.Bluetooth-Incoming-Port
...
crw-rw-rw-  1 root         wheel            2,   0 Jun  3 20:43 /dev/tty
crw-rw-rw-  1 root         wheel           22,   0 Jun  3 20:43 /dev/tty.Bluetooth-Incoming-Port
...
crw-rw-rw-  1 root         wheel            4,  48 Jun  3 20:43 /dev/ttys0
crw--w----  1 christopher  tty             16,   0 Jun  3 20:56 /dev/ttys000
crw--w----  1 christopher  tty             16,   1 Jun  3 20:52 /dev/ttys001
crw-rw-rw-  1 root         wheel            4,  49 Jun  3 20:43 /dev/ttys1
...
crw-rw-rw-  1 root         wheel            3,   3 Jun  3 20:43 /dev/zero

/dev/fd:
total 9
dr-xr-xr-x   1 root         wheel         0 Jun  3 20:43 .
dr-xr-xr-x   3 root         wheel      4451 Jun  3 20:43 ..
crw--w----   1 christopher  tty     16,   0 Jun  3 20:56 0
crw--w----   1 christopher  tty     16,   0 Jun  3 20:56 1
crw--w----   1 christopher  tty     16,   0 Jun  3 20:56 2
drw-r--r--  19 christopher  staff       608 Jun  3 12:44 3
dr--r--r--   1 root         wheel         0 Jun  3 20:43 4

Using a port of 22:

% muselsl list -i COM22
Traceback (most recent call last):
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/serial/serialposix.py", line 322, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: 'COM22'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/pygatt/backends/bgapi/bgapi.py", line 135, in _detect_device_port
    serial.Serial(port=self._serial_port)
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/serial/serialutil.py", line 244, in __init__
    self.open()
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/serial/serialposix.py", line 325, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port COM22: [Errno 2] No such file or directory: 'COM22'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/christopher/Documents/EEGHRV/.venv/bin/muselsl", line 8, in <module>
    sys.exit(main())
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/muselsl/__main__.py", line 57, in main
    cli = CLI(args.command)
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/muselsl/cli.py", line 9, in __init__
    getattr(self, command)()
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/muselsl/cli.py", line 32, in list
    list_muses(args.backend, args.interface)
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/muselsl/stream.py", line 56, in list_muses
    raise e
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/muselsl/stream.py", line 46, in list_muses
    adapter.start()
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/pygatt/backends/bgapi/bgapi.py", line 203, in start
    self._detect_device_port()
  File "/Users/christopher/Documents/EEGHRV/.venv/lib/python3.8/site-packages/pygatt/backends/bgapi/bgapi.py", line 138, in _detect_device_port
    raise BGAPIError(
pygatt.backends.bgapi.exceptions.BGAPIError: Unable to detect BLED112 serial port: COM22.

Any advice? Thanks!

sunshineinsandiego commented 3 years ago

Fixed by purchasing different Dongle, thanks!