Git Product home page Git Product logo

openbci_python's Introduction

THIS REPOSITORY IS NOW DEPRECATED AND NO LONGER IN ACTIVE DEVELOPMENT. PLEASE REFER TO "FOR DEVELOPERS" IN THE DOCS SECTION FOR INFORMATION ON BRAINFLOW-PYTHON.

OpenBCI Python

banner

Provide a stable Python driver for all OpenBCI Biosensors

Build Status

Welcome!

First and foremost, Welcome! πŸŽ‰ Willkommen! 🎊 Bienvenue! 🎈🎈🎈

Thank you for visiting the OpenBCI Python repository. This python code is meant to be used by people familiar with python and programming in general. It's purpose is to allow for programmers to interface with OpenBCI technology directly, both to acquire data and to write programs that can use that data on a live setting, using python.

This document (the README file) is a hub to give you some information about the project. Jump straight to one of the sections below, or just scroll down to find out more.

What are we doing?

The problem

  • OpenBCI is an incredible biosensor that can be challenging to work with
  • Data comes into the computer very quickly
  • Complex byte streams
  • Lot's of things can go wrong when dealing with a raw serial byte stream
  • The boards all use different physical technologies to move data to computers such as bluetooth or wifi
  • Developers want to integrate OpenBCI with other platforms and interfaces

So, if even the very best developers want to use Python with their OpenBCI boards, they are left scratching their heads with where to begin.

The solution

The OpenBCI Python will:

  • Allow Python users to install one module and use any board they choose
  • Provide examples of using Python to port data to other apps like lab streaming layer
  • Perform the heavy lifting when extracting and transforming raw binary byte streams
  • Use unit tests to ensure perfect quality of core code

Using this repo provides a building block for developing with Python. The goal for the Python library is to provide a stable Python driver for all OpenBCI Biosensors

Who are we?

The founder of the OpenBCI Python repository is Jermey Frey. The Python driver is one of the most popular repositories and has the most contributors!

The contributors to these repos are people using Python mainly for their data acquisition and analytics.

What do we need?

You! In whatever way you can help.

We need expertise in programming, user experience, software sustainability, documentation and technical writing and project management.

We'd love your feedback along the way.

Our primary goal is to provide a stable Python driver for all OpenBCI Biosensors, and we're excited to support the professional development of any and all of our contributors. If you're looking to learn to code, try out working collaboratively, or translate you skills to the digital domain, we're here to help.

Get involved

If you think you can help in any of the areas listed above (and we bet you can) or in any of the many areas that we haven't yet thought of (and here we're sure you can) then please check out our contributors' guidelines and our roadmap.

Please note that it's very important to us that we maintain a positive and supportive environment for everyone who wants to participate. When you join us we ask that you follow our code of conduct in all interactions both on and offline.

Contact us

If you want to report a problem or suggest an enhancement we'd love for you to open an issue at this github repository because then we can get right on it.

Find out more

You might be interested in:

And of course, you'll want to know our:

Glossary

OpenBCI boards are commonly referred to as biosensors. A biosensor converts biological data into digital data.

The Ganglion has 4 channels, meaning the Ganglion can take four simultaneous voltage readings.

The Cyton has 8 channels and Cyton with Daisy has 16 channels.

Generally speaking, the Cyton records at a high quality with less noise. Noise is anything that is not signal.

Thank you

Thank you so much (Danke schΓΆn! Merci beaucoup!) for visiting the project and we do hope that you'll join us on this amazing journey to make programming with OpenBCI fun and easy.

Dependencies

NOTE: For comprehensive list see requirments.txt: (https://github.com/OpenBCI/OpenBCI_Python/blob/master/requirements.txt)

OpenBCI 8 and 32 bit board with 8 or 16 channels.

This library includes the OpenBCICyton and OpenBCIGanglion classes which are drivers for their respective devices. The OpenBCICyton class is designed to work on all systems, while the OpenBCIGanglion class relies on a Bluetooth driver that is only available on Linux, discussed in the next section.

For additional details on connecting your Cyton board visit: http://docs.openbci.com/Hardware/02-Cyton

Ganglion Board

The Ganglion board relies on Bluetooth Low Energy connectivity (BLE), and our code relies on the BluePy library to communicate with it. The BluePy library currently only works on Linux-based operating systems. To use Ganglion you will need to install it:

pip install bluepy

You may be able to use the Ganglion board from a virtual machine (VM) running Linux on other operating systems, such as MacOS or Windows. See this thread for advice.

You may need to alter the settings of your Bluetooth adapter in order to reduce latency and avoid packet drops -- e.g. if the terminal spams "Warning: Dropped 1 packets" several times a seconds, DO THAT.

On Linux, assuming hci0 is the name of your bluetooth adapter:

sudo bash -c 'echo 9 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval'

sudo bash -c 'echo 10 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval'

Install

Using PyPI

pip install openbci-python

Anaconda is not currently supported, if you want to use anaconda, you need to create a virtual environment in anaconda, activate it and use the above command to install it.

From sources

For the latest version, you can install the package from the sources using the setup.py script

python setup.py install

or in developer mode to be able to modify the sources.

python setup.py develop

Functionality

Basic usage

The startStreaming function of the Board object takes a callback function and begins streaming data from the board. Each packet it receives is then parsed as an OpenBCISample which is passed to the callback function as an argument.

OpenBCISample members: -id: int from 0-255. Used to tell if packets were skipped.

-channel_data: 8 int array with current voltage value of each channel (1-8)

-aux_data: 3 int array with current auxiliary data. (0s by default)

user.py

This code provides a simple user interface (called user.py) to handle various plugins and communicate with the board. To use it, connect the board to your computer using the dongle (see http://docs.openbci.com/tutorials/01-GettingStarted for details).

Then simply run the code given as an argument the port your board is connected to: Ex Linux:

$python user.py -p /dev/ttyUSB0

The program should establish a serial connection and reset the board to default settings. When a '-->' appears, you can type a character (character map http://docs.openbci.com/software/01-OpenBCI_SDK) that will be sent to the board using ser.write. This allows you to change the settings on the board.

A good first test is to try is to type '?':

--> ?

This should output the current configuration settings on the board.

Another test would be to change the board settings so that all the pins in the board are internally connected to a test (square) wave. To do this, type:

--> [

Alternatively, there are 6 test signals pre configured:

--> /test1 (connect all pins to ground)

--> /test2 (connect all pins to vcc)

--> /test3 (Connecting pins to low frequency 1x amp signal)

--> /test4 (Connecting pins to high frequency 1x amp signal)

--> /test5 (Connecting pins to low frequency 2x amp signal)

--> /test6 (Connecting pins to high frequency 2x amp signal)

The / is used in the interface to execute a pre-configured command. Writing anything without a preceding '/' will automatically write those characters, one by one, to the board.

For example, writing

-->x3020000X will do the following:

β€˜x’ enters Channel Settings mode. Channel 3 is set up to be powered up, with gain of 2, normal input, removed from BIAS generation, removed from SRB2, removed from SRB1. The final β€˜X’ latches the settings to the ADS1299 channel settings register.

Pre-configured commands that use the / prefix are:

test (As explained above)

--> /test4

start selected plugins (see below)

--> /start

Adding the argument "T:number" will set a timeout on the start command.

--> /start T:5

Stop the steam to issue new commands

--> /stop

Useful commands:

Writting to SD card a high frequency square wave (test5) for 3 seconds:

$ python user.py -p /dev/ttyUSB0
User serial interface enabled...
Connecting to  /dev/ttyUSB0
Serial established...
View command map at http://docs.openbci.com.
Type start to run. Type /exit to exit.

-->
OpenBCI V3 8bit Board
Setting ADS1299 Channel Values
ADS1299 Device ID: 0x3E
LIS3DH Device ID: 0x33
Free RAM: 447
$$$
--> /test5
Warning: Connecting pins to high frequency 2x amp signal

--> a
Corresponding SD file OBCI_18.TXT$$$
--> /start T:3

NOTES:

When writing to the board and expecting a response, give the board a second. It sometimes lags and requires the user to hit enter on the user.py script until you get a response.

Ganglion

The Ganglion board is currently supported only on Linux. The communication is made directly through bluetooth (BLE), instead of using a dongle through a serial port. To launch the script, auto-detect the bluetooth MAC address of the nearby board and print values upon /start:

$sudo python user.py --board ganglion --add print

Note that if you want to configure manually the board, the API differs from the Cyton, refer to the proper documentation, i.e. http://docs.openbci.com/OpenBCI%20Software/06-OpenBCI_Ganglion_SDK

Plugins

Use plugins

Select the print plugin:

$python user.py -p /dev/ttyUSB0 --add print

Plugin with optional parameter:

$python user.py -p /dev/ttyUSB0 --add csv_collect record.csv

Select several plugins, e.g. streaming to OSC and displaying effective sample rate:

$python user.py -p /dev/ttyUSB0 --add streamer_osc --add sample_rate

Change the plugin path:

$python user.py -p /dev/ttyUSB0 --add print --plugins-path /home/user/my_plugins

Note: type /start to launch the selected plugins.

Create new plugins

Add new functionalities to user.py by creating new scripts inside the plugins folder. You class must inherit from yapsy.IPlugin, see below a minimal example with print plugin:

import plugin_interface as plugintypes

class PluginPrint(plugintypes.IPluginExtended):
    def activate(self):
        print("Print activated")

    def deactivate(self):
        print("Goodbye")

    def show_help(self):
        print("I do not need any parameter, just printing stuff.")

    # called with each new sample
    def __call__(self, sample):
        print("----------------")
        print("%f" % sample.id)
        print(sample.channel_data)
        print(sample.aux_data)

Describe your plugin with a corresponding print.yapsy-plugin:

[Core]
Name = print
Module = print

[Documentation]
Author = Various
Version = 0.1
Description = Print board values on stdout

You're done, your plugin should be automatically detected by user.py.

Existing plugins

  • print: Display sample values -- verbose output!

  • csv_collect: Export data to a csv file.

  • sample_rate: Print effective sampling rate averaged over XX seconds (default: 10).

  • streamer_tcp: Acts as a TCP server, using a "raw" protocol to send value.

    • The stream can be acquired with OpenViBE acquisition server, selecting telnet, big endian, float 32 bits, forcing 250 sampling rate (125 if daisy mode is used).
    • Default IP: localhost, default port: 12345
  • streamer_osc: Data is sent through OSC (UDP layer).

    • Default IP: localhost, default port: 12345, default stream name: /openbci
    • Requires pyosc. On linux type either pip install --pre pyosc as root, or pip install --pre --user.
  • udp_server: Very simple UDP server that sends data as json. Made to work with: https://github.com/OpenBCI/OpenBCI_Node

    • Default IP: 127.0.0.1, default port: 8888
  • streamer_lsl: Data is sent through LSL.

    • Default EEG stream name "OpenBCI_EEG", ID "openbci_eeg_id1"; default AUX stream name "OpenBCI_AUX", ID "openbci_aux_id1".
    • Requires LSL library. Download last version from offcial site, e.g., ftp://sccn.ucsd.edu/pub/software/LSL/SDK/liblsl-Python-1.10.2.zip and unzip files in a "lib" folder at the same level as user.py.

Tip: Type python user.py --list to list available plugins and python user.py --help [plugin_name] to get more information.

Scripts

In the scripts folder you will find code snippets that use directly the OpenBCIBoard class from open_bci_v3.py.

Note: copy open_bci_v3.py there if you want to run the code -- no proper package yet.

  • test.py: minimal example, printing values.
  • stream_data.py a version of a TCP streaming server that somehow oversamples OpenBCI from 250 to 256Hz.
  • upd_server.py DEPRECATED (Use Plugin): see https://github.com/OpenBCI/OpenBCI_Node for implementation example.

License:

MIT

openbci_python's People

Contributors

afazocar avatar biomurph avatar cfausn avatar chipaudette avatar chrisjz avatar conorrussomanno avatar cousteaulecommandant avatar daniellasry avatar dustinbcox avatar frederik-d-weber avatar gabrielibagon avatar ikmckenz avatar jfrey-xx avatar jnaulty avatar lambdaloop avatar mesca avatar micuat avatar neurocademy avatar rceballos98 avatar retiutut avatar roman3017 avatar taolin1992 avatar teonbrooks avatar timka avatar yarikoptic avatar yufengwng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openbci_python's Issues

Impedance testing

@aj-ptw

I'm working on getting impedance testing implemented on the OpenBCI using Python. The fact that it was not implemented in the original OpenBCI_Python code makes me wonder if this is a more difficult task than it seems.

Does anyone have any insight on this?

Based on what I can find in the OpenBCI Processing GUI, the steps should be to

  1. activate lead off negative pin for each channel of interest
  2. grab the channel data coming from the board and use it for impedance calculations
  3. deactivate the lead off negative pin for each channel of interest

Am I missing anything? Is anyone aware of anyone else who has got this up and running in Python?

Missing info / broken link in user.py section of README

Hi,

I thought I'd mention that in the README when you get to the user.py section it assumes that you've connected to the board via Bluetooth, and references a broken (re-directed) link on how to do so (http://docs.openbci.com/tutorials/01-GettingStarted).

My assumption is that the linked resource was replaced with the board-specific versions thereof, but (http://docs.openbci.com/Tutorials/02-Ganglion_Getting%20Started_Guide) I didn't see instructions in the board-specific getting started sections on how to connect via bluetooth and find a dev path like the one in your example.

On a tangentially related note, it might be worth noting that you can't use the pip install version of bluepy because then from btle won't work (I can go into more detail if needed).

sample output meaning

Hi everybody, i have only a question: when i run the test.py, those value that print, what rapresent?

Is the printing of status messages off?

At first I thought the character mapping was off, but after further experimentation, it just seems to be something weird about how/when status messages are printed to the screen.

Here's what I'm talking about:

--> !

--> @
%	Activating channel 
%	1

$$$

--> #
%	Activating channel 
%	2

$$$

--> $
%	Activating channel 
%	3

$$$

--> %
%	Activating channel 
%	4

$$$

--> %

--> 1

--> 2
%	Deactivating channe
%	l 1

$$$

--> 3
%	Deactivating channe
%	l 2

$$$
4
--> 4
%	Deactivating channe
%	l 3

$$$

--> 5
%	Deactivating channe
%	l 4

$$$
%	Deactivating channe
%	l 4


I don't think it's a major issue.

plugins initialization failed

after running user.py script ,when i add the plugins like by typing add print, i get message" initialization failed ,could not find Fat16/32 partition".i have every thing alright ,Sdcard is inserted and format is fat 32.
i am running this on Raspbian OS at Raspberry pie 3.python version is 2.7.i haive plugged in usb dongle of openbci in rasppberry pie 3.

i have attached the snapshot below.
errors

Trouble in the serial connection

Hi,
this is the error in my terminal. I don't understand what has gone wrong, someone can help me?

No handlers could be found for logger "yapsy"
USER.py
user.py: open_bci_v3...

------------SETTINGS-------------
('Notch filtering:', True)
user.py: Logging Disabled.

-------INSTANTIATING BOARD-------
Connecting to V3 at port /dev/ttyUSB0
Serial established...
Traceback (most recent call last):
File "user.py", line 98, in
log=args.log)
File "/home/pi/Desktop/OpenBCI_Python-master/open_bci_v3.py", line 88, in init
self.print_incoming_text()
File "/home/pi/Desktop/OpenBCI_Python-master/open_bci_v3.py", line 319, in print_incoming_text
c = self.ser.read().decode('utf-8')
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

Python2/3 on El Capitain 10.11.6

hello!

I am trying to run both, test_log.py and user.py in Python 2 and 3 on El Capitain, but have some issues :)

As far as I can tell all dependencies are installed and the same list is posted with pip list and pip3 list

Package          Version  
---------------- ---------
certifi          2018.4.16
chardet          3.0.4    
idna             2.7      
numpy            1.14.5   
pip              10.0.1   
pylsl            1.10.5   
pyserial         3.4      
python-osc       1.6.8    
requests         2.19.1   
setuptools       39.2.0   
six              1.11.0   
socketIO-client  0.7.2    
urllib3          1.23     
websocket-client 0.48.0   
wheel            0.31.1   
xmltodict        0.11.0   
Yapsy            1.11.223 

Some dependencies have higher versions than required and I hope this is OK.
Is this normal than Python 2 and 3 use the same library of dependencies?

When I run which pip I get this:
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip

user.py errors:

When I run python user.py -p /dev/tty.OpenBCI-DM00DRM0 I get this:

Traceback (most recent call last):
  File "user.py", line 12, in <module>
    from yapsy.PluginManager import PluginManager
ImportError: No module named yapsy.PluginManager

When I run the python3 version of this, python3 user.py -p /dev/tty.OpenBCI-DM00DRM0 , I get this:

------------user.py-------------
WARNING: no plugin selected, you will only be able to communicate with the board. You should select at least one plugin with '--add [plugin_name]'. Use '--list' to show available plugins or '--info [plugin_name]' to get more information.
Board type: OpenBCI Cyton (v3 API)
Port:  /dev/tty.OpenBCI-DM00DRM0

------------SETTINGS-------------
Notch filtering:True
user.py: Logging Disabled.

-------INSTANTIATING BOARD-------
Traceback (most recent call last):
  File "user.py", line 114, in <module>
    board = bci.OpenBCIGanglion(port=args.port,
AttributeError: module 'openbci.cyton' has no attribute 'OpenBCIGanglion'

test_log.py

When I run python test_log.py I get this:

Traceback (most recent call last):
  File "test_log.py", line 2, in <module>
    from openbci import cyton as bci
  File "/Users/tedor2/Dropbox/python/OpenBCI/OpenBCI_Python-master/openbci/__init__.py", line 4, in <module>
    from .plugins import *
  File "/Users/tedor2/Dropbox/python/OpenBCI/OpenBCI_Python-master/openbci/plugins/__init__.py", line 2, in <module>
    from .csv_collect import *
  File "/Users/tedor2/Dropbox/python/OpenBCI/OpenBCI_Python-master/openbci/plugins/csv_collect.py", line 5, in <module>
    import plugin_interface as plugintypes
  File "/Users/tedor2/Dropbox/python/OpenBCI/OpenBCI_Python-master/plugin_interface.py", line 21, in <module>
    from yapsy.IPlugin import IPlugin
ImportError: No module named yapsy.IPlugin

When running python3 test_log.py, here the post:

Connecting to V3 at port /dev/tty.OpenBCI-DM00DRM0
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serial/serialposix.py", line 265, 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: '/dev/tty.OpenBCI-DM00DRM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_log.py", line 21, in <module>
    board = bci.OpenBCICyton(port=port, scaled_output=False, log=True)
  File "/Users/tedor2/Dropbox/python/OpenBCI/OpenBCI_Python-master/openbci/cyton.py", line 82, in __init__
    self.ser = serial.Serial(port= port, baudrate = baud, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/tty.OpenBCI-DM00DRM0: [Errno 2] No such file or directory: '/dev/tty.OpenBCI-DM00DRM0'

Any recommendations?

Thanks, k

Can I read EEG data of Ganglion on Windows?

I wanna read EEG data of Ganglion board on Windows 10 Environment.
The communication of Ganglion board is made through bluetooth, and it needs a python interface "bluepy".
However, the "bluepy" seems to support Linux only.
Does it mean the Ganglion board does not work on Windows or Mac?

compile a requirements.txt file?

I was just trying to get started but kept running into python dependencies I didn't recognise. A requirements.txt file to be installed via pip -r requirements.txt would be very helpful.

Error running user.py - AttributeError

Hello,
I'm trying to stream EEG signals from the Cyton OpenBCI but after installing successfully all requirements for the user.py script, the output of the python command is the following:

$ python user.py -p=/dev/ttyUSB0 --add streamer_lsl --board=cyton

------------user.py-------------
Board type: OpenBCI Cyton (v3 API)
Port:  /dev/ttyUSB0

------------SETTINGS-------------
Notch filtering:True
user.py: Logging Disabled.

-------INSTANTIATING BOARD-------
Traceback (most recent call last):
  File "user.py", line 114, in <module>
    board = bci.OpenBCIGanglion(port=args.port,
AttributeError: module 'openbci.cyton' has no attribute 'OpenBCIGanglion'

Any ideas? I can't figure out why the program complains in 114 line about this AttributeError.
I'm currently on a Linux machine, with python 3.6.5 (Anaconda) installed - no virtual environment used.
Thanks in advance!

/exit command doesn't work

All most all the time, /exit command does not work. I have to kill the program manually. Is this expected behavior? I am using Ganglion Board.

Library installation

Hi,

I have 2 small comments:

  1. Unless I missed something, there's nothing in the README.md or elsewhere that I could find which actually says/shows how to install the library. It talks about dependencies and usage, but not installation.

  2. When trying to install it like this in Debian:

pip install git+https://github.com/OpenBCI/OpenBCI_Python.git

It fails:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-eIjxN1-build/

Or is this not a proper library, but just a script you use interactively with python user.py?

I apologize for my confusion.

Ganglion OpenBCI + Raspberry Pi 3 problem

Hi!
I'm trying to make my Raspberry Pi 3 to work with the Ganglion OpenBCI over Bluetooth using instructions from here by @micuat. Installation works without serious issues, I got my Cyton working and streaming using LSL, but still having trouble running the user.py script with the Ganglion.
I have sucessfully installed Bluetooth on my Raspberry, hcitool lescan finds my Ganglion on the network, compiled bluepy from source (1.2.0) from here, while the following python script runs without problems:

from bluepy import btle
dev = btle.Peripheral("HEX of Ganglion", 'random')
for svc in dev.services:
     print str(svc)

and outputs:

Service <uuid=Generic Attribute handleStart=8 handleEnd=11>
Service <uuid=Generic Access handleStart=1 handleEnd=7>
Service <uuid=fe84 handleStart=23 handleEnd=30>
Service <uuid=00001530-1212-efde-1523-785feabcd123 handleStart=31 handleEnd=65535>
Service <uuid=Device Information handleStart=12 handleEnd=22>

But when I issue the command:
sudo python user.py --board ganglion --port <MAC ADDRESS GANGLION> --add print
the script errors with the compaint:

------------user.py-------------
Board type: OpenBCI Ganglion
('Port: ', 'f8:03:fc:d0:cf:25')

------------SETTINGS-------------
Notch filtering:True
user.py: Logging Disabled.

-------INSTANTIATING BOARD-------
Looking for Ganglion board
Init BLE connection with MAC: f8:03:fc:d0:cf:25
NB: if it fails, try with root privileges.
Traceback (most recent call last):
  File "user.py", line 119, in <module>
    aux=args.aux)
  File "/home/pi/OpenBCI_Python/openbci/ganglion.py", line 94, in __init__
    self.connect()
  File "/home/pi/OpenBCI_Python/openbci/ganglion.py", line 121, in connect
    self.gang = Peripheral(self.port, 'random') # ADDR_TYPE_RANDOM
NameError: global name 'Peripheral' is not defined

The openbci/ganglion.py script ,

...
import sys
sys.path.insert(0,"bluepy/bluepy")
STUB_BTLE = False
try:
    from btle import Scanner, DefaultDelegate, Peripheral
except:
    DefaultDelegate = object
    STUB_BTLE = True
else:
    from bluepy.btle import Scanner, DefaultDelegate, Peripheral    
...

I tried to replace (comment out) the line sys.path.insert(0,"bluepy/bluepy") with the path that has my compiled bluepy (/home/pi/bluepy/build/lib.linux-armv7l-2.7/bluepy), or even comment it (to use the system installed version?), but no luck.
Any help?

pyOSC doesn't work with Python 3

I tried to install pyOSC with Python 3, and there are a lot of compatibility issues (using the version installed via pip + requirements.txt). We could rewrite parts of the module and include the file in the repository, or we could find another library that is more compatible with Python 2.7 and Python 3.

I'll be looking into a fix myself, but I wanted to shout this out there in case someone has insight.

Trouble connecting python to LSL

When I run:

python openbci_lsl.py --stream

it outputs the following:

-------INSTANTIATING BOARD-------
Traceback (most recent call last):
File "openbci_lsl.py", line 56, in
main(sys.argv[1:])
File "openbci_lsl.py", line 40, in main
lsl = streamerlsl.StreamerLSL(GUI=False)
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\streamerlsl.py", line 46, in init
self.initialize_board(autodetect=True)
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\streamerlsl.py", line 59, in initialize_board
self.board = bci.OpenBCIBoard()
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\open_bci_v3.py", line 77, in init
port = self.find_port()
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\open_bci_v3.py", line 599, in find_port
raise OSError('Cannot find OpenBCI port')
OSError: Cannot find OpenBCI port

Where can I find the [port] for my device? I have a Ganglion.

Also, how do I change the init function in open_bci_v3.py to establish a serial connection in Windows?

streamer-LSL incompatibility with LSL's MATLABViewer vis_stream

Hello!

When using user.py's streamer-lsl plugin, the LSL stream gets created successfully and streams data, as tested by LSL's RecieveData.py. However, when running LSL's MATLABViewer app, while it is able to detect the stream, once it starts receiving data it immediately crashes, displaying the error:

vis_stream error: Index exceeds matrix dimensions.
occurred in:
vis_stream/on_timer: 135
timercb: 30
timercb: 13

Note that the problem is not in vis_stream, because when I send artificial data via LSL's example script SendData.py, vis_stream successfully detects it, connects to it, and displays the streaming data.

To aid debugging, here's my version numbers:

  • OpenBCI 32Bit 8Channel Board V3
  • Python 2.7
  • OpenBCI_Python cloned July 13, 2016 (Commit: 65cb3f5)
  • MATLAB R2015b (8.6.0.267246)
  • LSL cloned July 13, 2016 (Commit: b9ff52584e0a6c9ef13de050b995a4816f82b0b9) master branch
  • MacOSX 10.11.5 El Capitan

The command I'm using to run user.py:

python user.py -p /dev/tty.usbserial-DJ00ISQW --add streamer_lsl

tuning for dropped packets

I had "dropped packets" even if I followed the instruction in README. Alternatively I did

sudo bash -c 'echo 8 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval'
sudo bash -c 'echo 8 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval'

and now I have very few packet lost (once in < 100 sec)

Code don't run in windows

Please sorry my redaction, the english it's my second language.
I am trying to run this code in windows 10, after that i used Zadig tool for using my ganglion board, streaming the signal with OpenBCI GUI and this works fine.
My goal its run in python a algoritm of machine learning using a Rasphery like processing plataform. I am familiarizate with python then its very helpfull this code. I need Know how i can run it on Windows.

A friend have linux and in this enviroment install all requirements it's very easy, but dont found the ganglion board in the port 0,1,2,3...30. If you can help me i will be very glad.

requirement pyOSC version fix

Hi, it's a small fix but the pyOSC is not

pyOSC==0.3.5b5294

but has to be

pyOSC==0.3.5b-5294

to be able to run sudo pip install -r requirements.txt

stream_data_wifi.py "failed to parse" errors

Apologies in advance if this is not the right way to post such an issue.

When trying to run stream_data_wifi.py, I am able to connect to the board but the packets are garbled, as shown in the output below:
Welcome to OpenBCI Native WiFi Shield Driver - Please contribute code!
Opened socket on 192.168.1.110:49624
Try to find WiFi shields on your local wireless network
Scanning for 5 seconds nearby devices...
Found WiFi Shield OpenBCI-4AAD with IP Address 192.168.1.104
Init WiFi connection with IP: 192.168.1.104
Connected to cyton with 8 channels
WiFi Shield to Python TCP Socket Established
WiFi Shield Instantiated
Incoming connection from ('192.168.1.104', 5672)
failed to parse: ?D??U??V?Ν†?? ?????s???F??#??9??k???u?????s???G????????????um?u??T?s,??H?????????Ú?u?????{?sU??I?????P?̍??%?u?%????r???J??{????????f?uO?S??1???K?????????Γ©?u?????j?sE??L?????????Γ₯?u?????Y?s;????M??????????Γ‹?uv?r??8?s?
No JSON object could be decoded

I have an OpenBCI Cyton and Wifi Shield, both with up-to-date firmware. Streaming works with the OpenBCI GUI, and I was able to get the js example (getStreaming.js) to work.

I'm running on a Mac so I was unable to install bluepy, but all other requirements are at or above the required versions.

Any assistance would be greatly appreciated.

Pip requirements not installing yapsy

I am receiving the error:

ImportError: No module named yapsy.PluginManager

I ran the command pip install -r requirements.txt, but the Plugin Manager does not seem to properly install.

How do I fix this? (I am trying to run this in virtualenv on Ubuntu).

demo mode

My understanding is that currently the script only runs when connected to a board. I think a "demo mode" that doesn't require a board and just stream sine or square waves will be extremely useful for debugging.

cannot make bluepy

following the ganglion instructions but get an error when I try to make blue py

Running on MacOSX 10.13.3

To reproduce:

  1. git clone (this repository) --recursive
  2. cd (this repo)/bluepy/bluepy
  3. make

Error:

make β„Ή info Invoking all target
make β„Ή info Invoking bluepy-helper target
(node:76540) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): undefined
(node:76540) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
make βœ– ERR  not found: make-$(LOCAL_SRCS)

  $ make <target...> [options]

  Options:
    --help             Show this help output
    --version          Show package version
    --debug            Enable extended log output

  Targets:
    all                Run target all
    bluepy-helper      Run target bluepy-helper
    bluez-tarfile      Run target bluez-tarfile
    uuids.json         Run target uuids.json
    TAGS               Run target TAGS
    clean              Run target clean

  Templates:
    ava                Generate ava setup (ava)
    cli                Generate cli setup (minimist, tabtab, ge...)
    default            Generate default setup (babel-cli, babel-plu...)
    eslint             Generate eslint setup (eslint, eslint-confi...)
    livereactload      Generate livereactload setup (babel-plugin-react-t...)
    mocha              Generate mocha setup (mocha)
    simple             Generate simple setup

I also tried running make in the parent directory OpenBCI_Python/bluepy. This works, but later when I try to run user.py I get an error saying bluepy-helper can not be found.

I also tried running make init in bluepy/bluepy. Something happened, but after running make after the same error appeared.

Proposition for INSTALL paragraph inside README.md

Proposition for INSTALL paragraph inside README.md, it may help a few

# only on Ubuntu, Fedora and macOS are ko in our case (bluepy: Python interface to Bluetooth LE on Linux).
# start your device, start your bluetooth
mkdir ~/my-ganglion-project
cd ~/my-ganglion-project
sudo apt-get install python-pip libglib2.0-dev
pip -V # check if version is in 2.x version
git clone --recursive https://github.com/OpenBCI/OpenBCI_Python
cd ~/my-ganglion-project/OpenBCI_Python/bluepy/bluepy
sudo mkdir /usr/local/lib/python2.7/dist-packages && sudo chmod g+rwx /usr/local/lib/python2.7/dist-packages# we had to do it ... maybe you don't
sudo make
sudo pip install -e ~/my-ganglion-project/OpenBCI_Python/bluepy
cd ~/my-ganglion-project/OpenBCI_Python
sudo pip install -r requirements.txt
hcitool lescan # you can see your device ;)
sudo hciconfig hci1 down # why ? I don't know :p
sudo hciconfig hci1 up
sudo python user.py --board ganglion --add print

pyserial

In Dependancies part, the pyserial library may be also required.

bugs in user.py?

Had a problem running user.py per the standard instructions. Modified the code and it worked. Two issues that I "fixed" are:

(1) Line 76 of user.py reads: plugins_paths = ["plugins"]

  • but the folder structure is openbci/plugins from the top-level directory that contains user.py
  • with line 76 as is, user.py was not finding the plugins
  • I changed that line to read: plugins_paths = ["openbci/plugins"]
  • it now works fine, with the code finding and loading the plugins

(2) Line 114 of user.py starts: board = bci.OpenBCIGanglion(...

  • why is the code calling OpenBCIGanglion when the code has already figured out that I have a Cyton?
  • I changed this code to use if and elif to check the value of args.board
  • it now works fine since my modifed code calls OpenBCICyton

Sorry if these aren't bugs, but rather just some newbie mistake of mine. I'd be surprised if they are bugs. But the code looks puzzling to me ... especially line 114.

Code don't run in Raspberry

Hello again, after this works in computer with linux, We try launch in a Rasphery 3, well we made the same steps but when we enter sudo python user.py --board ganglion -a print, this output "need more than 1 value to unpack". It's the same code and the same entry we dont understand.
we are very glad for your atention

Cannot connect to Ganglion

Running on Mac OSX 10.12 Sierra

This is all very new to me, so I may be doing something wrong. But here is what I have tried after looking through the code:

I am using the command:
python user.py --board 4 -p PORT

Here are some of the things I have tried for PORT:
/dev/tty.usbserial*
/dev/tty.usbserial-*
/dev/ttyUSB0
/dev/tty.usbmodem1411

/dev/tty.Bluetooth-Incoming-Port

With /dev/tty.Bluetooth-Incoming-Port it finally worked... or maybe not. Typing "?" gave no output:

image

I noticed in the code of open_bci_v_ganglion.py that find_port() is not defined. I tried copying over find_port() from v3 (and removing the requirement to input a port in the beginning) but this didn't work either:

image

How to run /scripts examples without moving the file into the home directory?

Hi - love the code so far.

How do we run the examples in the scripts directory?
running "python scripts/test.py" gives this:

Traceback (most recent call last):
File "scripts/test.py", line 1, in
import open_bci_v3 as bci
ImportError: No module named open_bci_v3

This is a simple python references issue, as moving the sample scripts into the same diretory as open_bci_v3.py removes the issue.

Thanks!

2's complement 24->32 bits conversion

I borrowed your implementation of conv24bitsToInt (referenced your name/work)

However I think:
if (unpacked[0] >= 127):

Should be replaced by
if (unpacked[0] > 127):

as 127 is written 0111 1111, sign bit is off.

END_BYTE value for Cyton board Firmware: v2.0.0

I'm not sure if this is a known issue, but trying to stream data from a Cyton 8-channels board I would consistently get the following warning for all data packets

<Unexpected END_BYTE found <193> instead of <192>

and of course no sample object.

Changing the value for END_BYTE from 0xC0 to 0xC1 fixed the issue.

OpenVibe Help Outdated

Hi,

I believe the OpenVibe help is outdated. I'm struggling to get my ganglion device connected to OpenVibe. There is no option for me to change the device field within the driver properties. As this field remains on automatic.

screen shot 2018-06-03 at 17 00 06

Any help on this would be much appreciated.

Cheers,

Laurence

Edit: I should say I'm getting this error when running:

screen shot 2018-06-03 at 17 01 48

plugin_interface

When installing from pip, from openbci import wifi will give an error: ModuleNotFoundError: No module named 'plugin_interface'. It is because plugin_interface.py is outside of the package.

Commenting the line from .plugins import * in openbci/__init__.py fixes the problem. I am not familiar with the plugin system, and maybe this quick fix has side-effects. Is there a better way?

Form of data

I want to know that data return in test.py is in which form?

junk package after /stop

this issue probably has more to do with the firmware or the radio but i post it here anyways.

i'm on macos 10.12.6 with a cyton 8ch board + dongle. (didn't perform the 'ftdi driver fix' yet if that could have somthing to do with it)

OpenBCI V3 8-16 channel
On Board ADS1299 Device ID: 0x3E
LIS3DH Device ID: 0x33
Firmware: v3.1.1

the issue i'm having is that after sending the stop command (s) i get a slightly garbled package as the last incoming package.
here's some test code to demonstrate...

import serial
import time

ser= serial.Serial(port= "/dev/tty.usbserial-DJ00DO0N", baudrate= 115200)
if ser.isOpen():
	print(ser.name)
	ser.write(b'b')  #start streaming
	timeout= time.time()+1
	while time.time()<timeout:
		ser.read()
	ser.write(b's')  #stop streaming
	while True:
		byte= ord(ser.read())
		print(byte)
		if byte==192:
			print('--------')

and here the output...

160
241
250
142
83
250
146
117
250
153
162
250
113
28
234
25
0
223
17
3
204
37
12
128
0
0
0
0
0
0
0
0
192
--------
160
242
250
142
55
250
146
91
250
153
133
250
113
4
234
24
234
223
16
238
204
36
244
128
0
0
0
0
0
0
0
0
192
--------
160
243
250
142
198
250
146
241
250
154
35
250
113
163
234
25
155
223
17
160
204
37
183
128
0
0
0
0
0
0
0
0
192
--------
65             <- THIS
244
165
82
250
147
123
250
154
183
250
114
53
234
26
55
223
18
60
204
38
96
128
0
0
2
80
1
0
32
144
192
--------

around 9/10 times the last package doesn't start with 160 but rather with 65. the package counter is correct and the rest of the data seem valid. it's just the wrong header.

how come? can someone verify on their system.
thank you.
_f

user.py not working

/start T:3 I tried this and its giving an error that is "No function loaded". I am using python code on windows 7. And its not working properly. I am unable to find a brief guide about this code.

yapsy logger not set when plugin search begins

In user.py, yapsy logger is not set when collectPlugins is called. Therefore, instead of a meaningful error messages there's a cryptic message about there being no handler for yapsy.
Easy to fix by adding e.g. logging.basicConfig(level=logging.ERROR) before calling yapsy.

OSC streaming requires Python 3

It seems that the python-osc library, currently used for streaming OSC messages, works only in Python 3.

This was not immediately clear, as the documentations states that OpenBCI_Python works requires Python 2.7 or later, and other examples run fine in 2.7.

I personally was able to move to python 3 with my code, but since most everything else works on both python 2.7+ and 3 maybe there would be a way to maintain this compatibility? Or at least document the extra requirements for OSC streaming.

find_port is not defined in open_bci_v3

from open_bci_v3 import *
board = OpenBCIBoard()

Produces error:

NameError                                 Traceback (most recent call last)
<ipython-input-2-376316daaf9a> in <module>()
----> 1 board = OpenBCIBoard()

/home/graeme/devel/openbci/OpenBCI_Python/open_bci_v3.py in __init__(self, port, baud, filter_data, scaled_output, daisy, log, timeout)
     70     self.log = log # print_incoming_text needs log
     71     if not port:
---> 72       port = find_port()
     73       if not port:
     74         raise OSError('Cannot find OpenBCI port')

NameError: name 'find_port' is not defined

python on windows

I want to run this code on windows Os, and I find on the following website in DEPENDENCIES part, that it says that "To use a Windows OS, change the β€œ__initβ€œ function in open_bci_v3.py to establish a serial connection in Windows". However, I don't unnderstand how to change this function. Can anyone help me? Thanks for your help.
http://docs.openbci.com/OpenBCI%20Software/05-OpenBCI_Python

raise OSError('Cannot find OpenBCI port')

Hello, after turning on my Ganglion board and dongle, I run the command:

python openbci_lsl.py --stream

and it outputs the following:

-------INSTANTIATING BOARD-------
Traceback (most recent call last):
File "openbci_lsl.py", line 56, in
main(sys.argv[1:])
File "openbci_lsl.py", line 40, in main
lsl = streamerlsl.StreamerLSL(GUI=False)
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\streamerlsl.py", line 46, in init
self.initialize_board(autodetect=True)
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\streamerlsl.py", line 59, in initialize_board
self.board = bci.OpenBCIBoard()
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\open_bci_v3.py", line 77, in init
port = self.find_port()
File "C:\Program Files\MATLAB\OpenBCI_LSL\lib\open_bci_v3.py", line 574, in find_port
raise OSError('Cannot find OpenBCI port')
OSError: Cannot find OpenBCI port

Does anyone know how to solve this error?

btle.BTLEException: Failed to execute mgmt cmd 'le on'

Hey Guys,

I have macOS High Sierra as my host machine, and I'm running Ubuntu 16.04 in VMware. I've downloaded all requirements and got my vm to access my headphones, so bluetooth is working.

When I run: $sudo python user.py --board ganglion --add print

I get:

"Failed to execute mgmt cmd '%s'" % (cmd))
btle.BTLEException: Failed to execute mgmt cmd 'le on'

Any help on this would be great. I've used the GUI on the mac and streamed data, but I'm keen to get access via this python library.

Thank you in advance.

L

Edit: I should say I'm running this from root
Edit: When I run the GUI on my macOS host - it finds the ganglion board. But when I run it on my linux vm, it does not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.